diff options
author | Pim van den Berg | 2012-09-07 13:48:21 +0200 |
---|---|---|
committer | Pim van den Berg | 2012-09-07 14:09:34 +0200 |
commit | e3f1cc22b6f392ba808034ef58e3b7946e3f0ba8 (patch) | |
tree | dd7c34e42c0a25b0e2ca47c55a3e3cf9c58875b3 | |
parent | plugin/snmp: add support for if_octets (diff) | |
download | apt-panopticon_cgp-e3f1cc22b6f392ba808034ef58e3b7946e3f0ba8.zip apt-panopticon_cgp-e3f1cc22b6f392ba808034ef58e3b7946e3f0ba8.tar.gz apt-panopticon_cgp-e3f1cc22b6f392ba808034ef58e3b7946e3f0ba8.tar.bz2 apt-panopticon_cgp-e3f1cc22b6f392ba808034ef58e3b7946e3f0ba8.tar.xz |
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:
<plugin>-<category>-<plugin_instance>/<type>-<type_instance>
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 <jonathan.huot@gmail.com>
Diffstat (limited to '')
-rw-r--r-- | detail.php | 1 | ||||
-rw-r--r-- | inc/collectd.inc.php | 38 | ||||
-rw-r--r-- | inc/functions.inc.php | 1 | ||||
-rw-r--r-- | plugin/varnish.php | 17 | ||||
-rw-r--r-- | type/Default.class.php | 12 |
5 files changed, 31 insertions, 38 deletions
@@ -14,6 +14,7 @@ if (empty($_GET['y'])) | |||
14 | $host = validate_get(GET('h'), 'host'); | 14 | $host = validate_get(GET('h'), 'host'); |
15 | $plugin = validate_get(GET('p'), 'plugin'); | 15 | $plugin = validate_get(GET('p'), 'plugin'); |
16 | $pinstance = validate_get(GET('pi'), 'pinstance'); | 16 | $pinstance = validate_get(GET('pi'), 'pinstance'); |
17 | $category = validate_get(GET('c'), 'category'); | ||
17 | $type = validate_get(GET('t'), 'type'); | 18 | $type = validate_get(GET('t'), 'type'); |
18 | $tinstance = validate_get(GET('ti'), 'tinstance'); | 19 | $tinstance = validate_get(GET('ti'), 'tinstance'); |
19 | $width = GET('x'); | 20 | $width = GET('x'); |
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) { | |||
33 | 33 | ||
34 | $data = array(); | 34 | $data = array(); |
35 | foreach($files as $item) { | 35 | foreach($files as $item) { |
36 | preg_match('#([\w_]+)(?:\-(.+))?/([\w_]+)(?:\-(.+))?\.rrd#', $item, $matches); | 36 | preg_match('` |
37 | (?P<p>[\w_]+) # plugin | ||
38 | (?:(?<=varnish)(?:\-(?P<c>[\w]+)))? # category | ||
39 | (?:\-(?P<pi>.+))? # plugin instance | ||
40 | / | ||
41 | (?P<t>[\w_]+) # type | ||
42 | (?:\-(?P<ti>.+))? # type instance | ||
43 | \.rrd | ||
44 | `x', $item, $matches); | ||
37 | 45 | ||
38 | $data[] = array( | 46 | $data[] = array( |
39 | 'p' => $matches[1], | 47 | 'p' => $matches['p'], |
40 | 'pi' => isset($matches[2]) ? $matches[2] : '', | 48 | 'c' => isset($matches['c']) ? $matches['c'] : '', |
41 | 't' => $matches[3], | 49 | 'pi' => isset($matches['pi']) ? $matches['pi'] : '', |
42 | 'ti' => isset($matches[4]) ? $matches[4] : '', | 50 | 't' => $matches['t'], |
51 | 'ti' => isset($matches['ti']) ? $matches['ti'] : '', | ||
43 | ); | 52 | ); |
44 | } | 53 | } |
45 | 54 | ||
@@ -70,7 +79,7 @@ function collectd_plugins($host) { | |||
70 | 79 | ||
71 | # returns an array of all pi/t/ti of an plugin | 80 | # returns an array of all pi/t/ti of an plugin |
72 | function collectd_plugindetail($host, $plugin, $detail, $where=NULL) { | 81 | function collectd_plugindetail($host, $plugin, $detail, $where=NULL) { |
73 | $details = array('pi', 't', 'ti'); | 82 | $details = array('pi', 'c', 't', 'ti'); |
74 | if (!in_array($detail, $details)) | 83 | if (!in_array($detail, $details)) |
75 | return false; | 84 | return false; |
76 | 85 | ||
@@ -122,11 +131,12 @@ function group_plugindata($plugindata) { | |||
122 | function plugin_sort($data) { | 131 | function plugin_sort($data) { |
123 | foreach ($data as $key => $row) { | 132 | foreach ($data as $key => $row) { |
124 | $pi[$key] = $row['pi']; | 133 | $pi[$key] = $row['pi']; |
134 | $c[$key] = $row['c']; | ||
125 | $ti[$key] = $row['ti']; | 135 | $ti[$key] = $row['ti']; |
126 | $t[$key] = $row['t']; | 136 | $t[$key] = $row['t']; |
127 | } | 137 | } |
128 | 138 | ||
129 | array_multisort($pi, SORT_ASC, $t, SORT_ASC, $ti, SORT_ASC, $data); | 139 | array_multisort($c, SORT_ASC, $pi, SORT_ASC, $t, SORT_ASC, $ti, SORT_ASC, $data); |
130 | 140 | ||
131 | return $data; | 141 | return $data; |
132 | } | 142 | } |
@@ -180,20 +190,6 @@ function build_url($base, $items, $s=NULL) { | |||
180 | return $base; | 190 | return $base; |
181 | } | 191 | } |
182 | 192 | ||
183 | # generate identifier that collectd's FLUSH command understands | ||
184 | function collectd_identifier($host, $plugin, $pinst, $type, $tinst) { | ||
185 | global $CONFIG; | ||
186 | |||
187 | $identifier = sprintf('%s/%s%s%s/%s%s%s', $host, | ||
188 | $plugin, strlen($pinst) ? '-' : '', $pinst, | ||
189 | $type, strlen($tinst) ? '-' : '', $tinst); | ||
190 | |||
191 | if (is_file($CONFIG['datadir'].'/'.$identifier.'.rrd')) | ||
192 | return $identifier; | ||
193 | else | ||
194 | return FALSE; | ||
195 | } | ||
196 | |||
197 | # tell collectd to FLUSH all data of the identifier(s) | 193 | # tell collectd to FLUSH all data of the identifier(s) |
198 | function collectd_flush($identifier) { | 194 | function collectd_flush($identifier) { |
199 | global $CONFIG; | 195 | global $CONFIG; |
diff --git a/inc/functions.inc.php b/inc/functions.inc.php index 39f1cd0..a72a589 100644 --- a/inc/functions.inc.php +++ b/inc/functions.inc.php | |||
@@ -15,6 +15,7 @@ function validate_get($value, $type) { | |||
15 | return NULL; | 15 | return NULL; |
16 | break; | 16 | break; |
17 | case 'plugin': | 17 | case 'plugin': |
18 | case 'category': | ||
18 | case 'type': | 19 | case 'type': |
19 | if (!preg_match('/^\w+$/u', $value)) | 20 | if (!preg_match('/^\w+$/u', $value)) |
20 | return NULL; | 21 | return NULL; |
diff --git a/plugin/varnish.php b/plugin/varnish.php index 4de4463..8099691 100644 --- a/plugin/varnish.php +++ b/plugin/varnish.php | |||
@@ -26,19 +26,8 @@ $obj = new Type_Default($CONFIG); | |||
26 | $obj->width = $width; | 26 | $obj->width = $width; |
27 | $obj->heigth = $heigth; | 27 | $obj->heigth = $heigth; |
28 | $obj->rrd_format = '%5.1lf%s'; | 28 | $obj->rrd_format = '%5.1lf%s'; |
29 | switch($obj->args['pinstance']) { | 29 | $obj->rrd_title = sprintf('%s (%s)', ucfirst($obj->args['pinstance']), $obj->args['category']); |
30 | case 'default-backend': | 30 | $obj->rrd_vertical = 'hits'; |
31 | $obj->rrd_title = 'backend'; | 31 | |
32 | $obj->rrd_vertical = 'hits'; | ||
33 | break; | ||
34 | case 'default-cache': | ||
35 | $obj->rrd_title = 'cache'; | ||
36 | $obj->rrd_vertical = 'hits'; | ||
37 | break; | ||
38 | case 'default-connections': | ||
39 | $obj->rrd_title = 'connections'; | ||
40 | $obj->rrd_vertical = 'hits'; | ||
41 | break; | ||
42 | } | ||
43 | collectd_flush($obj->identifiers); | 32 | collectd_flush($obj->identifiers); |
44 | $obj->rrd_graph(); | 33 | $obj->rrd_graph(); |
diff --git a/type/Default.class.php b/type/Default.class.php index b8650dc..dec583b 100644 --- a/type/Default.class.php +++ b/type/Default.class.php | |||
@@ -62,6 +62,7 @@ class Type_Default { | |||
62 | 'host' => GET('h'), | 62 | 'host' => GET('h'), |
63 | 'plugin' => GET('p'), | 63 | 'plugin' => GET('p'), |
64 | 'pinstance' => GET('pi'), | 64 | 'pinstance' => GET('pi'), |
65 | 'category' => GET('c'), | ||
65 | 'type' => GET('t'), | 66 | 'type' => GET('t'), |
66 | 'tinstance' => GET('ti'), | 67 | 'tinstance' => GET('ti'), |
67 | ); | 68 | ); |
@@ -120,9 +121,14 @@ class Type_Default { | |||
120 | } | 121 | } |
121 | 122 | ||
122 | function get_filenames() { | 123 | function get_filenames() { |
123 | $identifier = sprintf('%s/%s%s%s/%s%s%s', $this->args['host'], | 124 | $identifier = sprintf('%s/%s%s%s%s%s/%s%s%s', |
124 | $this->args['plugin'], strlen($this->args['pinstance']) ? '-' : '', $this->args['pinstance'], | 125 | $this->args['host'], |
125 | $this->args['type'], strlen($this->args['tinstance']) ? '-' : '', $this->args['tinstance']); | 126 | $this->args['plugin'], |
127 | strlen($this->args['category']) ? '-' : '', $this->args['category'], | ||
128 | strlen($this->args['pinstance']) ? '-' : '', $this->args['pinstance'], | ||
129 | $this->args['type'], | ||
130 | strlen($this->args['tinstance']) ? '-' : '', $this->args['tinstance'] | ||
131 | ); | ||
126 | 132 | ||
127 | $wildcard = strlen($this->args['tinstance']) ? '.' : '[-.]*'; | 133 | $wildcard = strlen($this->args['tinstance']) ? '.' : '[-.]*'; |
128 | 134 | ||