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><em>Sensors</em>\n<ul>";
174 $.each(data, function(i, item) {
176 url = "details.html?id="+escape("/api/1.1/sensors/"+item["id"]);
177 link = "<a href='"+url+"'>"+name+"</a>";
178 str += "<li>"+link+"</li>";
182 str += "<li><em>CPU</em><ul>";
183 url = "details.html?id="+escape("/api/1.1/cpu/usage");
184 link = "<a href='"+url+"'>usage</a>";
185 str += "<li>"+link+"</li>";
189 $("#menu-list").append(str);
195 function update_summary_sensors() {
196 var name, value_str, min_str, max_str, type, type_str, url;
198 $.getJSON("/api/1.1/sensors", function(data) {
199 $("#sensors tbody").html("");
201 $.each(data, function(i, item) {
204 value_str = value_to_str(item["last_measure"]["value"], type);
205 min_str = value_to_str(item["min"], type);
206 max_str = value_to_str(item["max"], type);
207 type_str = type_to_str(type);
208 url = "details.html?id="+escape("/api/1.1/sensors/"+item["id"]);
210 $("#sensors tbody").append("<tr>"
211 +"<td><a href='"+url+"'>"+name+"</a></td>"
212 +"<td>"+value_str+"</td>"
213 +"<td>"+min_str+"</td>"
214 +"<td>"+max_str+"</td>"
215 +"<td>"+type_str+"</td>"
221 function update_summary_sysinfo() {
222 $.getJSON("/api/1.1/sysinfo", function(data) {
223 $("#uptime").html("");
224 $("#cpu tbody").html("");
225 $("#memory").html("");
227 $("#net tbody").html("");
229 var load = Math.round(data["load"] * 100);
230 var load_1 = Math.round(data["load_1"]*1000)/1000;
231 var load_5 = Math.round(data["load_5"]*1000)/1000;
232 var load_15 = Math.round(data["load_15"]*1000)/1000;
233 var uptime = data["uptime"];
234 var uptime_s = uptime % 60;
235 var uptime_mn = Math.floor((uptime / 60) % 60);
236 var uptime_h = Math.floor((uptime / (60*60)) % 24);
237 var uptime_d = Math.floor(uptime / (60*60*24));
239 $("#cpu").append("<tr><td><a href='details.html?id=/api/1.1/cpu/usage'>"+load+"%</a></td><td>"
242 +load_15+"</td></tr>");
244 $("#uptime").append(uptime_d+"d "+uptime_h+"h "+uptime_mn+"mn");
246 var ram = data["ram"];
247 var swap = data["swap"];
248 var mu = data["mem_unit"];
250 var ramtotal = ram["total"]*mu;
251 var ramfree = ram["free"]*mu;
252 var ramused = (ram["total"] - ram["free"])*mu;
253 var ramshared = ram["shared"]*mu;
254 var rambuffer = ram["buffer"]*mu;
257 $("#memory").append("<td>Memory</td>"
258 +"<td>"+format_mem_size(ramtotal)+"</td>"
259 +"<td>"+format_mem_size(ramused)+"</td>"
260 +"<td>"+format_mem_size(ramfree)+"</td>"
261 +"<td>"+format_mem_size(ramshared)+"</td>"
262 +"<td>"+format_mem_size(rambuffer)+"</td>");
264 $("#swap").append("<td>Swap</td>"
265 +"<td>"+format_mem_size(swap["total"]*mu)+"</td>"
266 +"<td>"+format_mem_size(swap["total"]*mu-swap["free"]*mu)+"</td>"
267 +"<td>"+format_mem_size(swap["free"]*mu)+"</td>");
269 var netdata = data["net"];
270 $.each(netdata, function(i, item) {
271 $("#net").append("<tr><td>"+item["name"]+"</td>"
272 +"<td>"+format_mem_size(item["bytes_in"])+"</td>"
273 +"<td>"+format_mem_size(item["bytes_out"])+"</td></tr>");