aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc
diff options
context:
space:
mode:
authorDao-hui Chen2014-06-11 11:43:26 +0800
committerDao-hui Chen2014-06-11 11:43:26 +0800
commitfe344d01d0b70fe30ba3930af83a87a2cbed8925 (patch)
tree5f443002f42aab08197a4d7fb94a1219e8f58718 /inc
parentplugin/tcpconns: fix missing port number in rrd title (diff)
downloadapt-panopticon_cgp-fe344d01d0b70fe30ba3930af83a87a2cbed8925.zip
apt-panopticon_cgp-fe344d01d0b70fe30ba3930af83a87a2cbed8925.tar.gz
apt-panopticon_cgp-fe344d01d0b70fe30ba3930af83a87a2cbed8925.tar.bz2
apt-panopticon_cgp-fe344d01d0b70fe30ba3930af83a87a2cbed8925.tar.xz
Add support for multiple types db
Diffstat (limited to 'inc')
-rw-r--r--inc/collectd.inc.php39
1 files changed, 23 insertions, 16 deletions
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;