X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=www%2Fpsensor.js;h=3e902853faa99053eb469f835de90d936cdcdd7c;hb=912b5d1986633786a656bb3361f7ae9c1263acef;hp=862aa1d26dae0de65906d24886ca185111ceafcd;hpb=759199c3e1e9b2edc919379058b9893266952f08;p=psensor.git diff --git a/www/psensor.js b/www/psensor.js index 862aa1d..3e90285 100644 --- a/www/psensor.js +++ b/www/psensor.js @@ -41,29 +41,36 @@ function format_mem_size(s) { return o+"o"; return "0"; -}; +} function type_to_str(stype) { var stype_str; - stype_str = "N/A"; - - if (stype & 0x0100) - stype_str = "Sensor"; - else if (stype & 0x0200) - stype_str = "NVidia"; - else if (stype & 0x0400) - stype_str = "HDD"; - else if (stype & 0x1000) - stype_str = "AMD"; + if (stype & 0x0200) + stype_str = "NVidia "; + else if (stype & 0x0800) + stype_str = "ATI/AMD "; + else + stype_str = ""; - if (stype & 0x0001) - stype_str += " Temperature"; + if (stype & 0x04000) + stype_str += "HDD "; + else if (stype & 0x08000) + stype_str += "CPU "; + else if (stype & 0x10000) + stype_str += "GPU "; + else if (stype & 0x20000) + stype_str += "Fan "; + + if (stype & 0x0001) + stype_str += "Temperature"; else if (stype & 0x0002) - stype_str += " Fan"; + stype_str += "RPM"; + else if (stype & 0x0004) + stype_str += "Load"; return stype_str; -}; +} function type_to_unit(stype) { if (stype & 0x0001) @@ -78,8 +85,7 @@ function value_to_str(value, type) { return value+type_to_unit(type); } -function get_url_params() -{ +function get_url_params() { var vars, hashes, i; vars = []; @@ -99,11 +105,19 @@ function update_chart(chart_id, title, data) { var measures, data_chart, date, entry; var style; + $("#"+chart_id).html(""); + measures = data["measures"]; data_chart = []; + $("h1").html(""); $("h1").append(data["name"]); - $("title").append(data["name"]); + + try { + $("title").html(data["name"]); + } catch(ignore) { + // IE8 doesn't allow to modify the page title + } $.each(measures, function(i, item) { value = item["value"]; @@ -145,25 +159,37 @@ function update_chart(chart_id, title, data) { } ] }; + $.jqplot (chart_id, [data_chart], style); } function update_menu() { var name, link, url, str; - $.getJSON("/api/1.0/sensors", function(data) { - str = "
  • Sensors\n"; + $("#menu-list").append(str); + }); } @@ -171,17 +197,19 @@ function update_menu() { function update_summary_sensors() { var name, value_str, min_str, max_str, type, type_str, url; - $.getJSON("/api/1.0/sensors", function(data) { - $.each(data, function(i, item) { + $.getJSON("/api/1.1/sensors", function(data) { + $("#sensors tbody").html(""); + + $.each(data, function(i, item) { name = item["name"]; type = item["type"]; value_str = value_to_str(item["last_measure"]["value"], type); min_str = value_to_str(item["min"], type); max_str = value_to_str(item["max"], type); type_str = type_to_str(type); - url = "details.html?id="+escape("/api/1.0/sensors/"+item["id"]); + url = "details.html?id="+escape("/api/1.1/sensors/"+item["id"]); - $("#sensors").append("" + $("#sensors tbody").append("" +""+name+"" +""+value_str+"" +""+min_str+"" @@ -190,4 +218,61 @@ function update_summary_sensors() { +""); }); }); +} + +function update_summary_sysinfo() { + $.getJSON("/api/1.1/sysinfo", function(data) { + $("#uptime").html(""); + $("#cpu tbody").html(""); + $("#memory").html(""); + $("#swap").html(""); + $("#net tbody").html(""); + + var load = Math.round(data["load"] * 100); + var load_1 = Math.round(data["load_1"]*1000)/1000; + var load_5 = Math.round(data["load_5"]*1000)/1000; + var load_15 = Math.round(data["load_15"]*1000)/1000; + var uptime = data["uptime"]; + var uptime_s = uptime % 60; + var uptime_mn = Math.floor((uptime / 60) % 60); + var uptime_h = Math.floor((uptime / (60*60)) % 24); + var uptime_d = Math.floor(uptime / (60*60*24)); + + $("#cpu").append(""+load+"%" + +load_1+"" + +load_5+"" + +load_15+""); + + $("#uptime").append(uptime_d+"d "+uptime_h+"h "+uptime_mn+"mn"); + + var ram = data["ram"]; + var swap = data["swap"]; + var mu = data["mem_unit"]; + + var ramtotal = ram["total"]*mu; + var ramfree = ram["free"]*mu; + var ramused = (ram["total"] - ram["free"])*mu; + var ramshared = ram["shared"]*mu; + var rambuffer = ram["buffer"]*mu; + + + $("#memory").append("Memory" + +""+format_mem_size(ramtotal)+"" + +""+format_mem_size(ramused)+"" + +""+format_mem_size(ramfree)+"" + +""+format_mem_size(ramshared)+"" + +""+format_mem_size(rambuffer)+""); + + $("#swap").append("Swap" + +""+format_mem_size(swap["total"]*mu)+"" + +""+format_mem_size(swap["total"]*mu-swap["free"]*mu)+"" + +""+format_mem_size(swap["free"]*mu)+""); + + var netdata = data["net"]; + $.each(netdata, function(i, item) { + $("#net").append(""+item["name"]+"" + +""+format_mem_size(item["bytes_in"])+"" + +""+format_mem_size(item["bytes_out"])+""); + }); + }); } \ No newline at end of file