forked from Cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremovespikes.php
More file actions
executable file
·247 lines (210 loc) · 7.03 KB
/
removespikes.php
File metadata and controls
executable file
·247 lines (210 loc) · 7.03 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env php
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 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/ |
+-------------------------------------------------------------------------+
*/
$dir = dirname(__FILE__);
chdir($dir);
/* Start Initialization Section */
require(__DIR__ . '/../include/cli_check.php');
require_once($config['base_path'] . '/lib/spikekill.php');
if ($config['poller_id'] > 1) {
print "FATAL: This utility is designed for the main Data Collector only" . PHP_EOL;
exit(1);
}
/* allow more memory */
ini_set('memory_limit', '-1');
/* setup defaults */
$debug = false;
$dryrun = false;
$out_start = '';
$out_end = '';
$rrdfile = '';
$std_kills = false;
$var_kills = false;
$html = false;
$backup = false;
$out_set = false;
$user = get_current_user();
$method = read_config_option('spikekill_method', 1);
$numspike = read_config_option('spikekill_number', 10);
$stddev = read_config_option('spikekill_deviations', 10);
$percent = read_config_option('spikekill_percent', 500);
$outliers = read_config_option('spikekill_outliers', 5);
$avgnan = read_config_option('spikekill_avgnan', 'last');
switch($method) {
case '1':
$method = 'stddev';
break;
case '2':
$method = 'variance';
break;
case '3':
$method = 'float';
break;
case '4':
$method = 'fill';
break;
default:
$method = 'variance';
}
/* process calling arguments */
$parms = $_SERVER['argv'];
array_shift($parms);
if (cacti_sizeof($parms)) {
foreach($parms as $parameter) {
if (strpos($parameter, '=')) {
list($arg, $value) = explode('=', $parameter, 2);
} else {
$arg = $parameter;
$value = '';
}
switch ($arg) {
case '--user':
case '-U':
print "WARNING: The user --user and -U are deprecated\n";
break;
case '--method':
case '-M':
$method = $value;
break;
case '--avgnan':
case '-A':
$avgnan = strtolower($value);
break;
case '--rrdfile':
case '-R':
$rrdfile = $value;
break;
case '--stddev':
case '-S':
$stddev = $value;
break;
case '--outlier-start':
$out_start = $value;
break;
case '--outlier-end':
$out_end = $value;
break;
case '--outliers':
case '-O':
$outliers = $value;
break;
case '--percent':
case '-P':
$percent = $value;
break;
case '--html':
$html = true;
break;
case '--backup':
$backup = true;
break;
case '-d':
case '--debug':
$debug = true;
break;
case '-D':
case '--dryrun':
$dryrun = true;
break;
case '--number':
case '-n':
$numspike = $value;
break;
case '--version':
case '-V':
case '-v':
display_version();
exit(0);
case '--help':
case '-H':
case '-h':
display_help();
exit(0);
default:
print 'ERROR: Invalid Parameter ' . $parameter . "\n\n";
display_help();
exit(-3);
}
}
} else {
display_help();
exit(0);
}
$spiker = new spikekill($rrdfile, $method, $avgnan, $stddev, $out_start, $out_end, $outliers, $percent, $numspike);
if ($debug) {
$spiker->debug = true;
}
if ($html) {
$spiker->html = true;
} else {
$spiker->html = false;
}
if ($dryrun) {
$spiker->dryrun = true;
} else {
$spiker->dryrun = false;
}
$result = $spiker->remove_spikes();
if (!$result) {
print "ERROR: Remove Spikes experienced errors\n";
print $spiker->get_errors();
exit(-1);
} else {
print $spiker->get_output();
exit(0);
}
/* display_version - displays version information */
function display_version() {
$version = get_cacti_cli_version();
print "Cacti Spike Remover Utility, Version $version, " . COPYRIGHT_YEARS . "\n";
}
/* display_help - displays the usage of the function */
function display_help () {
display_version();
print "\nusage: removespikes.php -R|--rrdfile=rrdfile [-M|--method=stddev] [-A|--avgnan] [-S|--stddev=N]\n";
print " [-O|--outliers=N | --outlier-start=YYYY-MM-DD HH:MM --outlier-end=YYYY-MM-DD HH:MM]\n";
print " [-P|--percent=N] [-N|--number=N] [-D|--dryrun] [-d|--debug]\n";
print " [--html]\n\n";
print "A utility to programmatically remove spikes from Cacti graphs. If no optional input parameters\n";
print "are specified the defaults are taken from the Cacti database.\n\n";
print "Required:\n";
print " --rrdfile=F - The path to the RRDfile that will be de-spiked.\n\n";
print "Optional:\n";
print " --method - The spike removal method to use. Options are stddev|variance|fill|float\n";
print " --avgnan - The spike replacement method to use. Options are last|avg|nan\n";
print " --stddev - The number of standard deviations +/- allowed\n";
print " --percent - The sample to sample percentage variation allowed\n";
print " --number - The maximum number of spikes to remove from the RRDfile\n";
print " --outlier-start - A start date of an incident where all data should be considered\n";
print " invalid data and should be excluded from average calculations.\n";
print " --outlier-end - An end date of an incident where all data should be considered\n";
print " invalid data and should be excluded from average calculations.\n";
print " --outliers - The number of outliers to ignore when calculating average.\n";
print " --dryrun - If specified, the RRDfile will not be changed. Instead a summary of\n";
print " changes that would have been performed will be issued.\n";
print " --backup - Backup the original RRDfile to preserve prior values.\n\n";
print "The remainder of arguments are informational\n";
print " --html - Format the output for a web browser\n";
print " --debug - Display verbose output during execution\n";
}