2 * Copyright (C) 2010-2011 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 function format_mem_size(s) {
21 var mo_bytes, go_bytes, o, k, m, g;
23 mo_bytes = 1024 * 1024;
24 go_bytes = 1024 * mo_bytes;
27 k = Math.round((s / 1024) % 1024);
28 m = Math.round((s / (1024*1024)) % 1024);
29 g = Math.round(s / (1024*1024*1024));
46 function type_to_str(stype) {
50 stype_str = "NVidia ";
51 else if (stype & 0x0800)
52 stype_str = "ATI/AMD ";
58 else if (stype & 0x08000)
60 else if (stype & 0x10000)
62 else if (stype & 0x20000)
66 stype_str += "Temperature";
67 else if (stype & 0x0002)
69 else if (stype & 0x0004)
75 function type_to_unit(stype) {
78 else if (stype & 0x0002)
84 function value_to_str(value, type) {
85 return value+type_to_unit(type);
88 function get_url_params() {
92 hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
94 for(i = 0; i < hashes.length; i++) {
95 hash = hashes[i].split('=');
97 vars[hash[0]] = hash[1];
103 function update_chart(chart_id, title, data) {
104 var min_date, max_date, min, max, value;
105 var measures, data_chart, date, entry;
108 $("#"+chart_id).html("");
110 measures = data["measures"];
114 $("h1").append(data["name"]);
117 $("title").html(data["name"]);
119 // IE8 doesn't allow to modify the page title
122 $.each(measures, function(i, item) {
123 value = item["value"];
124 date = new Date(item["time"]*1000);
125 entry = [date, item["value"]];
127 data_chart.push(entry);
129 if (!max_date || max_date < date)
131 if (!min_date || min_date > date)
134 if (!min || value < min)
136 if (!max || value > max)
144 renderer: $.jqplot.DateAxisRenderer,
146 formatString:'%H:%M:%S'
163 $.jqplot (chart_id, [data_chart], style);
166 function update_menu() {
167 var name, link, url, str;
171 $.getJSON("/api/1.1/sensors", function(data) {
172 str += "<li><a href=\"index.html#cpu\">CPU</a><ul>";
173 url = "details.html?id="+escape("/api/1.1/cpu/usage");
174 link = "<a href='"+url+"'>usage</a>";
175 str += "<li>"+link+"</li>";
178 str += "<li><a href=\"index.html#network\">Network</a></li>";
180 str += "<li><a href=\"index.html#memory\">Memory</a></li>";
182 str += "<li><a href=\"index.html#sensors\">Sensors</a>\n<ul>";
183 $.each(data, function(i, item) {
185 url = "details.html?id="+escape("/api/1.1/sensors/"+item["id"]);
186 link = "<a href='"+url+"'>"+name+"</a>";
187 str += "<li>"+link+"</li>";
191 $("#menu-list").append(str);
197 function update_summary_sensors() {
198 var name, value_str, min_str, max_str, type, type_str, url;
200 $.getJSON("/api/1.1/sensors", function(data) {
201 $("#sensors tbody").html("");
203 $.each(data, function(i, item) {
206 value_str = value_to_str(item["last_measure"]["value"], type);
207 min_str = value_to_str(item["min"], type);
208 max_str = value_to_str(item["max"], type);
209 type_str = type_to_str(type);
210 url = "details.html?id="+escape("/api/1.1/sensors/"+item["id"]);
212 $("#sensors tbody").append("<tr>"
213 +"<td><a href='"+url+"'>"+name+"</a></td>"
214 +"<td>"+value_str+"</td>"
215 +"<td>"+min_str+"</td>"
216 +"<td>"+max_str+"</td>"
217 +"<td>"+type_str+"</td>"
223 function update_summary_sysinfo() {
224 $.getJSON("/api/1.1/sysinfo", function(data) {
225 $("#uptime").html("");
226 $("#cpu tbody").html("");
227 $("#memory").html("");
229 $("#net tbody").html("");
231 var load = Math.round(data["load"] * 100);
232 var load_1 = Math.round(data["load_1"]*1000)/1000;
233 var load_5 = Math.round(data["load_5"]*1000)/1000;
234 var load_15 = Math.round(data["load_15"]*1000)/1000;
235 var uptime = data["uptime"];
236 var uptime_s = uptime % 60;
237 var uptime_mn = Math.floor((uptime / 60) % 60);
238 var uptime_h = Math.floor((uptime / (60*60)) % 24);
239 var uptime_d = Math.floor(uptime / (60*60*24));
241 $("#cpu").append("<tr><td><a href='details.html?id=/api/1.1/cpu/usage'>"+load+"%</a></td><td>"
244 +load_15+"</td></tr>");
246 $("#uptime").append(uptime_d+"d "+uptime_h+"h "+uptime_mn+"mn");
248 var ram = data["ram"];
249 var swap = data["swap"];
250 var mu = data["mem_unit"];
252 var ramtotal = ram["total"]*mu;
253 var ramfree = ram["free"]*mu;
254 var ramused = (ram["total"] - ram["free"])*mu;
255 var ramshared = ram["shared"]*mu;
256 var rambuffer = ram["buffer"]*mu;
259 $("#memory").append("<td>Memory</td>"
260 +"<td>"+format_mem_size(ramtotal)+"</td>"
261 +"<td>"+format_mem_size(ramused)+"</td>"
262 +"<td>"+format_mem_size(ramfree)+"</td>"
263 +"<td>"+format_mem_size(ramshared)+"</td>"
264 +"<td>"+format_mem_size(rambuffer)+"</td>");
266 $("#swap").append("<td>Swap</td>"
267 +"<td>"+format_mem_size(swap["total"]*mu)+"</td>"
268 +"<td>"+format_mem_size(swap["total"]*mu-swap["free"]*mu)+"</td>"
269 +"<td>"+format_mem_size(swap["free"]*mu)+"</td>");
271 var netdata = data["net"];
272 $.each(netdata, function(i, item) {
273 $("#net").append("<tr><td>"+item["name"]+"</td>"
274 +"<td>"+format_mem_size(item["bytes_in"])+"</td>"
275 +"<td>"+format_mem_size(item["bytes_out"])+"</td></tr>");