tailstrom 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/dummylog +16 -0
- data/bin/tailstrom +6 -0
- data/lib/tailstrom/command/stat.rb +68 -0
- data/lib/tailstrom/counter.rb +40 -0
- data/lib/tailstrom/counter_collection.rb +21 -0
- data/lib/tailstrom/table.rb +73 -0
- data/lib/tailstrom/tail_reader.rb +10 -0
- data/lib/tailstrom/version.rb +3 -0
- data/lib/tailstrom.rb +5 -0
- data/tailstrom.gemspec +20 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b35a6296aafaca9109eb5fa60b6adaa0e2d98a2f
|
4
|
+
data.tar.gz: c4e00a60b880f28e030c88421e45795953beabb1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9de2b148f1eb4fa79783a3a3028c4c3e6f948166eb07f6fae1bdc0eae3e5f57ff978bc2e6803c85afc91a49a424852798e9db4c29f1af026d66a266fbddedf08
|
7
|
+
data.tar.gz: 6bcbfb29db916fbce4671daf296377a57fdf945f3b1e016c8afe3fba6c2f0740e44d5c4a3066b31cdaf7a89a748fd529bbc366b350968d9ec3503eeb16c58f2a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Issei Naruta
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Tailstrom
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tailstrom'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tailstrom
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/dummylog
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
begin
|
5
|
+
loop do
|
6
|
+
url = "/#{%w(users products photos).sample}/#{rand(1000)}"
|
7
|
+
time = Time.now.iso8601
|
8
|
+
rtime = rand(1_000_000)
|
9
|
+
status = [200, 302].sample
|
10
|
+
puts [status, time, rtime, url].join("\t")
|
11
|
+
$stdout.flush
|
12
|
+
sleep rand(10).to_f / 100.0
|
13
|
+
end
|
14
|
+
rescue Interrupt
|
15
|
+
exit 0
|
16
|
+
end
|
data/bin/tailstrom
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'tailstrom/counter_collection'
|
3
|
+
require 'tailstrom/table'
|
4
|
+
require 'thread'
|
5
|
+
|
6
|
+
module Tailstrom
|
7
|
+
module Command
|
8
|
+
class Stat
|
9
|
+
SCHEMA = [
|
10
|
+
{ :name => 'count', :width => 7 },
|
11
|
+
{ :name => 'min', :width => 15 },
|
12
|
+
{ :name => 'max', :width => 15 },
|
13
|
+
{ :name => 'avg', :width => 15 }
|
14
|
+
]
|
15
|
+
|
16
|
+
def initialize(argv)
|
17
|
+
@infile = $stdin
|
18
|
+
@counters = CounterCollection.new
|
19
|
+
@table = Table.new SCHEMA
|
20
|
+
parse_option argv
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
Thread.start {
|
25
|
+
loop do
|
26
|
+
while line = @infile.gets
|
27
|
+
line = line.chomp
|
28
|
+
parse_line line
|
29
|
+
end
|
30
|
+
sleep 0.1
|
31
|
+
end
|
32
|
+
}
|
33
|
+
|
34
|
+
@table.print_header
|
35
|
+
|
36
|
+
loop do
|
37
|
+
unless @counters.empty?
|
38
|
+
c = @counters[:all]
|
39
|
+
@table.print_row c.count, c.min, c.max, c.avg
|
40
|
+
end
|
41
|
+
@counters.clear
|
42
|
+
sleep @options[:interval]
|
43
|
+
end
|
44
|
+
rescue Interrupt
|
45
|
+
exit 0
|
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
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Tailstrom
|
2
|
+
class Counter
|
3
|
+
def initialize
|
4
|
+
clear
|
5
|
+
end
|
6
|
+
|
7
|
+
def <<(value)
|
8
|
+
@values << value
|
9
|
+
end
|
10
|
+
|
11
|
+
def clear
|
12
|
+
@values = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def avg
|
16
|
+
return nil if @values.empty?
|
17
|
+
sum / @values.length
|
18
|
+
end
|
19
|
+
|
20
|
+
def sum
|
21
|
+
@values.inject(0, :+)
|
22
|
+
end
|
23
|
+
|
24
|
+
def min
|
25
|
+
@values.min
|
26
|
+
end
|
27
|
+
|
28
|
+
def max
|
29
|
+
@values.max
|
30
|
+
end
|
31
|
+
|
32
|
+
def med
|
33
|
+
@values[@values.length / 2]
|
34
|
+
end
|
35
|
+
|
36
|
+
def count
|
37
|
+
@values.count
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'tailstrom/counter'
|
2
|
+
|
3
|
+
module Tailstrom
|
4
|
+
class CounterCollection
|
5
|
+
def initialize
|
6
|
+
@counters = Hash.new {|h, k| h[k] = Counter.new }
|
7
|
+
end
|
8
|
+
|
9
|
+
def clear
|
10
|
+
@counters.values.each(&:clear)
|
11
|
+
end
|
12
|
+
|
13
|
+
def [](key)
|
14
|
+
@counters[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def empty?
|
18
|
+
@counters.empty?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Tailstrom
|
2
|
+
class Table
|
3
|
+
def initialize(schema)
|
4
|
+
@schema = schema
|
5
|
+
@out = $stdout
|
6
|
+
end
|
7
|
+
|
8
|
+
def print_row(*cols)
|
9
|
+
cols.each_with_index do |col, i|
|
10
|
+
col_schema = @schema[i]
|
11
|
+
num_str = col ? num_with_delim(col) : '-'
|
12
|
+
print ' ' if i > 0
|
13
|
+
printf "%#{col_schema[:width]}s", num_str
|
14
|
+
end
|
15
|
+
@out.puts
|
16
|
+
end
|
17
|
+
|
18
|
+
def print_header
|
19
|
+
border = head = ''
|
20
|
+
@schema.each_with_index do |col, i|
|
21
|
+
if i > 0
|
22
|
+
border += '-'
|
23
|
+
head += ' '
|
24
|
+
#border += '+'
|
25
|
+
#head += '|'
|
26
|
+
end
|
27
|
+
border += '-' * col[:width]
|
28
|
+
head += "%#{col[:width]}s" % col[:name]
|
29
|
+
end
|
30
|
+
@out.puts border, head, border
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def num_with_delim(num)
|
35
|
+
head, tail = num.to_s.split('.')
|
36
|
+
head.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
|
37
|
+
if tail
|
38
|
+
"#{head}.#{tail[0..2]}"
|
39
|
+
else
|
40
|
+
head
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if $0 == __FILE__
|
47
|
+
nums = [
|
48
|
+
459938.0869565217,
|
49
|
+
588316.4761904762,
|
50
|
+
459265.652173913,
|
51
|
+
473729.63636363635,
|
52
|
+
625076.2857142857,
|
53
|
+
461625.76,
|
54
|
+
412747.04761904763,
|
55
|
+
367196.3,
|
56
|
+
0.125,
|
57
|
+
9.50,
|
58
|
+
10.1,
|
59
|
+
100,
|
60
|
+
100
|
61
|
+
]
|
62
|
+
|
63
|
+
schema = [
|
64
|
+
{ :name => 'min', :width => 15 },
|
65
|
+
{ :name => 'max', :width => 15 },
|
66
|
+
]
|
67
|
+
|
68
|
+
table = Tailstrom::Table.new schema
|
69
|
+
table.print_header
|
70
|
+
nums.each do |num|
|
71
|
+
table.print_row num, num
|
72
|
+
end
|
73
|
+
end
|
data/lib/tailstrom.rb
ADDED
data/tailstrom.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tailstrom/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tailstrom"
|
8
|
+
spec.version = Tailstrom::VERSION
|
9
|
+
spec.authors = ["Issei Naruta"]
|
10
|
+
spec.email = ["naruta@cookpad.com"]
|
11
|
+
spec.description = %q{tailstrom is a utility for "tail -f"}
|
12
|
+
spec.summary = %q{A utility for "tail -f"}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tailstrom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Issei Naruta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: tailstrom is a utility for "tail -f"
|
14
|
+
email:
|
15
|
+
- naruta@cookpad.com
|
16
|
+
executables:
|
17
|
+
- dummylog
|
18
|
+
- tailstrom
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/dummylog
|
28
|
+
- bin/tailstrom
|
29
|
+
- lib/tailstrom.rb
|
30
|
+
- lib/tailstrom/command/stat.rb
|
31
|
+
- lib/tailstrom/counter.rb
|
32
|
+
- lib/tailstrom/counter_collection.rb
|
33
|
+
- lib/tailstrom/table.rb
|
34
|
+
- lib/tailstrom/tail_reader.rb
|
35
|
+
- lib/tailstrom/version.rb
|
36
|
+
- tailstrom.gemspec
|
37
|
+
homepage: ''
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.0.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: A utility for "tail -f"
|
61
|
+
test_files: []
|