<meta charset="utf-8">
<title>Sensor </title>
- <link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin">
+ <link type="text/css"
+ rel="stylesheet"
+href="http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin">
- <link type="text/css" href="style.css" rel="stylesheet" />
+ <link href="jqplot.css" rel="stylesheet" type="text/css"/>
+ <link href="style.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="jqplot.js"></script>
- <link type="text/css" href="jqplot.css" rel="stylesheet" />
- <script type="text/javascript" src="jqplot.dateAxisRenderer.js"></script>
+ <script src="jquery.js" type="text/javascript"></script>
+ <script src="jqplot.js" type="text/javascript"></script>
+ <script src="jqplot.dateAxisRenderer.js" type="text/javascript"></script>
- <script type="text/javascript" src="psensor.js"></script>
+ <script src="psensor.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
- var max_date = null;
- var min_date = null;
- var min, max, value;
- var params = get_url_params();
- var url_id = params["id"];
+ var url_id;
- min = max = null;
+ url_id = get_url_params()["id"];
$.getJSON(url_id, function(data) {
- var measures = data["measures"];
- var data_chart = [];
-
- $("#title").append(data["name"]);
- $("title").append(data["name"]);
-
- $.each(measures, function(i, item) {
- value = item["value"];
- var d = new Date(item["time"]*1000);
- var entry = [d, item["value"]];
-
- data_chart.push(entry);
-
- if (max_date == null || max_date < d)
- max_date = d;
-
- if (min_date == null || min_date > d)
- min_date = d;
-
- if (min == null || value < min)
- min = value;
- if (max == null || value > max)
- max = value;
-
- });
-
- var plot1 = $.jqplot ('chart1', [data_chart],
- {
- title: type_to_str(data["type"]),
- axes:{
- xaxis:{
- renderer:$.jqplot.DateAxisRenderer,
- tickOptions:{formatString:'%H:%M:%S'},
- min: min_date,
- max: max_date
- },
- yaxis: {
- min: min-1,
- max: max+1
- }
- },
- series: [{lineWidth:1,showMarker:false}]
- });
- });
+ update_chart("chart", type_to_str(data["type"]), data);
+ });
});
</script>
</head>
<body>
- <div class='page'>
- <div class='page-header'>
- <h1 id='title'></h1>
- </div>
+ <h1></h1>
- <div class="chart">
- <div id='chart1'></div>
- </div>
- </div>
+ <div class="chart" id="chart"></div>
- <div id="footer">Generated by <a href='http://wpitchoune.net/psensor'>psensor-server</a></div>
+ <div id="footer">
+ Generated by <a href='http://wpitchoune.net/psensor'>psensor-server</a>
+ </div>
</body>
</html>
+/*
+ * Copyright (C) 2010-2011 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
function format_mem_size(s) {
- var mo_bytes = 1024 * 1024;
- var go_bytes = 1024 * mo_bytes;
+ var mo_bytes, go_bytes, o, k, m, g;
+
+ mo_bytes = 1024 * 1024;
+ 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));
+ o = s % 1024;
+ k = Math.round((s / 1024) % 1024);
+ m = Math.round((s / (1024*1024)) % 1024);
+ g = Math.round(s / (1024*1024*1024));
if (g >= 1)
return g+"Go ";
};
function type_to_str(stype) {
- var stype_str = "N/A";
+ var stype_str;
- if (stype & 0x0100) {
+ stype_str = "N/A";
+
+ if (stype & 0x0100)
stype_str = "Sensor";
- } else if (stype & 0x0200) {
+ else if (stype & 0x0200)
stype_str = "NVidia";
- } else if (stype & 0x0400) {
+ else if (stype & 0x0400)
stype_str = "HDD";
- } else if (stype & 0x1000) {
+ else if (stype & 0x1000)
stype_str = "AMD";
- }
-
- if (stype & 0x0001) {
+
+ if (stype & 0x0001)
stype_str += " Temperature";
- } else if (stype & 0x0002) {
+ else if (stype & 0x0002)
stype_str += " Fan";
- }
return stype_str;
};
function type_to_unit(stype) {
- if (stype & 0x0001) {
+ if (stype & 0x0001)
unit = " C";
- } else if (stype & 0x0002) {
+ else if (stype & 0x0002)
unit = " RPM";
- }
return unit;
}
function get_url_params()
{
- var vars = [], hash;
- var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
- for(var i = 0; i < hashes.length; i++)
- {
+ var vars, hashes, i;
+
+ vars = [];
+ hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
+
+ for(i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
+
return vars;
}
+function update_chart(chart_id, title, data) {
+ var min_date, max_date, min, max, value;
+ var measures, data_chart, date, entry;
+ var style;
+
+ measures = data["measures"];
+ data_chart = [];
+
+ $("h1").append(data["name"]);
+ $("title").append(data["name"]);
+
+ $.each(measures, function(i, item) {
+ value = item["value"];
+ date = new Date(item["time"]*1000);
+ entry = [date, item["value"]];
+
+ data_chart.push(entry);
+
+ if (!max_date || max_date < date)
+ max_date = date;
+ if (!min_date || min_date > date)
+ min_date = date;
+
+ if (!min || value < min)
+ min = value;
+ if (!max || value > max)
+ max = value;
+ });
+
+ style = {
+ title: title,
+ axes: {
+ xaxis: {
+ renderer: $.jqplot.DateAxisRenderer,
+ tickOptions: {
+ formatString:'%H:%M:%S'
+ },
+ min: min_date,
+ max: max_date
+ },
+ yaxis: {
+ min: min-1,
+ max: max+1
+ }
+ },
+ series: [ {
+ lineWidth: 1,
+ showMarker:false
+ } ]
+ };
+
+ $.jqplot (chart_id, [data_chart], style);
+}
\ No newline at end of file