Module: TcpsnitchAnalyzer
- Defined in:
- lib/tcpsnitch_analyzer.rb,
lib/tcpsnitch_analyzer/opt_parser.rb,
lib/tcpsnitch_analyzer/proportion_stat.rb,
lib/tcpsnitch_analyzer/time_serie_stat.rb,
lib/tcpsnitch_analyzer/descriptive_stat.rb
Defined Under Namespace
Classes: DescriptiveStat, OptParser, ProportionStat, TimeSerieStat
Constant Summary
collapse
- EXECUTABLE =
'tcpsnitch_analyzer'
- VERSION =
'0.0.1'
Class Method Summary
collapse
Class Method Details
.error(msg) ⇒ Object
67
68
69
70
71
|
# File 'lib/tcpsnitch_analyzer.rb', line 67
def error(msg)
puts "#{EXECUTABLE}: #{msg}."
puts "Try '#{EXECUTABLE} -h' for more information."
exit 1
end
|
.filter(hash, filter) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/tcpsnitch_analyzer.rb', line 73
def filter(hash, filter)
if filter then
hash[:type] == filter ? hash : nil
else
hash
end
end
|
.keys_from_path(path) ⇒ Object
85
86
87
|
# File 'lib/tcpsnitch_analyzer.rb', line 85
def keys_from_path(path)
path.split('.').collect(&:to_sym)
end
|
.node_val(hash, path) ⇒ Object
89
90
91
|
# File 'lib/tcpsnitch_analyzer.rb', line 89
def node_val(hash, path)
val_for(hash, keys_from_path(path))
end
|
.process_files(options, files) ⇒ Object
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
|
# File 'lib/tcpsnitch_analyzer.rb', line 16
def process_files(options, files)
matched_data = false
files.each do |file|
File.open(file).each_with_index do |line, index|
next if index == 0 next if line.eql? "]"
begin
hash = Oj.load(line.chomp(",\n")) rescue Exception => e
error(e)
end
next unless filter(hash, options.event_filter)
matched_data = true
begin
val = node_val(hash, options.node_path)
rescue Exception => e
error("invalid -n argument: '#{options.node_path}'")
end
if options.analysis_type == TimeSerieStat
options.analysis_type.add_point(node_val(hash, 'timestamp'), val)
else
options.analysis_type.add_val(val)
end
end
end
(options)
if matched_data
options.analysis_type.print(options)
else
puts "No data point matching criterias."
end
end
|
93
94
95
96
97
98
|
# File 'lib/tcpsnitch_analyzer.rb', line 93
def (options)
puts "JSON node:".ljust(15) + "#{options.node_path}"
event_filter = options.event_filter ? options.event_filter : "/"
puts "Type filter:".ljust(15) + event_filter
puts ""
end
|
.val_for(hash, keys) ⇒ Object
81
82
83
|
# File 'lib/tcpsnitch_analyzer.rb', line 81
def val_for(hash, keys)
keys.reduce(hash) { |h, key| h[key] }
end
|