From aa454ff4b3d4d5be9d5cc9dff4b4246c6e655f3e Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Wed, 4 Nov 2009 21:05:37 +0100 Subject: remove path_format from plugins The relative path to an rrd file can be generated based on host, plugin, plugin instance, type and type instance. In this case path_format is not needed anymore. This commit includes code based on the collectd_identifier function from php-collection by Bruno Prémont. --- plugin/cpu.php | 1 - plugin/df.php | 1 - plugin/disk.php | 1 - plugin/entropy.php | 1 - plugin/interface.php | 1 - plugin/irq.php | 1 - plugin/load.php | 1 - plugin/memory.php | 1 - plugin/processes.php | 1 - plugin/sensors.php | 1 - plugin/swap.php | 1 - plugin/users.php | 1 - type/Default.class.php | 22 +++++++++++++++++----- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/plugin/cpu.php b/plugin/cpu.php index 04ef3a4..d750a3a 100644 --- a/plugin/cpu.php +++ b/plugin/cpu.php @@ -22,7 +22,6 @@ $tinstance = collectd_plugindetail($host, $plugin, 'ti'); $obj = new Type_GenericStacked; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}-{pinstance}/{type}-{tinstance}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/df.php b/plugin/df.php index 780ca0c..f4dd5d6 100644 --- a/plugin/df.php +++ b/plugin/df.php @@ -12,7 +12,6 @@ require_once 'type/GenericStacked.class.php'; $obj = new Type_GenericStacked; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/disk.php b/plugin/disk.php index e73cbac..0c18016 100644 --- a/plugin/disk.php +++ b/plugin/disk.php @@ -14,7 +14,6 @@ require_once 'type/GenericIO.class.php'; $obj = new Type_GenericIO; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}-{pinstance}/{type}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/entropy.php b/plugin/entropy.php index 58d810b..dcfbcc8 100644 --- a/plugin/entropy.php +++ b/plugin/entropy.php @@ -10,7 +10,6 @@ require_once 'type/Default.class.php'; $obj = new Type_Default; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/interface.php b/plugin/interface.php index bda0550..a3fca3d 100644 --- a/plugin/interface.php +++ b/plugin/interface.php @@ -13,7 +13,6 @@ require_once 'type/GenericIO.class.php'; $obj = new Type_GenericIO; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/irq.php b/plugin/irq.php index 6a05245..e442142 100644 --- a/plugin/irq.php +++ b/plugin/irq.php @@ -16,7 +16,6 @@ sort($tinstance); $obj = new Type_GenericStacked; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/load.php b/plugin/load.php index 17002ea..0246edc 100644 --- a/plugin/load.php +++ b/plugin/load.php @@ -10,7 +10,6 @@ require_once 'type/Default.class.php'; $obj = new Type_Default; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/memory.php b/plugin/memory.php index 29f93fe..6cef5a7 100644 --- a/plugin/memory.php +++ b/plugin/memory.php @@ -18,7 +18,6 @@ $tinstance = collectd_plugindetail($host, $plugin, 'ti'); $obj = new Type_GenericStacked; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/processes.php b/plugin/processes.php index 32a925d..c741a02 100644 --- a/plugin/processes.php +++ b/plugin/processes.php @@ -20,7 +20,6 @@ $tinstance = collectd_plugindetail($host, $plugin, 'ti'); $obj = new Type_GenericStacked; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/sensors.php b/plugin/sensors.php index c7f038b..b1b15cf 100644 --- a/plugin/sensors.php +++ b/plugin/sensors.php @@ -17,7 +17,6 @@ $tinstance = collectd_plugindetail($host, $plugin, 'ti', array('t' => $type)); $obj = new Type_Default; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}-{pinstance}/{type}-{tinstance}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/swap.php b/plugin/swap.php index d1ba823..7160ec3 100644 --- a/plugin/swap.php +++ b/plugin/swap.php @@ -17,7 +17,6 @@ $tinstance = collectd_plugindetail($host, $plugin, 'ti'); $obj = new Type_GenericStacked; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/plugin/users.php b/plugin/users.php index 41d4c25..00874a2 100644 --- a/plugin/users.php +++ b/plugin/users.php @@ -10,7 +10,6 @@ require_once 'type/Default.class.php'; $obj = new Type_Default; $obj->datadir = $CONFIG['datadir']; -$obj->path_format = '{host}/{plugin}/{type}.rrd'; $obj->args = array( 'host' => $host, 'plugin' => $plugin, diff --git a/type/Default.class.php b/type/Default.class.php index 8a5dd72..f40d12d 100644 --- a/type/Default.class.php +++ b/type/Default.class.php @@ -46,14 +46,26 @@ class Type_Default { return $c[r].$c[g].$c[b]; } + function identifier($host, $plugin, $pinst, $type, $tinst) { + $identifier = sprintf('%s/%s%s%s/%s%s%s', $host, + $plugin, strlen($pinst) ? '-' : '', $pinst, + $type, strlen($tinst) ? '-' : '', $tinst); + + if (is_file($this->datadir.'/'.$identifier.'.rrd')) + return $identifier; + else + return FALSE; + } + function get_filename($tinstance=NULL) { if (!is_array($this->args['tinstance']) && $tinstance == NULL) $tinstance = $this->args['tinstance']; - - $search = array('{host}', '{plugin}', '{pinstance}', '{type}', '{tinstance}'); - $replace = array($this->args['host'], $this->args['plugin'], $this->args['pinstance'], $this->args['type'], $tinstance); - $f = $this->datadir . '/' . str_replace($search, $replace, $this->path_format); - return $f; + + $identifier = $this->identifier($this->args['host'], + $this->args['plugin'], $this->args['pinstance'], + $this->args['type'], $tinstance); + + return $this->datadir.'/'.$identifier.'.rrd'; } function rrd_graph($debug=false) { -- cgit v1.1