Skip to content

Commit

Permalink
add support for varnish plugin categories
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pommi committed Sep 7, 2012
1 parent b5f789c commit e3f1cc2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
1 change: 1 addition & 0 deletions detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$host = validate_get(GET('h'), 'host');
$plugin = validate_get(GET('p'), 'plugin');
$pinstance = validate_get(GET('pi'), 'pinstance');
$category = validate_get(GET('c'), 'category');
$type = validate_get(GET('t'), 'type');
$tinstance = validate_get(GET('ti'), 'tinstance');
$width = GET('x');
Expand Down
38 changes: 17 additions & 21 deletions inc/collectd.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<p>[\w_]+) # plugin
(?:(?<=varnish)(?:\-(?P<c>[\w]+)))? # category
(?:\-(?P<pi>.+))? # plugin instance
/
(?P<t>[\w_]+) # type
(?:\-(?P<ti>.+))? # 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'] : '',
);
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions inc/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function validate_get($value, $type) {
return NULL;
break;
case 'plugin':
case 'category':
case 'type':
if (!preg_match('/^\w+$/u', $value))
return NULL;
Expand Down
17 changes: 3 additions & 14 deletions plugin/varnish.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,8 @@
$obj->width = $width;
$obj->heigth = $heigth;
$obj->rrd_format = '%5.1lf%s';
switch($obj->args['pinstance']) {
case 'default-backend':
$obj->rrd_title = 'backend';
$obj->rrd_vertical = 'hits';
break;
case 'default-cache':
$obj->rrd_title = 'cache';
$obj->rrd_vertical = 'hits';
break;
case 'default-connections':
$obj->rrd_title = 'connections';
$obj->rrd_vertical = 'hits';
break;
}
$obj->rrd_title = sprintf('%s (%s)', ucfirst($obj->args['pinstance']), $obj->args['category']);
$obj->rrd_vertical = 'hits';

collectd_flush($obj->identifiers);
$obj->rrd_graph();
12 changes: 9 additions & 3 deletions type/Default.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function parse_get() {
'host' => GET('h'),
'plugin' => GET('p'),
'pinstance' => GET('pi'),
'category' => GET('c'),
'type' => GET('t'),
'tinstance' => GET('ti'),
);
Expand Down Expand Up @@ -120,9 +121,14 @@ function rrd_files() {
}

function get_filenames() {
$identifier = sprintf('%s/%s%s%s/%s%s%s', $this->args['host'],
$this->args['plugin'], strlen($this->args['pinstance']) ? '-' : '', $this->args['pinstance'],
$this->args['type'], strlen($this->args['tinstance']) ? '-' : '', $this->args['tinstance']);
$identifier = sprintf('%s/%s%s%s%s%s/%s%s%s',
$this->args['host'],
$this->args['plugin'],
strlen($this->args['category']) ? '-' : '', $this->args['category'],
strlen($this->args['pinstance']) ? '-' : '', $this->args['pinstance'],
$this->args['type'],
strlen($this->args['tinstance']) ? '-' : '', $this->args['tinstance']
);

$wildcard = strlen($this->args['tinstance']) ? '.' : '[-.]*';

Expand Down

0 comments on commit e3f1cc2

Please sign in to comment.