aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/collectd.inc.php
diff options
context:
space:
mode:
authorPim van den Berg2010-09-19 13:17:31 +0200
committerPim van den Berg2010-09-19 13:24:19 +0200
commita1fc70ead8f15fa79da7f4b67b08cfadb17040d0 (patch)
treef036ab7445305da6d89a65644ced1954e2049b7f /inc/collectd.inc.php
parentautomatic alignment of graph legend (diff)
downloadapt-panopticon_cgp-a1fc70ead8f15fa79da7f4b67b08cfadb17040d0.zip
apt-panopticon_cgp-a1fc70ead8f15fa79da7f4b67b08cfadb17040d0.tar.gz
apt-panopticon_cgp-a1fc70ead8f15fa79da7f4b67b08cfadb17040d0.tar.bz2
apt-panopticon_cgp-a1fc70ead8f15fa79da7f4b67b08cfadb17040d0.tar.xz
inc/collectd: simplify the way collectd_plugindata gathers its data
A couple of preg_replaces are replaced by one simple but effective preg_match.
Diffstat (limited to 'inc/collectd.inc.php')
-rw-r--r--inc/collectd.inc.php33
1 files changed, 10 insertions, 23 deletions
diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php
index f5769c0..7f88456 100644
--- a/inc/collectd.inc.php
+++ b/inc/collectd.inc.php
@@ -31,31 +31,18 @@ function collectd_plugindata($host) {
31 if (!$files) 31 if (!$files)
32 return false; 32 return false;
33 33
34 $data; 34 $data = array();
35 $i = 0;
36 foreach($files as $item) { 35 foreach($files as $item) {
37 unset($part); 36 preg_match('#([\w_]+)(?:\-(.+))?/([\w_]+)(?:\-(.+))?\.rrd#', $item, $matches);
38 37
39 # split item by plugin/type 38 $data[] = array(
40 $part = explode('/', $item); 39 'p' => $matches[1],
41 $part[1] = preg_replace('/\.rrd/', '', $part[1]); 40 'pi' => isset($matches[2]) ? $matches[2] : '',
42 41 't' => $matches[3],
43 # plugin 42 'ti' => isset($matches[4]) ? $matches[4] : '',
44 $data[$i]['p'] = preg_replace('/-.+/', '', $part[0]); 43 );
45
46 # plugin instance
47 if(preg_match('/-/', $part[0]))
48 $data[$i]['pi'] = preg_replace('/^[a-z_]+\-/', '', $part[0]);
49
50 # type
51 $data[$i]['t'] = preg_replace('/-.+/', '', $part[1]);
52
53 # type instance
54 if(preg_match('/-/', $part[1]))
55 $data[$i]['ti'] = preg_replace('/^[a-z_]+\-/', '', $part[1]);
56
57 $i++;
58 } 44 }
45
59 return($data); 46 return($data);
60} 47}
61 48