aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/collectd.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/collectd.inc.php')
-rw-r--r--inc/collectd.inc.php65
1 files changed, 0 insertions, 65 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?>