aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc
diff options
context:
space:
mode:
authorPim van den Berg2014-05-03 11:40:46 +0200
committerPim van den Berg2014-05-03 19:19:05 +0200
commit1bb10c398d1a3198a8b86517bd780b8122e2e69d (patch)
tree669ea50b9b0efe268f4bb9153459f95ccfb167b5 /inc
parenttype: move generic functions to base class (diff)
downloadapt-panopticon_cgp-1bb10c398d1a3198a8b86517bd780b8122e2e69d.zip
apt-panopticon_cgp-1bb10c398d1a3198a8b86517bd780b8122e2e69d.tar.gz
apt-panopticon_cgp-1bb10c398d1a3198a8b86517bd780b8122e2e69d.tar.bz2
apt-panopticon_cgp-1bb10c398d1a3198a8b86517bd780b8122e2e69d.tar.xz
move collectd_flush function to base class
Diffstat (limited to 'inc')
-rw-r--r--inc/collectd.inc.php65
-rw-r--r--inc/html.inc.php6
2 files changed, 5 insertions, 66 deletions
diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php
index 74595aa..3bfc6ff 100644
--- a/inc/collectd.inc.php
+++ b/inc/collectd.inc.php
@@ -167,68 +167,3 @@ function plugin_sort($data) {
167 167
168 return $data; 168 return $data;
169} 169}
170
171function socket_cmd($socket, $cmd) {
172 $r = fwrite($socket, $cmd, strlen($cmd));
173 if ($r === false || $r != strlen($cmd)) {
174 error_log(sprintf('ERROR: Failed to write full command to unix-socket: %d out of %d written',
175 $r === false ? -1 : $r, strlen($cmd)));
176 return FALSE;
177 }
178
179 $resp = fgets($socket,128);
180 if ($resp === false) {
181 error_log(sprintf('ERROR: Failed to read response from collectd for command: %s',
182 trim($cmd)));
183 return FALSE;
184 }
185
186 $n = (int)$resp;
187 while ($n-- > 0)
188 fgets($socket,128);
189
190 return TRUE;
191}
192
193# tell collectd to FLUSH all data of the identifier(s)
194function collectd_flush($identifier) {
195 global $CONFIG;
196
197 if (!$CONFIG['socket'])
198 return FALSE;
199
200 if (!$identifier || (is_array($identifier) && count($identifier) == 0) ||
201 !(is_string($identifier) || is_array($identifier)))
202 return FALSE;
203
204 if (!is_array($identifier))
205 $identifier = array($identifier);
206
207 $u_errno = 0;
208 $u_errmsg = '';
209 if (! $socket = @fsockopen($CONFIG['socket'], 0, $u_errno, $u_errmsg)) {
210 error_log(sprintf('ERROR: Failed to open unix-socket to %s (%d: %s)',
211 $CONFIG['socket'], $u_errno, $u_errmsg));
212 return FALSE;
213 }
214
215 if ($CONFIG['flush_type'] == 'collectd'){
216 $cmd = 'FLUSH';
217 foreach ($identifier as $val)
218 $cmd .= sprintf(' identifier="%s"', $val);
219 $cmd .= "\n";
220 socket_cmd($socket, $cmd);
221 }
222 elseif ($CONFIG['flush_type'] == 'rrdcached') {
223 foreach ($identifier as $val) {
224 $cmd = sprintf("FLUSH %s.rrd\n", $val);
225 socket_cmd($socket, $cmd);
226 }
227 }
228
229 fclose($socket);
230
231 return TRUE;
232}
233
234?>
diff --git a/inc/html.inc.php b/inc/html.inc.php
index 2bcbc3f..7f6e7c0 100644
--- a/inc/html.inc.php
+++ b/inc/html.inc.php
@@ -196,7 +196,11 @@ function host_summary($cat, $hosts) {
196 $CONFIG['weburl'],$host, $host); 196 $CONFIG['weburl'],$host, $host);
197 197
198 if ($CONFIG['showload']) { 198 if ($CONFIG['showload']) {
199 collectd_flush(sprintf('%s/load/load', $host)); 199 require_once 'type/Default.class.php';
200 $load = array('h' => $host, 'p' => 'load', 't' => 'load');
201 $obj = new Type_Default($CONFIG, $load);
202 $obj->collectd_flush();
203
200 $rrd_info = $rrd->rrd_info($CONFIG['datadir'].'/'.$host.'/load/load.rrd'); 204 $rrd_info = $rrd->rrd_info($CONFIG['datadir'].'/'.$host.'/load/load.rrd');
201 205
202 # ignore if file does not exist 206 # ignore if file does not exist