Skip to content

Commit 2ed2e09

Browse files
committed
Add system info page
1 parent 3fae150 commit 2ed2e09

11 files changed

+90
-39
lines changed

Diff for: notes.txt

+1-17
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,10 @@ content:
7373
- uptime
7474
- free memory
7575
- top CPU usage
76+
- wifi stats
7677
- audio hardware parameters:
7778
- playback
7879
- capture
7980

80-
#! /bin/bash
81-
# sysinfo.sh
82-
echo Uptime: $(uptime | sed -r 's/.*up(.*) [0-9]+ users?,/\1/')
83-
echo ""
84-
echo Free memory: $(free -t | grep "buffers/cache" | awk '{print $4/($3+$4) * 100}')%
85-
echo ""
86-
echo "Top processes"
87-
ps -eo pcpu,pid,args | sort -k 1 -r | head -5
88-
echo ""
89-
echo "Audio playback parameters"
90-
cat /proc/asound/card0/pcm0p/sub0/hw_params
91-
echo ""
92-
echo "Audio capture parameters"
93-
cat /proc/asound/card0/pcm0c/sub0/hw_params
94-
echo ""
95-
echo Wifi $(iwconfig 2> /dev/null | grep 'Link Quality' | sed -r 's/^ *//')
96-
9781
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9882

Diff for: static/images/ajax-loader.gif

7.64 KB
Loading

Diff for: static/images/icons-18-black.png

1.92 KB
Loading

Diff for: static/images/icons-18-white.png

1.94 KB
Loading

Diff for: static/images/icons-36-black.png

3.77 KB
Loading

Diff for: static/images/icons-36-white.png

3.77 KB
Loading

Diff for: static/index.html

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
</head>
1313
<body>
1414
<div data-role="page" id="tv_page">
15-
<div data-role="header"><h1>TV Volume</h1></div>
15+
<div data-role="header">
16+
<a href="#info_page" data-icon="info">Info</a>
17+
<h1>TV Volume</h1>
18+
</div>
1619
<div data-role="content">
1720
<form id="tv_volume_form" action="/ctl" data-ajax="false">
1821
<input type="range" name="tv_vol" id="tv_vol" min="0" max="100" disabled="disabled">
@@ -23,5 +26,13 @@
2326
</form>
2427
</div>
2528
</div>
29+
<div data-role="page" id="info_page">
30+
<div data-role="header">
31+
<a href="#tv_page" data-direction="reverse" data-icon="home">Back</a>
32+
<h1>System Info</h1>
33+
<a href="#system_info" id="info_refresh" data-icon="refresh">Refresh</a>
34+
</div>
35+
<div class="scrollable"><pre id="system_info"></pre></div>
36+
</div>
2637
</body>
2738
</html>

Diff for: static/script.js

+41-15
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,30 @@ $(document).ready(function() {
2323
var set_volume = SquashEvents(100);
2424
var url = $("#tv_volume_form").attr("action")
2525

26-
$.get(url, {}, function (data) {
27-
var tv_toggle = $('#tv_toggle');
28-
var tv_vol = $('#tv_vol');
29-
if (data.loopback !== undefined) {
30-
tv_toggle.val(data.loopback);
31-
}
32-
tv_volume_value = data.volume;
33-
if (data.volume !== undefined) {
34-
tv_vol.val(data.volume);
35-
}
36-
tv_vol.slider("enable");
37-
tv_toggle.slider("enable");
38-
tv_vol.slider("refresh");
39-
tv_toggle.slider("refresh");
40-
}, "json");
26+
function setup_main_page() {
27+
$.mobile.loading("show");
28+
$.get(url, {}, function (data) {
29+
var tv_toggle = $('#tv_toggle');
30+
var tv_vol = $('#tv_vol');
31+
if (data.loopback !== undefined) {
32+
tv_toggle.val(data.loopback);
33+
}
34+
tv_volume_value = data.volume;
35+
if (data.volume !== undefined) {
36+
tv_vol.val(data.volume);
37+
}
38+
tv_vol.slider("enable");
39+
tv_toggle.slider("enable");
40+
tv_vol.slider("refresh");
41+
tv_toggle.slider("refresh");
42+
$.mobile.loading("hide");
43+
}, "json");
44+
};
45+
setup_main_page();
46+
47+
$('#tv_page').on("pageshow", function (event, ui) {
48+
setup_main_page();
49+
});
4150

4251
$('#tv_vol').change(function (event, ui) {
4352
var val = parseInt($(this).val());
@@ -61,4 +70,21 @@ $(document).ready(function() {
6170
}, "json");
6271
});
6372

73+
function load_system_info(el) {
74+
$.mobile.loading("show");
75+
$.get("/system-info", {}, function (data) {
76+
$.mobile.loading("hide");
77+
$("#system_info").text(data);
78+
}, "text");
79+
};
80+
81+
$('#info_page').on("pageshow", function (event, ui) {
82+
load_system_info();
83+
});
84+
85+
$('#info_refresh').on("click", function (event, ui) {
86+
load_system_info();
87+
return false;
88+
});
89+
6490
});

