diff options
Diffstat (limited to 'inc/collectd.inc.php')
-rw-r--r-- | inc/collectd.inc.php | 38 |
1 files changed, 17 insertions, 21 deletions
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; |