From fd04134830d3111c137b47c7ba25a049ab597715 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Fri, 10 Aug 2012 18:56:30 +0200 Subject: introduce config option datasize to show graphs in bits or bytes Config setting $CONFIG['datasize'] can be set to bits or bytes to show graph data in bits or bytes. Inspired-by: Neptune Ning (Plan) --- conf/config.php | 3 +++ plugin/apache.php | 5 +++-- plugin/df.php | 5 +++-- plugin/disk.php | 3 ++- plugin/filecount.php | 3 ++- plugin/interface.php | 3 ++- plugin/libvirt.php | 6 ++++-- plugin/memcached.php | 6 ++++-- plugin/memory.php | 3 ++- plugin/netlink.php | 3 ++- plugin/postgresql.php | 3 ++- plugin/processes.php | 18 ++++++++++++------ plugin/swap.php | 3 ++- plugin/vserver.php | 6 ++++-- plugin/zfs_arc.php | 11 +++++++---- 15 files changed, 54 insertions(+), 27 deletions(-) diff --git a/conf/config.php b/conf/config.php index 781172d..c6fce92 100644 --- a/conf/config.php +++ b/conf/config.php @@ -25,6 +25,9 @@ $CONFIG['time_range']['uptime'] = 31536000; # show load averages on overview page $CONFIG['showload'] = true; +# show graphs in bits or bytes +$CONFIG['datasize'] = 'bytes'; + # browser cache time for the graphs (in seconds) $CONFIG['cache'] = 90; diff --git a/plugin/apache.php b/plugin/apache.php index 95c12fa..71be4fe 100644 --- a/plugin/apache.php +++ b/plugin/apache.php @@ -19,14 +19,15 @@ switch ($obj->args['type']) { case 'apache_bytes': $obj->data_sources = array('value'); $obj->ds_names = array( - 'value' => 'Bytes/s', + 'value' => sprintf('%s/s', ucfirst($CONFIG['datasize'])), ); $obj->colors = array( 'value' => '0000ff', ); $obj->rrd_title = sprintf('Webserver Traffic%s', !empty($obj->args['pinstance']) ? ' ('.$obj->args['pinstance'].')' : ''); - $obj->rrd_vertical = 'Bytes/s'; + $obj->rrd_vertical = sprintf('%s/s', ucfirst($CONFIG['datasize'])); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'apache_connections': $obj->data_sources = array('value'); diff --git a/plugin/df.php b/plugin/df.php index b5c7e73..33dded9 100644 --- a/plugin/df.php +++ b/plugin/df.php @@ -29,8 +29,9 @@ $obj->width = $width; $obj->heigth = $heigth; $obj->rrd_title = sprintf('Free space (%s)', $obj->args['pinstance']); -$obj->rrd_vertical = 'Bytes'; -$obj->rrd_format = '%5.1lf%sB'; +$obj->rrd_vertical = ucfirst($CONFIG['datasize']); +$obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; +$obj->rrd_format = '%5.1lf%s'; # backwards compatibility if ($CONFIG['version'] < 5) { diff --git a/plugin/disk.php b/plugin/disk.php index e3a5f3d..a776abd 100644 --- a/plugin/disk.php +++ b/plugin/disk.php @@ -33,8 +33,9 @@ switch($obj->args['type']) { break; case 'disk_octets': $obj->rrd_title = sprintf('Disk Traffic (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes per second'; + $obj->rrd_vertical = sprintf('%s per second', ucfirst($CONFIG['datasize'])); $obj->rrd_format = '%5.1lf%s'; + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'disk_ops': $obj->rrd_title = sprintf('Disk Operations (%s)', $obj->args['pinstance']); diff --git a/plugin/filecount.php b/plugin/filecount.php index 2c318a9..68545e7 100644 --- a/plugin/filecount.php +++ b/plugin/filecount.php @@ -23,7 +23,8 @@ switch($obj->args['type']) { $obj->ds_names = array('value' => 'Size'); $obj->colors = array('value' => '0000ff'); $obj->rrd_title = sprintf('Filecount: size (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'files': $obj->ds_names = array('value' => 'Files'); diff --git a/plugin/interface.php b/plugin/interface.php index f200813..107cb27 100644 --- a/plugin/interface.php +++ b/plugin/interface.php @@ -39,7 +39,8 @@ switch($obj->args['type']) { break; case 'if_octets': $obj->rrd_title = sprintf('Interface Traffic (%s)', $obj->args[$instance]); - $obj->rrd_vertical = 'Bytes per second'; + $obj->rrd_vertical = sprintf('%s per second', ucfirst($CONFIG['datasize'])); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'if_packets': $obj->rrd_title = sprintf('Interface Packets (%s)', $obj->args[$instance]); diff --git a/plugin/libvirt.php b/plugin/libvirt.php index 829c592..971b5a7 100644 --- a/plugin/libvirt.php +++ b/plugin/libvirt.php @@ -30,7 +30,8 @@ switch($obj->args['type']) { 'write' => '00b000', ); $obj->rrd_title = sprintf('Disk Traffic (%s)', $obj->args['tinstance']); - $obj->rrd_vertical = 'Bytes per second'; + $obj->rrd_vertical = sprintf('%s per second', ucfirst($CONFIG['datasize'])); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; $obj->rrd_format = '%5.1lf%s'; break; case 'disk_ops': @@ -84,7 +85,8 @@ switch($obj->args['type']) { 'tx' => '00b000', ); $obj->rrd_title = sprintf('Interface Traffic (%s)', $obj->args['tinstance']); - $obj->rrd_vertical = 'Bytes per second'; + $obj->rrd_vertical = sprintf('%s per second', ucfirst($CONFIG['datasize'])); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'if_packets': $obj->data_sources = array('rx', 'tx'); diff --git a/plugin/memcached.php b/plugin/memcached.php index e011c9e..accf6b3 100644 --- a/plugin/memcached.php +++ b/plugin/memcached.php @@ -37,7 +37,8 @@ switch(GET('t')) { 'free' => '0000ff', ); $obj->rrd_title = 'Memcached Memory Usage'; - $obj->rrd_vertical = 'bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; # memcached_command-(flush|get|set).rrd @@ -104,7 +105,8 @@ switch(GET('t')) { 'tx' => '00b000', ); $obj->rrd_title = 'Memcached Network Traffic'; - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; # memcached_ops-(evictions|hits|misses).rrd case 'memcached_ops': diff --git a/plugin/memory.php b/plugin/memory.php index 14779e2..afccc55 100644 --- a/plugin/memory.php +++ b/plugin/memory.php @@ -33,7 +33,8 @@ $obj->width = $width; $obj->heigth = $heigth; $obj->rrd_title = 'Physical memory utilization'; -$obj->rrd_vertical = 'Bytes'; +$obj->rrd_vertical = ucfirst($CONFIG['datasize']); +$obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; $obj->rrd_format = '%5.1lf%s'; collectd_flush($obj->identifiers); diff --git a/plugin/netlink.php b/plugin/netlink.php index 423775d..77c0c48 100644 --- a/plugin/netlink.php +++ b/plugin/netlink.php @@ -64,7 +64,8 @@ switch($obj->args['type']) { 'tx' => '00b000', ); $obj->rrd_title = sprintf('Interface Traffic (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes/s'; + $obj->rrd_vertical = sprintf('%s/s', ucfirst($CONFIG['datasize'])); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'if_packets': $obj->data_sources = array('rx', 'tx'); diff --git a/plugin/postgresql.php b/plugin/postgresql.php index 1eadc8d..ed984a6 100644 --- a/plugin/postgresql.php +++ b/plugin/postgresql.php @@ -51,7 +51,8 @@ switch($obj->args['type']) { ); $obj->rrd_title = sprintf('PostgreSQL DB size (%s)', !empty($obj->args['pinstance']) ? $obj->args['pinstance'] : ''); - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'pg_n_tup_c': $obj->order = array( diff --git a/plugin/processes.php b/plugin/processes.php index dca00b7..c66d3fb 100644 --- a/plugin/processes.php +++ b/plugin/processes.php @@ -63,7 +63,8 @@ switch($obj->args['type']) 'value' => '0000ff', ); $obj->rrd_title = sprintf('Text Resident Set (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'ps_count': @@ -105,7 +106,8 @@ switch($obj->args['type']) 'write' => '00b000', ); $obj->rrd_title = sprintf('Disk Traffic (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes per second'; + $obj->rrd_vertical = sprintf('%s per second', ucfirst($CONFIG['datasize'])); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'ps_disk_ops': @@ -130,7 +132,8 @@ switch($obj->args['type']) 'value' => '0000ff', ); $obj->rrd_title = sprintf('Data Resident Set (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'ps_pagefaults': @@ -155,7 +158,8 @@ switch($obj->args['type']) 'value' => '0000ff', ); $obj->rrd_title = sprintf('Resident Segment Size (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'ps_stacksize': @@ -166,7 +170,8 @@ switch($obj->args['type']) 'value' => '0000ff', ); $obj->rrd_title = sprintf('Stacksize (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'ps_vm': @@ -177,7 +182,8 @@ switch($obj->args['type']) 'value' => '0000ff', ); $obj->rrd_title = sprintf('Virtual Memory (%s)', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; } diff --git a/plugin/swap.php b/plugin/swap.php index c24d90b..dee5692 100644 --- a/plugin/swap.php +++ b/plugin/swap.php @@ -27,7 +27,8 @@ switch(GET('t')) { 'used' => 'ff0000', ); $obj->rrd_title = 'Swap utilization'; - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'swap_io': require_once 'type/GenericIO.class.php'; diff --git a/plugin/vserver.php b/plugin/vserver.php index 57687e3..e51d97d 100644 --- a/plugin/vserver.php +++ b/plugin/vserver.php @@ -51,7 +51,8 @@ switch($obj->args['type']) { $obj->heigth = $heigth; $obj->rrd_title = sprintf('Memory utilization on Vserver %s', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; $obj->rrd_format = '%5.1lf%s'; collectd_flush($obj->identifiers); @@ -104,7 +105,8 @@ switch($obj->args['type']) { 'unspec-tx' => '000080', ); $obj->rrd_title = sprintf('Traffic on Vserver %s', $obj->args['pinstance']); - $obj->rrd_vertical = 'Bytes per second'; + $obj->rrd_vertical = sprintf('%s per second', ucfirst($CONFIG['datasize'])); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; $obj->width = $width; $obj->heigth = $heigth; $obj->rrd_format = '%5.1lf%s'; diff --git a/plugin/zfs_arc.php b/plugin/zfs_arc.php index d40912d..1cc7e81 100644 --- a/plugin/zfs_arc.php +++ b/plugin/zfs_arc.php @@ -60,7 +60,8 @@ switch($obj->args['type']) { 'maxlimit', ); $obj->rrd_title = 'Arc size'; - $obj->rrd_vertical = 'bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'arc_l2_bytes': $obj->data_sources = array( @@ -76,20 +77,22 @@ switch($obj->args['type']) { 'read' => '0000ff', ); $obj->rrd_title = 'Arc L2 bytes'; - $obj->rrd_vertical = 'bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'arc_l2_size': $obj->data_sources = array( 'value', ); $obj->ds_names = array( - 'value' => 'Bytes', + 'value' => ucfirst($CONFIG['datasize']), ); $obj->colors = array( 'value' => '0000ff', ); $obj->rrd_title = 'Arc L2 size'; - $obj->rrd_vertical = 'bytes'; + $obj->rrd_vertical = ucfirst($CONFIG['datasize']); + $obj->scale = $CONFIG['datasize'] == 'bits' ? 8 : 1; break; case 'arc_ratio': $obj->data_sources = array('value'); -- cgit v1.1