Diff for: static/style.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.scrollable {
2+
overflow-x: auto;
3+
}

Diff for: sysinfo.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#! /bin/bash
2+
# A brief overview of system metrics
3+
echo Uptime: $(uptime | sed -r 's/.*up(.*) [0-9]+ users?,/\1/')
4+
echo ""
5+
echo Free memory: $(free -t | grep "buffers/cache" | awk '{print $4/($3+$4) * 100}')%
6+
echo ""
7+
echo "Top processes"
8+
echo "%CPU PID COMMAND"
9+
ps -eo pcpu,pid,args | grep -v CPU | sort -k 1 -n -r | head -4
10+
echo ""
11+
echo Wifi $(iwconfig 2> /dev/null | grep 'Link Quality' | sed -r 's/^ *//')
12+
echo ""
13+
echo "Audio playback parameters"
14+
cat /proc/asound/card0/pcm0p/sub0/hw_params
15+
echo ""
16+
echo "Audio capture parameters"
17+
cat /proc/asound/card0/pcm0c/sub0/hw_params

Diff for: webctl.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@
88
from bottle import (route, run, template, static_file, request, response,
99
redirect)
1010

11-
BASE_DIR = join(dirname(abspath(__file__)), "static")
11+
BASE_DIR = join(dirname(abspath(__file__)))
12+
STATIC_DIR = join(BASE_DIR, "static")
1213
AMIXER = "/usr/bin/amixer"
1314
TV_CHANNEL = "Line in"
1415
AMIXER_VOLUME_EXP = re.compile(r"Front Left: \d+ \[(\d+)%\]")
1516
ALSA_LOOP_SERVICE = "/etc/init.d/alsaloop"
17+
SYSINFO_COMMAND = join(BASE_DIR, 'sysinfo.sh')
1618

1719
amixer_state = {}
1820

1921
@route("/")
2022
def index():
21-
return static_file("index.html", root=BASE_DIR)
23+
return static_file("index.html", root=STATIC_DIR)
2224

23-
@route("/static/<filename>")
24-
def static(filename):
25-
if not filename or filename == "index.html":
25+
@route("/static/<filepath:path>")
26+
def static(filepath):
27+
if not filepath or filepath == "index.html":
2628
return redirect("/")
27-
return static_file(filename, root=BASE_DIR)
29+
return static_file(filepath, root=STATIC_DIR)
2830

2931
def tv_volume(value=None):
3032
"""Get/update TV volume
@@ -80,6 +82,14 @@ def set_ctl(actions=[("volume", tv_volume), ("loopback", loop_status)]):
8082
data = request.json
8183
return {field: action(data.get(field)) for field, action in actions}
8284

85+
@route("/system-info")
86+
def system_info():
87+
try:
88+
return check_output(SYSINFO_COMMAND)
89+
except Exception as err:
90+
return "Cannot load system info:\n{}: {}" \
91+
.format(type(err).__name__, err)
92+
8393
def main():
8494
parser = argparse.ArgumentParser(description="Pogo controller web server")
8595
parser.add_argument("--host", default="0.0.0.0")

0 commit comments

Comments
 (0)