-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-nginx-error
More file actions
executable file
·149 lines (128 loc) · 4.05 KB
/
process-nginx-error
File metadata and controls
executable file
·149 lines (128 loc) · 4.05 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
#!/usr/bin/perl -w
#
# 2013/04/19 09:55:35 [alert] 6253#0: 4096 worker_connections are not enough
# 2013/04/19 10:54:40 [error] 16433#0: *206031 recv() failed
#
use strict;
use Data::Dumper ;
use Time::Local qw{timegm};
use Text::CSV_XS;
my $snap = 5 ;
my $last = 0;
my $count = 0;
my $total_count = 0;
my $unfinished = 0 ;
my %completed ;
my $min_time = 0;
my $max_time = 0;
my $time = 0;
my %flags = ();
my $flag ;
my @fields = qw{ counter error other } ;
my %status_codes = ();
my %months = (
'Jan' => 0,
'Feb' => 1,
'Mar' => 2,
'Apr' => 3,
'May' => 4,
'Jun' => 5,
'Jul' => 6,
'Aug' => 7,
'Sep' => 8,
'Oct' => 9,
'Nov' => 10,
'Dec' => 11,
);
while (<>) {
chomp ;
next if /==> / ; # ==> /var/log/nginx/upstream-root.log <==
next if /^$/ ;
# YMD HMS
my ($y,$m,$d,$h,$i,$s) ;
if (/^(\d{4})\/(\d{2})\/(\d{2}) (\d{2}):(\d{2}):(\d{2})/) {
($y,$m,$d,$h,$i,$s) = ($1, $2, $3, $4, $5, $6) ;
} elsif (/(\d{2})\/(\w{3})\/(\d{4}):(\d{2}):(\d{2}):(\d{2})/) {
($y,$m,$d,$h,$i,$s) = ($3, $months{$2}, $1, $4, $5, $6) ;
} else {
printf("debug: unknown date: %s\n", $_);
next;
}
# ($sec,$min,$hour,$mday,$mon,$year)
$time = timegm($s,$i,$h,$d,$m,$y);
$time = int($time / $snap) * $snap;
if ($time > $max_time) {
$max_time = $time;
}
if ($min_time == 0) {
$min_time = $time;
}
$completed{$time}{counter} ++ ;
if (/\"(GET|POST|\-|HEAD|PUT) ([^\?]+)(\?.*)? HTTP\/\d\.\d\" (\d+)/) {
$completed{$time}{ $2 } ++ ;
$status_codes{ $2 } ++ ;
$completed{$time}{ $1 } ++ ;
$status_codes{ $1 } ++ ;
} elsif (/HEAD \/ HTTP\/1\.1\" 200 0 \"\-\" \"\-\"/) {
$completed{$time}{ HAPrxy } ++ ;
$status_codes{ HAPrxy} ++ ;
} elsif ( /\".*(?:\\x)[^\"]+" (\d+) \d+ "-" "-"/ ) {
# d\xFA\x94\x02\xB7^-\xFF/L\xBF\xD6\x0BI\xDC \xC5\xAC\xD6\x1C\xD9\
$completed{$time}{ $1 } ++ ;
$status_codes{ $1 } ++ ;
$completed{$time}{ ESSL } ++ ;
$status_codes{ ESSL } ++ ;
} elsif (/\"-\" (\d+)/) {
$completed{$time}{ $1 } ++ ;
$status_codes{ $1 } ++ ;
} elsif (/\[error\]/) {
$completed{$time}{ error } ++ ;
if (/refused/) {
$completed{$time}{ ERefused } ++ ;
$status_codes{ ERefused} ++ ;
} elsif (/timeout/) {
$completed{$time}{ ETimeOut } ++ ;
$status_codes{ EETimeOut } ++ ;
} elsif (/forbidden/) {
$completed{$time}{ EForbidden } ++ ;
$status_codes{ EForbidden } ++ ;
} elsif (/No such file or directory/) {
$completed{$time}{ ENoSuch } ++ ;
$status_codes{ ENoSuch } ++ ;
} elsif (/not found/) {
$completed{$time}{ ENotFound } ++ ;
$status_codes{ ENotFound } ++ ;
} elsif (/timed out/) {
$completed{$time}{ ETimeOut } ++ ;
$status_codes{ ETimeOut } ++ ;
} elsif (/prematurely closed/) {
$completed{$time}{ EPremClosed } ++ ;
$status_codes{ EPremClosed } ++ ;
} else {
printf("debug: other: %s\n", $_);
$completed{$time}{other} ++ ;
}
} else {
printf("debug: other: %s\n", $_);
$completed{$time}{other} ++ ;
}
$total_count ++
}
my $tab = Text::CSV_XS->new({ binary => 1, eol => "\n" });
$tab->print(\*STDOUT, ['time','date', @fields, sort keys %status_codes]);
for (my $idx = $min_time ; $idx < $max_time + $snap; $idx = $idx + $snap) {
if (!exists($completed{$idx})) {
$tab->print(\*STDOUT, [$idx, scalar gmtime($idx), map { 0 } @fields, map { 0 } keys %status_codes]);
next;
}
my $rec = $completed{$idx} ;
my $counter = $completed{$idx}{'counter'};
my @fresults = ($idx, scalar gmtime($idx));
foreach my $field (@fields) {
push @fresults, $completed{$idx}{$field} || 0;
}
foreach my $field (sort keys %status_codes) {
push @fresults, $completed{$idx}{$field} || 0;
}
$tab->print(\*STDOUT, \@fresults) ;
}