From 1bb10c398d1a3198a8b86517bd780b8122e2e69d Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Sat, 3 May 2014 11:40:46 +0200 Subject: move collectd_flush function to base class --- inc/collectd.inc.php | 65 ---------------------------------------------------- inc/html.inc.php | 6 ++++- 2 files changed, 5 insertions(+), 66 deletions(-) (limited to 'inc') 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) { return $data; } - -function socket_cmd($socket, $cmd) { - $r = fwrite($socket, $cmd, strlen($cmd)); - if ($r === false || $r != strlen($cmd)) { - error_log(sprintf('ERROR: Failed to write full command to unix-socket: %d out of %d written', - $r === false ? -1 : $r, strlen($cmd))); - return FALSE; - } - - $resp = fgets($socket,128); - if ($resp === false) { - error_log(sprintf('ERROR: Failed to read response from collectd for command: %s', - trim($cmd))); - return FALSE; - } - - $n = (int)$resp; - while ($n-- > 0) - fgets($socket,128); - - return TRUE; -} - -# tell collectd to FLUSH all data of the identifier(s) -function collectd_flush($identifier) { - global $CONFIG; - - if (!$CONFIG['socket']) - return FALSE; - - if (!$identifier || (is_array($identifier) && count($identifier) == 0) || - !(is_string($identifier) || is_array($identifier))) - return FALSE; - - if (!is_array($identifier)) - $identifier = array($identifier); - - $u_errno = 0; - $u_errmsg = ''; - if (! $socket = @fsockopen($CONFIG['socket'], 0, $u_errno, $u_errmsg)) { - error_log(sprintf('ERROR: Failed to open unix-socket to %s (%d: %s)', - $CONFIG['socket'], $u_errno, $u_errmsg)); - return FALSE; - } - - if ($CONFIG['flush_type'] == 'collectd'){ - $cmd = 'FLUSH'; - foreach ($identifier as $val) - $cmd .= sprintf(' identifier="%s"', $val); - $cmd .= "\n"; - socket_cmd($socket, $cmd); - } - elseif ($CONFIG['flush_type'] == 'rrdcached') { - foreach ($identifier as $val) { - $cmd = sprintf("FLUSH %s.rrd\n", $val); - socket_cmd($socket, $cmd); - } - } - - fclose($socket); - - return TRUE; -} - -?> 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) { $CONFIG['weburl'],$host, $host); if ($CONFIG['showload']) { - collectd_flush(sprintf('%s/load/load', $host)); + require_once 'type/Default.class.php'; + $load = array('h' => $host, 'p' => 'load', 't' => 'load'); + $obj = new Type_Default($CONFIG, $load); + $obj->collectd_flush(); + $rrd_info = $rrd->rrd_info($CONFIG['datadir'].'/'.$host.'/load/load.rrd'); # ignore if file does not exist -- cgit v1.1