aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPim van den Berg2014-06-24 12:49:26 +0200
committerPim van den Berg2014-06-24 12:49:26 +0200
commit30692ffbbd64ebac48d7d77ec39ae226779e547a (patch)
treeabee5d81cd7c2fe61e5288b4dac14586d46918c2
parentMerge remote-tracking branch 'feandil/for_upstream_lvm' (diff)
parentAdd support for multiple types db (diff)
downloadapt-panopticon_cgp-30692ffbbd64ebac48d7d77ec39ae226779e547a.zip
apt-panopticon_cgp-30692ffbbd64ebac48d7d77ec39ae226779e547a.tar.gz
apt-panopticon_cgp-30692ffbbd64ebac48d7d77ec39ae226779e547a.tar.bz2
apt-panopticon_cgp-30692ffbbd64ebac48d7d77ec39ae226779e547a.tar.xz
Merge remote-tracking branch 'dhchen/master'
-rw-r--r--conf/config.php2
-rw-r--r--inc/collectd.inc.php39
2 files changed, 24 insertions, 17 deletions
diff --git a/conf/config.php b/conf/config.php
index 3d54e26..e40cc9f 100644
--- a/conf/config.php
+++ b/conf/config.php
@@ -7,7 +7,7 @@ $CONFIG['version'] = 5;
7$CONFIG['datadir'] = '/var/lib/collectd/rrd'; 7$CONFIG['datadir'] = '/var/lib/collectd/rrd';
8 8
9# location of the types.db file 9# location of the types.db file
10$CONFIG['typesdb'] = '/usr/share/collectd/types.db'; 10$CONFIG['typesdb'][] = '/usr/share/collectd/types.db';
11 11
12# rrdtool executable 12# rrdtool executable
13$CONFIG['rrdtool'] = '/usr/bin/rrdtool'; 13$CONFIG['rrdtool'] = '/usr/bin/rrdtool';
diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php
index 695d79c..bbed611 100644
--- a/inc/collectd.inc.php
+++ b/inc/collectd.inc.php
@@ -168,25 +168,32 @@ function plugin_sort($data) {
168 return $data; 168 return $data;
169} 169}
170 170
171function parse_typesdb_file($file = '/usr/share/collectd/types.db') { 171function parse_typesdb_file($file = array('/usr/share/collectd/types.db')) {
172 if (!file_exists($file)) 172 if (!is_array($file))
173 $file = 'inc/types.db'; 173 $file = array($file);
174 if (!file_exists($file[0]))
175 $file[0] = 'inc/types.db';
174 176
175 $types = array(); 177 $types = array();
176 foreach (file($file) as $type) { 178 foreach ($file as $single_file)
177 if(!preg_match('/^(?P<dataset>[\w_]+)\s+(?P<datasources>.*)/', $type, $matches)) 179 {
180 if (!file_exists($single_file))
178 continue; 181 continue;
179 $dataset = $matches['dataset']; 182 foreach (file($single_file) as $type) {
180 $datasources = explode(', ', $matches['datasources']); 183 if(!preg_match('/^(?P<dataset>[\w_]+)\s+(?P<datasources>.*)/', $type, $matches))
181 184 continue;
182 foreach ($datasources as $ds) { 185 $dataset = $matches['dataset'];
183 if (!preg_match('/^(?P<dsname>\w+):(?P<dstype>[\w]+):(?P<min>[\-\dU\.]+):(?P<max>[\dU\.]+)/', $ds, $matches)) 186 $datasources = explode(', ', $matches['datasources']);
184 error_log(sprintf('CGP Error: DS "%s" from dataset "%s" did not match', $ds, $dataset)); 187
185 $types[$dataset][$matches['dsname']] = array( 188 foreach ($datasources as $ds) {
186 'dstype' => $matches['dstype'], 189 if (!preg_match('/^(?P<dsname>\w+):(?P<dstype>[\w]+):(?P<min>[\-\dU\.]+):(?P<max>[\dU\.]+)/', $ds, $matches))
187 'min' => $matches['min'], 190 error_log(sprintf('CGP Error: DS "%s" from dataset "%s" did not match', $ds, $dataset));
188 'max' => $matches['max'], 191 $types[$dataset][$matches['dsname']] = array(
189 ); 192 'dstype' => $matches['dstype'],
193 'min' => $matches['min'],
194 'max' => $matches['max'],
195 );
196 }
190 } 197 }
191 } 198 }
192 return $types; 199 return $types;