tailstrom 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tailstrom +20 -3
- data/lib/tailstrom/command/print.rb +19 -0
- data/lib/tailstrom/command/stat.rb +18 -37
- data/lib/tailstrom/tail_reader.rb +21 -3
- data/lib/tailstrom/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ba940607a94b7a30111d0a1d5cfc64d4ffbe92
|
4
|
+
data.tar.gz: 55a929d508f09b314fd783a4ba3843b89b3c9c0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 046e9476d9ed1d61b3ac8127fced3cfcd571de4b30d900aab9474da256fae61043a3a014ffb6fe0b40f96800280a6c92414293229cb01894e338dd5f92c453f0
|
7
|
+
data.tar.gz: 3da54d4b6b9c5d9270b6d65ee810536d7d1e65264e3c6dd54f83e37cfe52eac258443f4dafdd52e41272ea7103a20c1a18fe2aae3a341a66b044a6f4293cd01e
|
data/bin/tailstrom
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
options = {
|
5
|
+
:delimiter => "\t",
|
6
|
+
:interval => 1,
|
7
|
+
:mode => :stat
|
8
|
+
}
|
9
|
+
OptionParser.new(ARGV) {|opt|
|
10
|
+
opt.banner = "tail -f access.log | #{$0} <OPTIONS>"
|
11
|
+
opt.on('-f [field]', Integer, 'value field') {|v| options[:field] = v - 1 }
|
12
|
+
opt.on('-d [delimiter]', String) {|v| options[:delimiter] = v }
|
13
|
+
opt.on('-i [interval]', Integer, 'interval for stat mode') {|v| options[:interval] = v }
|
14
|
+
opt.on('-e [filter]', String) {|v| options[:filter] = v }
|
15
|
+
opt.on('--stat', 'statistics mode (default)') { options[:mode] = :stat }
|
16
|
+
opt.on('--print', 'print line mode') { options[:mode] = :print }
|
17
|
+
}.parse!
|
3
18
|
|
4
|
-
|
5
|
-
|
19
|
+
$: << File.expand_path('../../lib', __FILE__)
|
20
|
+
require "tailstrom/command/#{options[:mode]}"
|
21
|
+
cls = Module.const_get "Tailstrom::Command::#{options[:mode].capitalize}"
|
22
|
+
cmd = cls.new options
|
6
23
|
cmd.run
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'tailstrom/tail_reader'
|
2
|
+
|
3
|
+
module Tailstrom
|
4
|
+
module Command
|
5
|
+
class Print
|
6
|
+
def initialize(options)
|
7
|
+
@infile = $stdin
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
reader = TailReader.new @infile, @options
|
13
|
+
reader.each_line do |line|
|
14
|
+
puts line[:line]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'tailstrom/counter_collection'
|
1
|
+
require 'tailstrom/counter'
|
3
2
|
require 'tailstrom/table'
|
4
|
-
require '
|
3
|
+
require 'tailstrom/tail_reader'
|
5
4
|
|
6
5
|
module Tailstrom
|
7
6
|
module Command
|
@@ -13,56 +12,38 @@ module Tailstrom
|
|
13
12
|
{ :name => 'avg', :width => 15 }
|
14
13
|
]
|
15
14
|
|
16
|
-
def initialize(
|
15
|
+
def initialize(options)
|
17
16
|
@infile = $stdin
|
18
|
-
@
|
17
|
+
@counter = Counter.new
|
19
18
|
@table = Table.new SCHEMA
|
20
|
-
|
19
|
+
@options = options
|
21
20
|
end
|
22
21
|
|
23
22
|
def run
|
24
|
-
Thread.start
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
parse_line line
|
29
|
-
end
|
30
|
-
sleep 0.1
|
23
|
+
Thread.start do
|
24
|
+
reader = TailReader.new @infile, @options
|
25
|
+
reader.each_line do |line|
|
26
|
+
@counter << line[:value]
|
31
27
|
end
|
32
|
-
|
28
|
+
end
|
33
29
|
|
34
30
|
@table.print_header
|
35
31
|
|
36
32
|
loop do
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
if @counter
|
34
|
+
@table.print_row(
|
35
|
+
@counter.count,
|
36
|
+
@counter.min,
|
37
|
+
@counter.max,
|
38
|
+
@counter.avg
|
39
|
+
)
|
40
40
|
end
|
41
|
-
@
|
41
|
+
@counter.clear
|
42
42
|
sleep @options[:interval]
|
43
43
|
end
|
44
44
|
rescue Interrupt
|
45
45
|
exit 0
|
46
46
|
end
|
47
|
-
|
48
|
-
def parse_line(line)
|
49
|
-
columns = line.split @options[:delimiter]
|
50
|
-
value = @options[:field] ? columns[@options[:field]] : line
|
51
|
-
value = value =~ /\./ ? value.to_f : value.to_i
|
52
|
-
@counters[:all] << value
|
53
|
-
end
|
54
|
-
|
55
|
-
def parse_option(argv)
|
56
|
-
@options = {
|
57
|
-
:delimiter => "\t",
|
58
|
-
:interval => 1
|
59
|
-
}
|
60
|
-
opt = OptionParser.new(argv)
|
61
|
-
opt.on('-f [field]', Integer) {|v| @options[:field] = v - 1 }
|
62
|
-
opt.on('-d [delimiter]', String) {|v| @options[:delimiter] = v }
|
63
|
-
opt.on('-i [interval]', Integer) {|v| @options[:interval] = v }
|
64
|
-
opt.parse!
|
65
|
-
end
|
66
47
|
end
|
67
48
|
end
|
68
49
|
end
|
@@ -1,10 +1,28 @@
|
|
1
1
|
module Tailstrom
|
2
2
|
class TailReader
|
3
|
-
def initialize(infile)
|
4
|
-
@
|
3
|
+
def initialize(infile, options={})
|
4
|
+
@infile = infile
|
5
|
+
@options = options
|
5
6
|
end
|
6
7
|
|
7
|
-
def
|
8
|
+
def each_line
|
9
|
+
@infile.each_line do |line|
|
10
|
+
result = parse_line(line)
|
11
|
+
yield result if result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_line(line)
|
16
|
+
columns = line.split @options[:delimiter]
|
17
|
+
value = @options[:field] ? columns[@options[:field]] : line
|
18
|
+
value = value =~ /\./ ? value.to_f : value.to_i
|
19
|
+
|
20
|
+
if @options[:filter]
|
21
|
+
v, cols = value, columns # shorthands
|
22
|
+
return nil unless binding.eval(@options[:filter])
|
23
|
+
end
|
24
|
+
|
25
|
+
{ :line => line, :columns => columns, :value => value }
|
8
26
|
end
|
9
27
|
end
|
10
28
|
end
|
data/lib/tailstrom/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tailstrom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Issei Naruta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: tailstrom is a utility for "tail -f"
|
14
14
|
email:
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- bin/dummylog
|
28
28
|
- bin/tailstrom
|
29
29
|
- lib/tailstrom.rb
|
30
|
+
- lib/tailstrom/command/print.rb
|
30
31
|
- lib/tailstrom/command/stat.rb
|
31
32
|
- lib/tailstrom/counter.rb
|
32
33
|
- lib/tailstrom/counter_collection.rb
|