forked from Cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poller_commands.php
105 lines (85 loc) · 4.06 KB
/
poller_commands.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2016 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
/* we are not talking to the browser */
$no_http_headers = true;
define('MAX_RECACHE_RUNTIME', 296);
/* do NOT run this script through a web browser */
if (!isset($_SERVER['argv'][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
die('<br><strong>This script is only meant to run at the command line.</strong>');
}
/* Start Initialization Section */
include(dirname(__FILE__) . '/include/global.php');
include_once($config['base_path'] . '/lib/poller.php');
include_once($config['base_path'] . '/lib/data_query.php');
include_once($config['base_path'] . '/lib/rrd.php');
/* Record Start Time */
$start = microtime(true);
$poller_commands = db_fetch_assoc('SELECT poller_command.action, poller_command.command FROM poller_command WHERE poller_command.poller_id = 0');
$last_host_id = 0;
$first_host = true;
$recached_hosts = 0;
if (sizeof($poller_commands) > 0) {
foreach ($poller_commands as $command) {
switch ($command['action']) {
case POLLER_COMMAND_REINDEX:
list($host_id, $data_query_id) = explode(':', $command['command']);
if ($last_host_id != $host_id) {
$last_host_id = $host_id;
$first_host = true;
$recached_hosts++;
} else {
$first_host = false;
}
if ($first_host) {
cacti_log("Device[$host_id] WARNING: Recache Event Detected for Device", true, 'PCOMMAND');
}
if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_DEBUG) {
cacti_log("Device[$host_id] RECACHE: Recache for Device, data query #$data_query_id", true, 'PCOMMAND');
}
run_data_query($host_id, $data_query_id);
if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_DEBUG) {
cacti_log("Device[$host_id] RECACHE: Recache successful.", true, 'PCOMMAND');
}
break;
default:
cacti_log('ERROR: Unknown poller command issued', true, 'PCOMMAND');
}
/* record current_time */
$current = microtime(true);
/* end if runtime has been exceeded */
if (($current-$start) > MAX_RECACHE_RUNTIME) {
cacti_log("ERROR: Poller Command processing timed out after processing '" . $command . "'",true,'PCOMMAND');
break;
}
}
db_execute('DELETE FROM poller_command WHERE poller_id = 0');
}
/* take time to log performance data */
$recache = microtime(true);
$recache_stats = sprintf('RecacheTime:%01.4f DevicesRecached:%s', round($recache - $start, 4), $recached_hosts);
if ($recached_hosts > 0) {
cacti_log('STATS: ' . $recache_stats, true, 'RECACHE');
}
/* insert poller stats into the settings table */
db_execute("REPLACE INTO settings (name, value) VALUES ('stats_recache', '$recache_stats')");