-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhttp_status_
executable file
·61 lines (49 loc) · 1.41 KB
/
http_status_
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
#!/usr/bin/perl -w
#%# family=auto
#%# capabilities=autoconf suggest
use strict;
(my $log_name = $0) =~ s/^.*\/?http_status_//;
my @codes = split (/,/, $ENV{check_http_codes}) if ($ENV{check_http_codes});
my $arg = shift() || "";
if ($arg eq 'config') {
print<<EOC;
graph_title http status
graph_vlabel items
graph_category nginx
EOC
print "$_.label $_\n" for (@codes);
exit 0;
}
if ($arg eq 'autoconf') {
my $reason;
$reason .= 'No /var/log/nginx dir ' unless (-d '/var/log/nginx');
$reason .= 'No /etc/nginx dir ' unless (-d '/etc/nginx');
$reason .= 'No logtail2 instaled' unless (-x '/usr/sbin/logtail2');
if ($reason) {
print "No ($reason)\n";
} else {
print "yes\n";
}
exit 0;
}
if ($arg eq 'suggest') {
opendir(DIR, '/var/log/nginx');
my @targets = grep { /access.log$/ } readdir(DIR);
print join("\n", @targets);
exit 0;
}
my $offset_path = '/var/lib/munin/plugin-state/';
my $log_path = '/var/log/nginx/';
my $log_file = $log_path.$log_name;
my $offset_file = $offset_path.$log_name.'.offset';
my @logtail_lines;
if (-e $offset_file){
@logtail_lines = `/usr/sbin/logtail2 -f $log_file -o $offset_file`;
} else {
system('/usr/sbin/logtail2 -f '.$log_file.' -o '.$offset_file.' > /dev/null');
}
for my $code (@codes){
my $total = grep { /\sHTTP\/1\..\"\s$code\s/ } @logtail_lines;
print $code.'.value '. $total / 300;
print "\n";
}