diff options
Diffstat (limited to 'inc/collectd.inc.php')
-rw-r--r-- | inc/collectd.inc.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php index 3bfc6ff..695d79c 100644 --- a/inc/collectd.inc.php +++ b/inc/collectd.inc.php | |||
@@ -167,3 +167,27 @@ function plugin_sort($data) { | |||
167 | 167 | ||
168 | return $data; | 168 | return $data; |
169 | } | 169 | } |
170 | |||
171 | function parse_typesdb_file($file = '/usr/share/collectd/types.db') { | ||
172 | if (!file_exists($file)) | ||
173 | $file = 'inc/types.db'; | ||
174 | |||
175 | $types = array(); | ||
176 | foreach (file($file) as $type) { | ||
177 | if(!preg_match('/^(?P<dataset>[\w_]+)\s+(?P<datasources>.*)/', $type, $matches)) | ||
178 | continue; | ||
179 | $dataset = $matches['dataset']; | ||
180 | $datasources = explode(', ', $matches['datasources']); | ||
181 | |||
182 | foreach ($datasources as $ds) { | ||
183 | if (!preg_match('/^(?P<dsname>\w+):(?P<dstype>[\w]+):(?P<min>[\-\dU\.]+):(?P<max>[\dU\.]+)/', $ds, $matches)) | ||
184 | error_log(sprintf('CGP Error: DS "%s" from dataset "%s" did not match', $ds, $dataset)); | ||
185 | $types[$dataset][$matches['dsname']] = array( | ||
186 | 'dstype' => $matches['dstype'], | ||
187 | 'min' => $matches['min'], | ||
188 | 'max' => $matches['max'], | ||
189 | ); | ||
190 | } | ||
191 | } | ||
192 | return $types; | ||
193 | } | ||