tailstrom 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tailstrom/command/stat.rb +1 -2
- data/lib/tailstrom/option_parser.rb +8 -4
- data/lib/tailstrom/tail_reader.rb +26 -9
- data/lib/tailstrom/version.rb +1 -1
- data/spec/stat_command_spec.rb +21 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 248be97938bac3cb884cbdb068a7faca0916061f
|
4
|
+
data.tar.gz: ac7e4f1466fcfd541ea9f4282161c335e7b96afb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68cd4c9e158940659a5869aa63eb72d9577cc95869dddfe4da682b6dcd3acbe5a6c106a1f91211604c79e678cd97c4634f971a5d6480a6aad29a67aa1db4345f
|
7
|
+
data.tar.gz: 656e5d97c582ef745811da3331626da29d44816586a87646104300d8c0f575bdf5018ca8342973c54337156089cf9fc4e2c0f2ba0504704545179d2ea4c6e19a
|
@@ -34,8 +34,7 @@ module Tailstrom
|
|
34
34
|
begin
|
35
35
|
sleep @options[:interval]
|
36
36
|
|
37
|
-
|
38
|
-
if printed_lines > 0 && (@counters.size > 1 || @counters.keys != [:nil] && !@counters.empty?)
|
37
|
+
if printed_lines > 0 && (@multiline ||= @counters.size > 1)
|
39
38
|
@table.puts
|
40
39
|
printed_lines += 1
|
41
40
|
end
|
@@ -33,11 +33,11 @@ tail -f access.log | #{$0} [OPTIONS]
|
|
33
33
|
opt.on('-c file', '--config file', String, 'config file') do |v|
|
34
34
|
@options_from_file = load_config v
|
35
35
|
end
|
36
|
-
opt.on('-f
|
37
|
-
@options[:
|
36
|
+
opt.on('-f num_or_string', '--value num_or_string', String, 'value field') do |v|
|
37
|
+
@options[:value] = num_or_string v
|
38
38
|
end
|
39
|
-
opt.on('-k
|
40
|
-
@options[:key] = v
|
39
|
+
opt.on('-k num_or_string', '--key num_or_string', String, 'key field') do |v|
|
40
|
+
@options[:key] = num_or_string v
|
41
41
|
end
|
42
42
|
opt.on('-d delimiter', String, 'delimiter') do |v|
|
43
43
|
@options[:delimiter] = v
|
@@ -79,6 +79,10 @@ tail -f access.log | #{$0} [OPTIONS]
|
|
79
79
|
File.exist?(value) ? File.read(value) : value
|
80
80
|
end
|
81
81
|
|
82
|
+
def num_or_string(value)
|
83
|
+
value =~ /^\d+$/ ? value.to_i : file_or_string(value)
|
84
|
+
end
|
85
|
+
|
82
86
|
def load_config(file)
|
83
87
|
require 'yaml'
|
84
88
|
argv = []
|
@@ -30,29 +30,46 @@ module Tailstrom
|
|
30
30
|
|
31
31
|
def parse_line(line)
|
32
32
|
col = line.split @options[:delimiter]
|
33
|
-
|
34
|
-
value = format_value value
|
35
|
-
key = @options[:key] ? col[@options[:key]] : :nil
|
33
|
+
key = value = nil
|
36
34
|
in_filter = @options[:in_filter]
|
37
35
|
|
38
|
-
|
36
|
+
_scripts = []
|
39
37
|
|
40
38
|
if @options[:map]
|
41
|
-
|
42
|
-
|
39
|
+
_scripts << @options[:map]
|
40
|
+
_scripts << 'value=format_value(value)'
|
41
|
+
end
|
42
|
+
|
43
|
+
if @options[:key]
|
44
|
+
_scripts << index_or_eval('key', 'col', @options[:key])
|
45
|
+
end
|
46
|
+
|
47
|
+
if @options[:value]
|
48
|
+
_scripts << index_or_eval('value', 'col', @options[:value])
|
49
|
+
_scripts << 'value=format_value(value)'
|
43
50
|
end
|
44
51
|
|
45
52
|
if in_filter
|
46
|
-
|
47
|
-
return nil unless eval
|
53
|
+
_scripts << in_filter
|
54
|
+
return nil unless eval _scripts.join(';')
|
48
55
|
end
|
49
56
|
|
50
|
-
eval
|
57
|
+
eval _scripts.join(';')
|
51
58
|
{ :line => line, :columns => col, :key => key, :value => value }
|
52
59
|
end
|
53
60
|
|
54
61
|
def format_value(value)
|
55
62
|
value =~ /\./ ? value.to_f : value.to_i
|
56
63
|
end
|
64
|
+
|
65
|
+
def index_or_eval(var, col, idx)
|
66
|
+
case idx
|
67
|
+
when Integer
|
68
|
+
"#{var}=col[#{idx}]"
|
69
|
+
when String
|
70
|
+
"#{var}=#{idx}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
private :index_or_eval
|
57
74
|
end
|
58
75
|
end
|
data/lib/tailstrom/version.rb
CHANGED
data/spec/stat_command_spec.rb
CHANGED
@@ -20,7 +20,7 @@ END
|
|
20
20
|
139 1,521 958,131 476,502 200
|
21
21
|
END
|
22
22
|
|
23
|
-
it { expect(run '-f2
|
23
|
+
it { expect(run '-f2 --map key=col[3][/[a-z]+/]').to eq <<-END }
|
24
24
|
---------------------------------------------------
|
25
25
|
count min max avg key
|
26
26
|
---------------------------------------------------
|
@@ -29,14 +29,21 @@ END
|
|
29
29
|
103 1,521 989,278 414,438 photos
|
30
30
|
END
|
31
31
|
|
32
|
-
it { expect(run
|
32
|
+
it { expect(run %!-f2 --key col[3][/[a-z]+/] -e 'key=="products"'!).to eq <<-END }
|
33
33
|
---------------------------------------------------
|
34
34
|
count min max avg key
|
35
35
|
---------------------------------------------------
|
36
36
|
104 2,524 995,595 505,832 products
|
37
37
|
END
|
38
38
|
|
39
|
-
it { expect(run '-f2
|
39
|
+
it { expect(run '-f2 --map key=col[3][/[a-z]+/] --in-filter key=~/products/').to eq <<-END }
|
40
|
+
---------------------------------------------------
|
41
|
+
count min max avg key
|
42
|
+
---------------------------------------------------
|
43
|
+
104 2,524 995,595 505,832 products
|
44
|
+
END
|
45
|
+
|
46
|
+
it { expect(run '-f2 --map key=col[3][/[a-z]+/] --sort count').to eq <<-END }
|
40
47
|
---------------------------------------------------
|
41
48
|
count min max avg key
|
42
49
|
---------------------------------------------------
|
@@ -45,7 +52,7 @@ END
|
|
45
52
|
93 5,584 971,226 485,544 users
|
46
53
|
END
|
47
54
|
|
48
|
-
it { expect(run '-f2
|
55
|
+
it { expect(run '-f2 --map key=col[3][/[a-z]+/] --sort count --order asc').to eq <<-END }
|
49
56
|
---------------------------------------------------
|
50
57
|
count min max avg key
|
51
58
|
---------------------------------------------------
|
@@ -54,12 +61,21 @@ END
|
|
54
61
|
104 2,524 995,595 505,832 products
|
55
62
|
END
|
56
63
|
|
57
|
-
it { expect(run '-f2
|
64
|
+
it { expect(run '-f2 --map key=col[3][/[a-z]+/] --out-filter "min>2000"').to eq <<-END }
|
65
|
+
---------------------------------------------------
|
66
|
+
count min max avg key
|
67
|
+
---------------------------------------------------
|
68
|
+
104 2,524 995,595 505,832 products
|
69
|
+
93 5,584 971,226 485,544 users
|
70
|
+
END
|
71
|
+
|
72
|
+
it { expect(run '-f2 --map key1=col[3][/[a-z]+/] --key key1').to eq <<-END }
|
58
73
|
---------------------------------------------------
|
59
74
|
count min max avg key
|
60
75
|
---------------------------------------------------
|
61
76
|
104 2,524 995,595 505,832 products
|
62
77
|
93 5,584 971,226 485,544 users
|
78
|
+
103 1,521 989,278 414,438 photos
|
63
79
|
END
|
64
80
|
|
65
81
|
end
|