aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPim van den Berg2010-10-04 11:45:17 +0200
committerPim van den Berg2010-10-04 12:35:12 +0200
commit1ee60c5976e9cb049bc5e650e5c1b9205b15910f (patch)
treeb719f2dccc0d90a79be4421780b72b96f6633059
parentinc/collectd: simplify the way collectd_plugindata gathers its data (diff)
downloadapt-panopticon_cgp-1ee60c5976e9cb049bc5e650e5c1b9205b15910f.zip
apt-panopticon_cgp-1ee60c5976e9cb049bc5e650e5c1b9205b15910f.tar.gz
apt-panopticon_cgp-1ee60c5976e9cb049bc5e650e5c1b9205b15910f.tar.bz2
apt-panopticon_cgp-1ee60c5976e9cb049bc5e650e5c1b9205b15910f.tar.xz
inc/collectd: improve determining which files to group in 1 graph
Previously graphs were created by collecting and merging all PIs, Ts and TIs separately. This went wrong when a part of a plugin had a PI and another part had not (processes plugin). It also went wrong when a P-PI combination had different Ts and TIs (bind plugin). This is solved by using grouped and deduplicated plugindata. -- P = plugin, PI = plugin instance, T = type, TI = type instance
-rw-r--r--inc/collectd.inc.php77
1 files changed, 44 insertions, 33 deletions
diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php
index 7f88456..18f56c8 100644
--- a/inc/collectd.inc.php
+++ b/inc/collectd.inc.php
@@ -20,7 +20,7 @@ function collectd_hosts() {
20} 20}
21 21
22# returns an array of plugins/pinstances/types/tinstances 22# returns an array of plugins/pinstances/types/tinstances
23function collectd_plugindata($host) { 23function collectd_plugindata($host, $plugin=NULL) {
24 global $CONFIG; 24 global $CONFIG;
25 25
26 if (!is_dir($CONFIG['datadir'].'/'.$host)) 26 if (!is_dir($CONFIG['datadir'].'/'.$host))
@@ -43,6 +43,15 @@ function collectd_plugindata($host) {
43 ); 43 );
44 } 44 }
45 45
46 # only return data about one plugin
47 if (!is_null($plugin)) {
48 foreach($data as $item) {
49 if ($item['p'] == $plugin)
50 $pdata[] = $item;
51 }
52 $data = $pdata;
53 }
54
46 return($data); 55 return($data);
47} 56}
48 57
@@ -91,42 +100,44 @@ function collectd_plugindetail($host, $plugin, $detail, $where=NULL) {
91 return $return; 100 return $return;
92} 101}
93 102
103# group plugin files for graph generation
104function group_plugindata($plugindata) {
105 global $CONFIG;
106
107 # type instances should be grouped in 1 graph
108 foreach ($plugindata as $item) {
109 # backwards compatibility
110 if ($CONFIG['version'] >= 5 || !preg_match('/^(df|interface)$/', $item['p']))
111 unset($item['ti']);
112 $data[] = $item;
113 }
114
115 # remove duplicates
116 $data = array_map("unserialize", array_unique(array_map("serialize", $data)));
117
118 return $data;
119}
120
94# generate graph url's for a plugin of a host 121# generate graph url's for a plugin of a host
95function graphs_from_plugin($host, $plugin) { 122function graphs_from_plugin($host, $plugin) {
96 global $CONFIG; 123 global $CONFIG;
97 124
98 $pis = collectd_plugindetail($host, $plugin, 'pi'); 125 $plugindata = collectd_plugindata($host, $plugin);
99 $ts = collectd_plugindetail($host, $plugin, 't'); 126 $plugindata = group_plugindata($plugindata);
100 $tis = collectd_plugindetail($host, $plugin, 'ti'); 127
101 if (!$pis) $pis = array('NULL'); 128 foreach ($plugindata as $items) {
102 if (!$tis) $tis = array('NULL'); 129 $items['h'] = $host;
103 # backwards compatibility 130
104 if ($CONFIG['version'] >= 5 || !preg_match('/^(df|interface)$/', $plugin)) 131 $time = array_key_exists($plugin, $CONFIG['time_range'])
105 $tis = array('NULL'); 132 ? $CONFIG['time_range'][$plugin]
106 133 : $CONFIG['time_range']['default'];
107 foreach($pis as $pi) { 134
108 foreach ($tis as $ti) { 135 printf('<a href="%s/%s"><img src="%s/%s"></a>'."\n",
109 foreach ($ts as $t) { 136 $CONFIG['weburl'],
110 $items = array( 137 build_url('detail.php', $items, $time),
111 'h' => $host, 138 $CONFIG['weburl'],
112 'p' => $plugin, 139 build_url('graph.php', $items, $time)
113 'pi' => $pi, 140 );
114 't' => $t,
115 'ti' => $ti
116 );
117
118 $time = array_key_exists($plugin, $CONFIG['time_range'])
119 ? $CONFIG['time_range'][$plugin]
120 : $CONFIG['time_range']['default'];
121
122 printf('<a href="%s/%s"><img src="%s/%s"></a>'."\n",
123 $CONFIG['weburl'],
124 build_url('detail.php', $items, $time),
125 $CONFIG['weburl'],
126 build_url('graph.php', $items, $time)
127 );
128 }
129 }
130 } 141 }
131} 142}
132 143