-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyslogscan.rb
89 lines (81 loc) · 2.21 KB
/
syslogscan.rb
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
#!/usr/bin/ruby
require 'time'
class App
def initialize argv
@db = {}
end
def register tag, time, line
@db[tag] = {} unless @db[tag]
row = @db[tag]
row['count'] = row['count'].to_i + 1
if /elapsed ([.0-9]+)/ === line then
row['elapsed'] = row['elapsed'].to_f + Float($1)
end
if /012job \d+ at / === line then
row['batch'] = row['batch'].to_i + 1
end
if /rc=(\d+)/ === line then
rc = $1
rc = '0' if tag == 'feedstore' and rc == '3' or rc == '11'
unless rc == '0' then
row['err'] = '' unless row['err']
row['err'] += " #{rc},#{time.strftime('%H:%M')}"
end
end
if /"200"=>(\d+)/ === line then
row['dlfiles'] = row['dlfiles'].to_i + Integer($1)
end
if /"([45]\d\d)"=>\d+/ === line then
rc = $1
row['err'] = '' unless row['err']
row['err'] += " #{rc},#{time.strftime('%H:%M')}"
end
if /"(wait\w+)"=>\d+/ === line then
rc = $1
row['err'] = '' unless row['err']
row['err'] += " #{rc},#{time.strftime('%H:%M')}"
end
if /rescue=([:\w]+)/ === line then
rc = $1.sub(/[:\w]+::/, '')
row['err'] = '' unless row['err']
row['err'] += " #{rc},#{time.strftime('%H:%M')}"
end
if /(\S+) invoked oom-killer/ === line then
cause = $1
row['oom'] = '' unless row['oom']
row['oom'] += " #{cause},#{time.strftime('%H:%M')}"
end
end
def dump
@db.keys.sort.each {|tag|
row = ['tag:' + tag]
@db[tag].keys.sort.each {|item|
val = @db[tag][item]
case val
when String
val = val.gsub(/\s+/, '|')
when Float
val = '%-9.3f' % val
end
row.push "#{item}:#{val}"
}
puts row.join("\t")
}
end
def run argf
argf.set_encoding('ASCII-8BIT')
argf.each_line {|line|
unless /^(\w\w\w [ 123]\d \d\d:\d\d:\d\d)/ === line
next
end
time = Time.parse($1)
next unless /(oom-killer|run-prep|syndl|feedstore|wxmon|jmxscan|pshbspool|tarwriter|notifygah)/ === line
tag = $1
tag = $1 if /syndl\.(\w+)/ === line
tag = $1 if /"tag"=>"(\w+)"/ === line
register(tag, time, line)
}
dump
end
end
App.new(ARGV).run(ARGF)