From e3f1cc22b6f392ba808034ef58e3b7946e3f0ba8 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Fri, 7 Sep 2012 13:48:21 +0200 Subject: add support for varnish plugin categories Since commit collectd-4.10.0-88-g02e12db the varnish plugin groups collected values in categories. The collectd filestructure used for varnish is now: --/- Because this isn't distinguishable from a regular plugin like df, ... df-var-tmp/df_complex-free.rrd ("var" isn't the category here) ... the category is only set with the varnish plugin. Reported-by: Jonathan Huot --- inc/collectd.inc.php | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'inc/collectd.inc.php') diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php index d5a3d83..3c016af 100644 --- a/inc/collectd.inc.php +++ b/inc/collectd.inc.php @@ -33,13 +33,22 @@ function collectd_plugindata($host, $plugin=NULL) { $data = array(); foreach($files as $item) { - preg_match('#([\w_]+)(?:\-(.+))?/([\w_]+)(?:\-(.+))?\.rrd#', $item, $matches); + preg_match('` + (?P

[\w_]+) # plugin + (?:(?<=varnish)(?:\-(?P[\w]+)))? # category + (?:\-(?P.+))? # plugin instance + / + (?P[\w_]+) # type + (?:\-(?P.+))? # type instance + \.rrd + `x', $item, $matches); $data[] = array( - 'p' => $matches[1], - 'pi' => isset($matches[2]) ? $matches[2] : '', - 't' => $matches[3], - 'ti' => isset($matches[4]) ? $matches[4] : '', + 'p' => $matches['p'], + 'c' => isset($matches['c']) ? $matches['c'] : '', + 'pi' => isset($matches['pi']) ? $matches['pi'] : '', + 't' => $matches['t'], + 'ti' => isset($matches['ti']) ? $matches['ti'] : '', ); } @@ -70,7 +79,7 @@ function collectd_plugins($host) { # returns an array of all pi/t/ti of an plugin function collectd_plugindetail($host, $plugin, $detail, $where=NULL) { - $details = array('pi', 't', 'ti'); + $details = array('pi', 'c', 't', 'ti'); if (!in_array($detail, $details)) return false; @@ -122,11 +131,12 @@ function group_plugindata($plugindata) { function plugin_sort($data) { foreach ($data as $key => $row) { $pi[$key] = $row['pi']; + $c[$key] = $row['c']; $ti[$key] = $row['ti']; $t[$key] = $row['t']; } - array_multisort($pi, SORT_ASC, $t, SORT_ASC, $ti, SORT_ASC, $data); + array_multisort($c, SORT_ASC, $pi, SORT_ASC, $t, SORT_ASC, $ti, SORT_ASC, $data); return $data; } @@ -180,20 +190,6 @@ function build_url($base, $items, $s=NULL) { return $base; } -# generate identifier that collectd's FLUSH command understands -function collectd_identifier($host, $plugin, $pinst, $type, $tinst) { - global $CONFIG; - - $identifier = sprintf('%s/%s%s%s/%s%s%s', $host, - $plugin, strlen($pinst) ? '-' : '', $pinst, - $type, strlen($tinst) ? '-' : '', $tinst); - - if (is_file($CONFIG['datadir'].'/'.$identifier.'.rrd')) - return $identifier; - else - return FALSE; -} - # tell collectd to FLUSH all data of the identifier(s) function collectd_flush($identifier) { global $CONFIG; -- cgit v1.1