From 95c70c919837f588389f525fe2cf4aba479e9f91 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Thu, 31 Dec 2009 11:42:56 +0100 Subject: rewrite of type classes A constructor is added to the Type_Default class. The constructor will parse GET values (such as host, plugin, pinstance, type, tinstance, seconds), create an array of all needed rrd files to generate a graph and substract identifiers from these rrd files. Because of the constructor (and related functions) it is not needed to define an array of tinstances to be grouped and shown in one graph. Also $obj->args don't have to be defined per plugin. This will result in smaller plugin files. The type classes are based on the fact that a plugin has multiple type instances OR multiple rrd data sources. This is called the source and is retrieved by rrd_get_sources in each rrd_gen_graph function. Also variables in function rrd_gen_graph have been renamed to better ones. --- plugin/interface.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'plugin/interface.php') diff --git a/plugin/interface.php b/plugin/interface.php index 7d8d929..89e4280 100644 --- a/plugin/interface.php +++ b/plugin/interface.php @@ -12,15 +12,7 @@ require_once 'inc/collectd.inc.php'; # interface/if_octets-XXXX.rrd # interface/if_packets-XXXX.rrd -$obj = new Type_GenericIO; -$obj->datadir = $CONFIG['datadir']; -$obj->args = array( - 'host' => $host, - 'plugin' => $plugin, - 'pinstance' => $pinstance, - 'type' => $type, - 'tinstance' => $tinstance, -); +$obj = new Type_GenericIO($CONFIG['datadir']); $obj->data_sources = array('rx', 'tx'); $obj->ds_names = array( 'rx' => 'Receive ', @@ -32,25 +24,24 @@ $obj->colors = array( ); $obj->width = $width; $obj->heigth = $heigth; -$obj->seconds = $seconds; $obj->rrd_format = '%5.1lf%s'; -switch($type) { + +switch($obj->args['type']) { case 'if_errors': - $obj->rrd_title = sprintf('Interface Errors (%s)', $tinstance); + $obj->rrd_title = sprintf('Interface Errors (%s)', $obj->args['tinstance']); $obj->rrd_vertical = 'Errors per second'; break; case 'if_octets': - $obj->rrd_title = sprintf('Interface Traffic (%s)', $tinstance); + $obj->rrd_title = sprintf('Interface Traffic (%s)', $obj->args['tinstance']); $obj->rrd_vertical = 'Bits per second'; break; case 'if_packets': - $obj->rrd_title = sprintf('Interface Packets (%s)', $tinstance); + $obj->rrd_title = sprintf('Interface Packets (%s)', $obj->args['tinstance']); $obj->rrd_vertical = 'Packets per second'; break; } -collectd_flush(ident_from_args($obj->args)); - +collectd_flush($obj->identifiers); $obj->rrd_graph(); ?> -- cgit v1.1