X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=www%2Fpsensor.js;h=3e902853faa99053eb469f835de90d936cdcdd7c;hb=c1e20f2631a1249720e9c75d753eacfcb0f6c7b9;hp=925f3d4d9792a660277a273f8326625ac2d4a12e;hpb=09c3a371e5e48ea84a9dc3a591564d58cfeaadd6;p=psensor.git diff --git a/www/psensor.js b/www/psensor.js index 925f3d4..3e90285 100644 --- a/www/psensor.js +++ b/www/psensor.js @@ -41,41 +41,51 @@ 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) - unit = " C"; + unit = "C"; else if (stype & 0x0002) - unit = " RPM"; + unit = "RPM"; return unit; } -function get_url_params() -{ +function value_to_str(value, type) { + return value+type_to_unit(type); +} + +function get_url_params() { var vars, hashes, i; vars = []; @@ -95,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"]; @@ -137,9 +155,124 @@ function update_chart(chart_id, title, data) { }, series: [ { lineWidth: 1, - showMarker:false + showMarker: false } ] }; + $.jqplot (chart_id, [data_chart], style); +} + +function update_menu() { + var name, link, url, str; + + str = ""; + + $.getJSON("/api/1.1/sensors", function(data) { + str += "
  • CPU"; + + str += "
  • Network
  • "; + + str += "
  • Memory
  • "; + + str += "
  • Sensors\n"; + + $("#menu-list").append(str); + + }); + +} + +function update_summary_sensors() { + var name, value_str, min_str, max_str, type, type_str, url; + + $.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.1/sensors/"+item["id"]); + + $("#sensors tbody").append("" + +""+name+"" + +""+value_str+"" + +""+min_str+"" + +""+max_str+"" + +""+type_str+"" + +""); + }); + }); +} + +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