-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-notification-log
More file actions
executable file
·108 lines (89 loc) · 2.92 KB
/
process-notification-log
File metadata and controls
executable file
·108 lines (89 loc) · 2.92 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
#!/usr/bin/perl -w
#
# [I 130502 07:15:39 tornado_notification_server_nginx:210] [147/148] Connected <Android:user967110ktestenvlocal1364469539>
# [W 130502 07:15:39 handler:229] < device_os:Android device_uuid:uQPxJVgKvUhXL76GRQlvEpQYnWL > 408 POST /notification/poll (127.0.0.1) 600001.96ms
# [I 130502 07:15:39 tornado_notification_server_nginx:231] [146/147] Disconnected <Android:uQPxJVgKvUhXL76GRQlvEpQYnWL>
#
# time, date, connected,disconnected,decrypt_fail,other,accu, 200,408
# 1367478900,Thu May 2 07:15:00 2013,1,1,0,0,-2,0,1
# 31367478905,Thu May 2 07:15:05 2013,0,0,0,0,0,0,0
# 1367478910,Thu May 2 07:15:10 2013,1,0,0,0,-1,0,0
use strict;
use Data::Dumper ;
use Time::Local qw{timegm};
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{ connected disconnected decrypt_fail other accu } ;
my %status_codes = ();
my $accu = 0 ;
while (<>) {
chomp ;
next unless /(Connected|Disconnected|Decrypt|handler:)/ ;
my $mode = $1 ;
# YMD HMS
my ($y,$m,$d,$h,$i,$s) = /(\d{2})(\d{2})(\d{2}) (\d{2}):(\d{2}):(\d{2})/ ;
$y += 2000;
$m -- ;
# ($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 ($mode eq 'Connected') {
$completed{$time}{connected} ++ ;
$accu ++ ;
} elsif ($mode eq 'Disconnected') {
$completed{$time}{disconnected} ++ ;
$accu -- ;
} elsif ($mode eq 'Decrypt') {
$completed{$time}{decrypt_fail} ++ ;
} elsif ($mode eq 'handler:') {
if (/(\d+) POST [\/\w]+ \([\d\.]+\) ([\d\.]+)ms\z/) {
$completed{$time}{$1} ++ ;
$status_codes{$1} ++ ;
} else {
$completed{$time}{other} ++ ;
}
} else {
$completed{$time}{other} ++ ;
}
$completed{$time}{accu} = $accu ;
$total_count ++
}
printf("# parsed total %d entries\n", $total_count);
printf("# time, date, %s, %s\n", join(',',@fields), join(',',sort keys %status_codes));
for (my $idx = $min_time ; $idx < $max_time + $snap; $idx = $idx + $snap) {
if (!exists($completed{$idx})) {
printf("%s,%s,%s,%s\n",
$idx, scalar gmtime($idx),
join(',', map { 0 } @fields),
join(',', map { 0 } keys %status_codes));
next;
}
my $rec = $completed{$idx} ;
my $counter = $completed{$idx}{'counter'};
printf("%d,%s", $idx, scalar gmtime($idx));
foreach my $field (@fields) {
my $val = $completed{$idx}{$field} || 0;
printf(",%d", $val);
}
foreach my $field (sort keys %status_codes) {
my $val = $completed{$idx}{$field} || 0;
printf(",%d", $val);
}
printf("\n");
}