added graph of sensors (web server)
[psensor.git] / www / monitor.html
index 57472d3..ce33104 100644 (file)
@@ -5,32 +5,8 @@
 
     <link type="text/css" href="style.css" rel="stylesheet" /> 
     <script type="text/javascript" src="jquery.js"></script>
-
-    <script>
-      function format_mem_size(s) {
-          var mo_bytes = 1024 * 1024;
-          var go_bytes = 1024 * mo_bytes;
-
-          var o = s % 1024;
-          var k = Math.round((s / 1024) % 1024);
-          var m = Math.round((s / (1024*1024)) % 1024);
-          var g = Math.round(s / (1024*1024*1024));
-
-          if (g >= 1)
-               return g+"Go ";
-
-          if (m >= 1)
-               return m+"Mo";
-
-          if (k >= 1)
-               return k+"Ko";
-          if (o > 0)
-               return o+"o";
-
-          return "0";
-      };
-
+    <script type="text/javascript" src="psensor.js"></script>
+    <script>  
       $(document).ready(function() {          
           $.getJSON("/api/1.0/sensors", function(data) {
               $.each(data, function(i, item) {
                   var smin = item["min"];
                   var smax = item["max"];
                   var stype = item["type"];
-                  var stype_str = "N/A";
-                  var unit = "";
-
-                  if (stype & 0x0100) {
-                      stype_str = "Sensor";
-                  } else if (stype & 0x0200) {
-                      stype_str = "NVidia";
-                  } else if (stype & 0x0400) {
-                      stype_str = "HDD";
-                  } else if (stype & 0x0800) {
-                      stype_str = "Fan";
-                  }
-
-                  if (stype & 0x0001) {
-                      stype_str += " Temperature";
-                      unit = " C";
-                  } else if (stype & 0x0002) {
-                      unit = " RPM";
-                  }
-      
-                  $("#sensors").append("<tr><td>"+sname+"</td><td>"+svalue+unit+"</td><td>"+smin+unit+"</td><td>"+smax+unit+"</td><td>"+stype_str+"</td></tr>");                 
+                  var stype_str;
+                  var unit;
+
+                  unit = type_to_unit(stype);
+                  stype_str = type_to_str(stype);
+
+                  $("#sensors").append("<tr>"
+                                      +"<td>"
+                                      +"<a href='details.html?id="+escape(item["id"])
+                                       +"'>"+sname+"</a></td>"
+                                      +"<td>"+svalue+unit+"</td><td>"+smin+unit+"</td><td>"+smax+unit+"</td><td>"+stype_str+"</td></tr>");                 
               });          
           });
 
     </script>
   </head>
   <body>
-
     <div class='page'>
       <div class='page-header'>
        <h1>Psensor Server Monitoring</h1>
       </div>
 
       <div class='page-content'>
+
        <p id='uptime'><strong>Uptime</strong>: </p>
-       
+
        <h2>CPU</h2>
-       
-       <table id='cpu' border='0' cellspacing='0' cellpadding='0'>
-         <thead>
-           <tr>
-             <th>Current usage</th>
-             <th>Load 1mn</th>
-             <th>Load 5mn</th>
-             <th>Load 15mn</th>
-         </tr>
-         </thead>
-         <tbody></tbody>
-       </table>
+
+       <div>
+         <table id='cpu' border='0' cellspacing='0' cellpadding='0'>
+           <thead>
+             <tr>
+               <th>Current usage</th>
+               <th>Load 1mn</th>
+               <th>Load 5mn</th>
+               <th>Load 15mn</th>
+             </tr>
+           </thead>
+           <tbody></tbody>
+         </table>
+       </div>
        
        <h2>Memory</h2>
-       
-       <table border='0' cellspacing='0' cellpadding='0'>
-         <thead>
-           <tr>
-              <th></th>
-             <th>Total</th>
-             <th>Used</th>
-             <th>Free</th>
-             <th>Shared</th>
-             <th>Buffer</th>
-           </tr>
-         </thead>
-         <tbody>
-           <tr id='memory'><td>Memory</td></tr>
-           <tr id='swap'><td>Swap</td></tr>
-         </tbody>
-       </table>
+
+       <div>
+         <table border='0' cellspacing='0' cellpadding='0'>
+           <thead>
+             <tr>
+               <th></th>
+               <th>Total</th>
+               <th>Used</th>
+               <th>Free</th>
+               <th>Shared</th>
+               <th>Buffer</th>
+             </tr>
+           </thead>
+             <tbody>
+               <tr id='memory'><td>Memory</td></tr>
+               <tr id='swap'><td>Swap</td></tr>
+             </tbody>
+           </table>
+       </div>
 
        <h2>Network</h2>
 
-       <table id='net' border='0' cellspacing='0' cellpadding='0'>
-         <thead>
-           <tr>
-             <th>Interface</th>
-             <th>Bytes In</th>
-             <th>Bytes Out</th>
-           </tr>
-         </thead>
-         <tbody>
-         </tbody>
-       </table>
-       
+       <div>
+         <table id='net' border='0' cellspacing='0' cellpadding='0'>
+           <thead>
+             <tr>
+               <th>Interface</th>
+               <th>Bytes In</th>
+               <th>Bytes Out</th>
+             </tr>
+           </thead>
+           <tbody>
+           </tbody>
+         </table>
+       </div>
+
        <h2>Sensors</h2>
-       
-       <table id='sensors' border='0' cellspacing='0' cellpadding='0'>
-         <thead><tr><th>Name</th><th>Value</th><th>Min</th><th>Max</th><th>Type</th></thead>
-         <tbody></tbody>
-       </table>
-      </div>
 
+       <div>
+         <table id='sensors' border='0' cellspacing='0' cellpadding='0'>
+           <thead>
+             <tr>
+               <th>Name</th>
+               <th>Value</th>
+               <th>Min</th>
+               <th>Max</th>
+               <th>Type</th>
+             </tr>
+           </thead>
+           <tbody></tbody>
+         </table>
+       </div>
+      </div>
+      </div>
     </div>
       <div class='page-footer'>
        <a href='http://wpitchoune.net/psensor'>Psensor Server</a> - (c)2011 jeanfi@gmail.com