Permalink
Browse files

Adding logarithmic scale, zero origine and toggle legend to graph

  • Loading branch information...
1 parent cf27b8d commit 153f49bd7bf8295bf285899c389a6ca33560276f Cyril Feraudet committed Jul 3, 2012
Showing with 119 additions and 21 deletions.
  1. +2 −0 css/perfwatcher.css
  2. +1 −1 etc/definitions.local.php
  3. +55 −8 etc/definitions.php
  4. +6 −9 graph.php
  5. +9 −0 html/contextmenu.html
  6. +41 −3 js/pwgraph.js
  7. +5 −0 lib/functions.graph.php
View
2 css/perfwatcher.css
@@ -22,3 +22,5 @@ li[tag="message"] b { color: green; }
.ui-widget-content { background: white repeat-x scroll 100% 100% #FFFFFF; border: 1px solid #AAAAAA; color: #222222; }
.widget { height: 220px; }
#timespan { background-color:#AAAAAA; opacity:0.6; filter:alpha(opacity=60); position:absolute; }
+li { white-space: nowrap; }
+.contextMenu { width: 145px; }
View
2 etc/definitions.local.php
@@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-function load_graph_definitions_local($logarithmic = false, $tinylegend = false) {
+function load_graph_definitions_local($logarithmic = false, $tinylegend = false, $zero = false) {
global $GraphDefs, $MetaGraphDefs;
// Define 1-rrd Graph definitions here
View
63 etc/definitions.php
@@ -24,7 +24,7 @@
if (is_file('etc/definitions.local.php'))
require_once('etc/definitions.local.php');
-function load_graph_definitions($logarithmic = false, $tinylegend = false) {
+function load_graph_definitions($logarithmic = false, $tinylegend = false, $zero = false) {
global $GraphDefs, $MetaGraphDefs;
$Canvas = 'FFFFFF';
@@ -118,6 +118,40 @@ function load_graph_definitions($logarithmic = false, $tinylegend = false) {
'GPRINT:avg_sum:LAST:(%.1lf%sW/h',
'GPRINT:price:LAST:%.1lf Euros)\l');
+ $GraphDefs['percentidtplx'] = array(
+ '-v', 'Percent', '-r', '-l', '0', '-u', '100',
+ 'DEF:avg_AC={pathplugin}current-AC Avg Power power_management_board (21.0).rrd:value:AVERAGE',
+ 'DEF:avg_A={pathplugin}current-Domain A AvgPwr power_management_board (21.0).rrd:value:AVERAGE',
+ 'DEF:avg_B={pathplugin}current-Domain B AvgPwr power_management_board (21.0).rrd:value:AVERAGE',
+ 'DEF:avg_FAN={pathplugin}current-Chassis Fan Pwr power_management_board (21.0).rrd:value:AVERAGE',
+ 'CDEF:avg_rawa=avg_FAN,avg_A,-',
+ 'CDEF:avg_rawb=avg_rawa,avg_B,-',
+ 'CDEF:avg=0,avg_rawb,-,avg_AC,/,100,*',
+ "LINE1:avg#$FullBlue:Percent",
+ 'GPRINT:avg:AVERAGE:%5.1lf%% Avg,',
+ 'GPRINT:avg:LAST:%5.1lf%% Last\l');
+ $GraphDefs['currentidtplx'] = array(
+ '-v', 'Watt',
+ 'DEF:avg_AC={pathplugin}current-AC Avg Power power_management_board (21.0).rrd:value:AVERAGE',
+ 'DEF:avg_A={pathplugin}current-Domain A AvgPwr power_management_board (21.0).rrd:value:AVERAGE',
+ 'DEF:avg_B={pathplugin}current-Domain B AvgPwr power_management_board (21.0).rrd:value:AVERAGE',
+ 'DEF:avg_FAN={pathplugin}current-Chassis Fan Pwr power_management_board (21.0).rrd:value:AVERAGE',
+ 'CDEF:avg_rawa=avg_AC,avg_A,-',
+ 'CDEF:avg_rawb=avg_rawa,avg_B,-',
+ 'CDEF:avg_raw=avg_rawb,avg_FAN,-',
+ 'CDEF:avg=avg_raw,3600,/',
+ 'CDEF:mytime=avg_raw,TIME,TIME,IF',
+ 'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+ 'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+ 'CDEF:avg_sample=avg,UN,0,avg,IF,sample_len,*',
+ 'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
+ 'CDEF:price=avg_sum,1000,/,0.15,*',
+ "LINE1:avg_raw#$FullBlue:Bits/s",
+ 'GPRINT:avg_raw:AVERAGE:%5.1lf%s Avg,',
+ 'GPRINT:avg_raw:LAST:%5.1lf%s Last',
+ 'GPRINT:avg_sum:LAST:(%.1lf%sW/h',
+ 'GPRINT:price:LAST:%.1lf Euros)\l');
+
$GraphDefs['df'] = array(
'-v', 'Percent', '-l', '0',
'DEF:free_avg={file}:free:AVERAGE',
@@ -1260,16 +1294,29 @@ function load_graph_definitions($logarithmic = false, $tinylegend = false) {
$MetaGraphDefs['dns_transfer'] = 'meta_graph_dns_event';
if (function_exists('load_graph_definitions_local'))
- load_graph_definitions_local($logarithmic, $tinylegend);
+ load_graph_definitions_local($logarithmic, $tinylegend, $zero);
- if ($logarithmic)
- foreach ($GraphDefs as &$GraphDef)
+ if ($logarithmic) {
+ foreach ($GraphDefs as &$GraphDef) {
array_unshift($GraphDef, '-o');
- if ($tinylegend)
- foreach ($GraphDefs as &$GraphDef)
- for ($i = count($GraphDef)-1; $i >=0; $i--)
- if (strncmp('GPRINT:', $GraphDef[$i], 7) == 0)
+ }
+ }
+ if ($zero) {
+ foreach ($GraphDefs as &$GraphDef) {
+ array_unshift($GraphDef, '0');
+ array_unshift($GraphDef, '-l');
+ array_unshift($GraphDef, '-r');
+ }
+ }
+ if ($tinylegend) {
+ foreach ($GraphDefs as &$GraphDef) {
+ for ($i = count($GraphDef)-1; $i >=0; $i--) {
+ if (strncmp('GPRINT:', $GraphDef[$i], 7) == 0) {
unset($GraphDef[$i]);
+ }
+ }
+ }
+ }
}
function meta_graph_files_count($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
View
15 graph.php
@@ -181,14 +181,15 @@ function error500($title, $msg) {
$logscale = (boolean)read_var('logarithmic', $_GET, false);
$tinylegend = (boolean)read_var('tinylegend', $_GET, false);
+$zero = (boolean)read_var('zero', $_GET, false);
// Check that at least 1 RRD exists for the specified request
$all_tinst = collectd_list_types($host, $plugin, $pinst, $type);
if (count($all_tinst) == 0)
return error404($graph_identifier, "No rrd file found for graphing : $host, $plugin, $pinst, $type");
// Now that we are read, do the bulk work
-load_graph_definitions($logscale, $tinylegend);
+load_graph_definitions($logscale, $tinylegend, $zero);
$pinst = strlen($pinst) == 0 ? null : $pinst;
$tinst = strlen($tinst) == 0 ? null : $tinst;
@@ -199,15 +200,11 @@ function error500($title, $msg) {
$opts['logarithmic'] = 1;
if ($tinylegend)
$opts['tinylegend'] = 1;
+if ($zero)
+ $opts['zero'] = 1;
$rrd_cmd = false;
if (isset($MetaGraphDefs[$type])) {
-/*
- $identifiers = array();
- foreach ($all_tinst as &$atinst)
- $identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst);
- collectd_flush($identifiers);
-*/
if ($type == '_') {
$rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts);
} else {
@@ -216,9 +213,9 @@ function error500($title, $msg) {
} else {
// collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst));
if (isset($GraphDefs[$type]))
- $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst);
+ $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst, $opts);
else
- $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst);
+ $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst, $opts);
}
$rrd_cmd[] = 'VRULE:'.$GLOBALS['xcenter'].'#888888:'.date("Y/m/d H\\\\:i\\\\:s",$GLOBALS['xcenter']).'\l:dashes';
$rrd_cmd = array_merge($rrd_cmd,$xconfig);
View
9 html/contextmenu.html
@@ -8,6 +8,15 @@
<li class="export">
<a href="#export">Export graph ...</a>
</li>
+ <li class="tinylegend">
+ <a href="#tinylegend">Toggle legend</a>
+ </li>
+ <li class="logarithmic">
+ <a href="#logarithmic">Logarithmic scale</a>
+ </li>
+ <li class="zero">
+ <a href="#zero">Scale from 0</a>
+ </li>
<li class="setalarm">
<a href="#setalarm">Set an alert ...</a>
</li>
View
44 js/pwgraph.js
@@ -3,6 +3,9 @@
var options = {
begin : -86400,
end : null,
+ zero : 0,
+ logarithmic : 0,
+ tinylegend : 0,
width : 697,
gridXstart : 67,
gridXend : 667,
@@ -45,16 +48,21 @@
var toptime = options['begin'] + Math.round(step * x);
showtop(toptime);
break;
- case 'save':
+ case 'save':
var url = $(current_graph).attr('src') + '&download';
document.location = url;
break;
- case 'export':
+ case 'export':
var url = $(current_graph).attr('src');
document.location = url.replace('graph.php', 'export.php');
break;
+ case 'tinylegend':
+ case 'zero':
+ case 'logarithmic':
+ $(current_graph).pwgraph(action).pwgraph('display');
+ break;
default:
- alert('Available soon ...');
+ alert(action + ' Available soon ...');
break;
}
});
@@ -79,6 +87,9 @@
+ '&begin=' + options['begin']
+ (options['end'] != null ? '&end=' + options['end'] : '')
+ '&width=' + options['width']
+ + '&zero=' + options['zero']
+ + '&logarithmic=' + options['logarithmic']
+ + '&tinylegend=' + options['tinylegend']
+ '&t=' + (new Date()).getTime()
);
return this;
@@ -152,6 +163,33 @@
this.data(options);
return this;
},
+ zero : function() {
+ var options = this.data();
+ if (options['zero'] == 1)
+ options['zero'] = 0;
+ else
+ options['zero'] = 1;
+ this.data(options);
+ return this;
+ },
+ logarithmic : function() {
+ var options = this.data();
+ if (options['logarithmic'] == 1)
+ options['logarithmic'] = 0;
+ else
+ options['logarithmic'] = 1;
+ this.data(options);
+ return this;
+ },
+ tinylegend : function() {
+ var options = this.data();
+ if (options['tinylegend'] == 1)
+ options['tinylegend'] = 0;
+ else
+ options['tinylegend'] = 1;
+ this.data(options);
+ return this;
+ },
setts : function() {
var options = this.data();
$('.graph').each(function (i) {
View
5 lib/functions.graph.php
@@ -558,6 +558,11 @@ function collectd_draw_rrd($host, $plugin, $pinst = null, $type, $tinst = null,
$opts['rrd_opts'] = array();
if (isset($opts['logarithmic']) && $opts['logarithmic'])
array_unshift($opts['rrd_opts'], '-o');
+ if (isset($opts['zero']) && $opts['zero']) {
+ array_unshift($opts['rrd_opts'], '0');
+ array_unshift($opts['rrd_opts'], '-l');
+ array_unshift($opts['rrd_opts'], '-r');
+ }
$rrdinfo = null;
$rrdfile = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, is_null($pinst) ? '' : '-', $pinst, $type, is_null($tinst) ? '' : '-', $tinst);

0 comments on commit 153f49b

Please sign in to comment.