ix-cli 0.0.16 → 0.0.18
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 +4 -4
- data/bin/ix-bcat +11 -1
- data/bin/ix-center +28 -0
- data/bin/ix-cloudfront-to-json +31 -0
- data/bin/ix-cycle +54 -0
- data/bin/ix-df-to-json +33 -0
- data/bin/ix-df2 +40 -0
- data/bin/ix-domain-dns +43 -0
- data/bin/ix-elb-to-json +217 -0
- data/bin/ix-hls +13 -5
- data/bin/ix-json-filter +41 -0
- data/bin/ix-json-join +76 -0
- data/bin/ix-json-key-on-steroids +3 -0
- data/bin/ix-json-swap +8 -0
- data/bin/ix-json-to-yaml +6 -0
- data/bin/ix-ljust +5 -0
- data/bin/ix-matrioshka +76 -0
- data/bin/ix-mysqldump-to-json +120 -0
- data/bin/ix-noansi +9 -0
- data/bin/ix-pad +36 -0
- data/bin/ix-percentage +105 -21
- data/bin/ix-query-string-to-json +10 -0
- data/bin/ix-remove +46 -0
- data/bin/ix-rjust +5 -0
- data/bin/ix-rulers +79 -0
- data/bin/ix-s3-log-to-json +38 -0
- data/bin/ix-time-distance +47 -0
- data/bin/ix-timestamp2 +4 -6
- data/bin/ix-yaml-to-json +7 -0
- metadata +58 -12
- data/bin/ix-json-to-xml +0 -1
data/bin/ix-matrioshka
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
|
|
5
|
+
options = {}
|
|
6
|
+
options[:style] = :round
|
|
7
|
+
|
|
8
|
+
OptionParser.new do |opts|
|
|
9
|
+
|
|
10
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
|
11
|
+
|
|
12
|
+
opts.on('-s', '--style [STRING]', 'One of [round, square, mysql, double].') do |value|
|
|
13
|
+
options[:style] = value.to_sym
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end.parse!
|
|
17
|
+
|
|
18
|
+
required_options = [:style]
|
|
19
|
+
required_options.each do |option|
|
|
20
|
+
unless options[option]
|
|
21
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
|
22
|
+
exit 1
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def box(string, style = :round)
|
|
27
|
+
styles = {
|
|
28
|
+
round: {
|
|
29
|
+
top: '╭╮',
|
|
30
|
+
bottom: '╰╯',
|
|
31
|
+
side: '│',
|
|
32
|
+
horizontal: '─'
|
|
33
|
+
},
|
|
34
|
+
square: {
|
|
35
|
+
top: '┌┐',
|
|
36
|
+
bottom: '└┘',
|
|
37
|
+
side: '│',
|
|
38
|
+
horizontal: '─'
|
|
39
|
+
},
|
|
40
|
+
double: {
|
|
41
|
+
top: '╔╗',
|
|
42
|
+
bottom: '╚╝',
|
|
43
|
+
side: '║',
|
|
44
|
+
horizontal: '═'
|
|
45
|
+
},
|
|
46
|
+
mysql: {
|
|
47
|
+
top: '++',
|
|
48
|
+
bottom: '++',
|
|
49
|
+
side: '|',
|
|
50
|
+
horizontal: '-'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if styles[style].nil?
|
|
54
|
+
$stderr.puts "Unknown style #{style}"
|
|
55
|
+
exit 1
|
|
56
|
+
end
|
|
57
|
+
s = styles[style]
|
|
58
|
+
lines = []
|
|
59
|
+
string.each_line do |line|
|
|
60
|
+
lines.push(line.chomp)
|
|
61
|
+
end
|
|
62
|
+
result = ''
|
|
63
|
+
max = lines.map { |line| line.size }.sort.last
|
|
64
|
+
line = (s[:horizontal] * (max + 2))
|
|
65
|
+
result << "#{s[:top][0]}#{line}#{s[:top][1]}\n"
|
|
66
|
+
lines.each do |line|
|
|
67
|
+
line = line.ljust(max)
|
|
68
|
+
padding_left = ' ' * ((max - line.size) / 2)
|
|
69
|
+
padding_right = ' ' * (max - line.size - padding_left.size)
|
|
70
|
+
result << "#{s[:side]} #{padding_left}#{line}#{padding_right} #{s[:side]}\n"
|
|
71
|
+
end
|
|
72
|
+
result << "#{s[:bottom][0]}#{line}#{s[:bottom][1]}\n"
|
|
73
|
+
result
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
puts box(STDIN.read, options[:style])
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# ai did not cut it, I had to write this myself..
|
|
4
|
+
# cat file.sql | ruby parse.rb
|
|
5
|
+
|
|
6
|
+
require 'json'
|
|
7
|
+
|
|
8
|
+
class Buffer
|
|
9
|
+
def initialize
|
|
10
|
+
@buffer = []
|
|
11
|
+
end
|
|
12
|
+
def add(line)
|
|
13
|
+
@buffer << line
|
|
14
|
+
end
|
|
15
|
+
def flush
|
|
16
|
+
@buffer.join("\n")
|
|
17
|
+
end
|
|
18
|
+
def reset
|
|
19
|
+
@buffer = []
|
|
20
|
+
end
|
|
21
|
+
def to_s
|
|
22
|
+
flush
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class Database
|
|
27
|
+
attr_accessor :name
|
|
28
|
+
attr_accessor :tables
|
|
29
|
+
def initialize(name)
|
|
30
|
+
@name = name
|
|
31
|
+
@tables = []
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class Table
|
|
36
|
+
attr_accessor :name
|
|
37
|
+
attr_accessor :columns
|
|
38
|
+
def initialize(name)
|
|
39
|
+
@name = name
|
|
40
|
+
@columns = []
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class Column
|
|
45
|
+
attr_accessor :name
|
|
46
|
+
attr_accessor :type
|
|
47
|
+
def initialize(name, type)
|
|
48
|
+
@name = name
|
|
49
|
+
@type = type
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
# -- Host: localhost Database: empowerkit_DBnew
|
|
53
|
+
REGEX_DATABASE_1 = /(^USE `)([^`]+)(`;)|(-- Host: [^\s]+Database: )(\w+)(\n)/
|
|
54
|
+
REGEX_DATABASE_2 = /(-- Host: [^\s]+\s+Database: )(\w+)($)/
|
|
55
|
+
REGEX_TABLE_START = /(^CREATE TABLE `)([^`]+)(` \()/
|
|
56
|
+
REGEX_TABLE_END = /(^\)( ENGINE.)(\w+))/
|
|
57
|
+
REGEX_COLUMN = /(^ `)([^`]+)(` )(\w+)([^\n]+)/
|
|
58
|
+
|
|
59
|
+
database = nil
|
|
60
|
+
parsing_table = false
|
|
61
|
+
buffer = Buffer.new
|
|
62
|
+
|
|
63
|
+
def get_table_object(string)
|
|
64
|
+
table_name = string.match(REGEX_TABLE_START)[2]
|
|
65
|
+
table_columns = []
|
|
66
|
+
string.scan(REGEX_COLUMN) do |column|
|
|
67
|
+
table_columns << Column.new(column[1], column[3])
|
|
68
|
+
end
|
|
69
|
+
table = Table.new(table_name)
|
|
70
|
+
table.columns = table_columns
|
|
71
|
+
table
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
STDIN.each_line do |line|
|
|
75
|
+
# line = line.force_encoding('UTF-8')
|
|
76
|
+
line = line.force_encoding('ISO-8859-1').encode('UTF-8')
|
|
77
|
+
|
|
78
|
+
if line =~ REGEX_DATABASE_1
|
|
79
|
+
database = Database.new($2)
|
|
80
|
+
next
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
if line =~ REGEX_DATABASE_2
|
|
84
|
+
database = Database.new($2)
|
|
85
|
+
next
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
next unless database
|
|
89
|
+
|
|
90
|
+
if line =~ REGEX_TABLE_START
|
|
91
|
+
buffer.reset
|
|
92
|
+
buffer.add(line.chomp)
|
|
93
|
+
parsing_table = true
|
|
94
|
+
next
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
if parsing_table
|
|
98
|
+
buffer.add(line.chomp)
|
|
99
|
+
if line =~ REGEX_TABLE_END
|
|
100
|
+
parsing_table = false
|
|
101
|
+
get_table_object(buffer.flush).tap do |table|
|
|
102
|
+
database.tables << table
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
database.tables.each do |table|
|
|
110
|
+
table.columns.each do |column|
|
|
111
|
+
object = {
|
|
112
|
+
:database => database.name,
|
|
113
|
+
:table => table.name,
|
|
114
|
+
:column => column.name,
|
|
115
|
+
:type => column.type
|
|
116
|
+
}
|
|
117
|
+
puts object.to_json
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
data/bin/ix-noansi
ADDED
data/bin/ix-pad
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
|
|
5
|
+
options = {}
|
|
6
|
+
options[:size] = 2
|
|
7
|
+
|
|
8
|
+
OptionParser.new do |opts|
|
|
9
|
+
|
|
10
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
|
11
|
+
|
|
12
|
+
opts.on('-s', '--size [NUMBER]', 'Size.') do |value|
|
|
13
|
+
options[:size] = value.to_i
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end.parse!
|
|
17
|
+
|
|
18
|
+
required_options = [:size]
|
|
19
|
+
required_options.each do |option|
|
|
20
|
+
unless options[option]
|
|
21
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
|
22
|
+
exit 1
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
options[:size].times do |i|
|
|
27
|
+
puts ''
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
STDIN.each_line do |line|
|
|
31
|
+
puts (' ' * options[:size]) + line.chomp + (' ' * options[:size])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
options[:size].times do |i|
|
|
35
|
+
puts ''
|
|
36
|
+
end
|
data/bin/ix-percentage
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
|
+
require 'isna'
|
|
5
|
+
|
|
4
6
|
# Percentage bar.
|
|
5
7
|
#
|
|
6
8
|
# items = (1..100).to_a
|
|
@@ -14,7 +16,7 @@
|
|
|
14
16
|
class Percentage
|
|
15
17
|
def initialize(product, divisor, scale = 100)
|
|
16
18
|
@product = product
|
|
17
|
-
@scale = scale
|
|
19
|
+
@scale = scale
|
|
18
20
|
@pre_percentage = (divisor * @scale / product).to_f
|
|
19
21
|
@percentage = (@pre_percentage * 100 / @scale)
|
|
20
22
|
@divisor = divisor
|
|
@@ -29,25 +31,37 @@ class Percentage
|
|
|
29
31
|
# 0 ~ 50 green
|
|
30
32
|
# 50 ~ 80 yellow
|
|
31
33
|
# 80 ~ 100 red
|
|
32
|
-
def to_bar(color = true, bar = '|')
|
|
33
|
-
|
|
34
|
-
padding = 0
|
|
34
|
+
def to_bar(color = true, bar = '|', label = '')
|
|
35
|
+
bars = (bar * @pre_percentage.to_f).rjust(@scale, ' ')
|
|
35
36
|
if color
|
|
36
|
-
if to_i
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
if to_i >= 50 and to_i < 80
|
|
40
|
-
filling = "[0;33;1m" + (bar * @pre_percentage.to_f) + "[0m"
|
|
37
|
+
if to_i < 33
|
|
38
|
+
bars = bars.to_ansi.green.to_s
|
|
41
39
|
end
|
|
42
|
-
if to_i >=
|
|
43
|
-
|
|
40
|
+
if to_i >= 33 and to_i < 66
|
|
41
|
+
bars = bars.to_ansi.yellow.to_s
|
|
44
42
|
end
|
|
45
|
-
if
|
|
46
|
-
|
|
43
|
+
if to_i >= 66
|
|
44
|
+
bars = bars.to_ansi.red.to_s
|
|
47
45
|
end
|
|
48
46
|
end
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
|
|
48
|
+
output_percentage = (to_f.round(2).to_s.rjust(5, ' ') + '%')
|
|
49
|
+
output_divisor = @divisor.round(2).to_s.rjust(10, ' ')
|
|
50
|
+
|
|
51
|
+
if color
|
|
52
|
+
output_percentage = output_percentage.to_ansi.pink.to_s
|
|
53
|
+
output_divisor = output_divisor.to_ansi.cyan.to_s
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
bindings = {
|
|
57
|
+
:open => '[',
|
|
58
|
+
:close => ']',
|
|
59
|
+
:bars => bars,
|
|
60
|
+
:percentage => output_percentage,
|
|
61
|
+
:divisor => output_divisor,
|
|
62
|
+
:label => label
|
|
63
|
+
}
|
|
64
|
+
format("%<open>s%<bars>s%<close>s %<percentage>s %<divisor>s %<label>s", bindings)
|
|
51
65
|
end
|
|
52
66
|
end
|
|
53
67
|
|
|
@@ -76,13 +90,75 @@ class Array
|
|
|
76
90
|
|
|
77
91
|
end
|
|
78
92
|
|
|
93
|
+
require 'optparse'
|
|
94
|
+
require 'json'
|
|
95
|
+
|
|
96
|
+
options = {}
|
|
97
|
+
options[:width] = 40
|
|
98
|
+
options[:label] = ''
|
|
99
|
+
options[:char] = '|'
|
|
100
|
+
options[:color] = 'yes'
|
|
101
|
+
|
|
102
|
+
OptionParser.new do |opts|
|
|
103
|
+
|
|
104
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
|
105
|
+
|
|
106
|
+
opts.on('-c', '--char [STRING]', 'Char to use to print the percentage bar') do |value|
|
|
107
|
+
options[:char] = value
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
opts.on('-w', '--width [NUMBER]', 'Chars to use to print the bar.') do |value|
|
|
111
|
+
options[:width] = value.to_f
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
opts.on('-l', '--label [STRING]', 'Label to use when printing out the layout.') do |value|
|
|
115
|
+
options[:label] = value
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
opts.on('-o', '--color [yes|no]', 'Weather if we should use ansi colors to print colors') do |value|
|
|
119
|
+
options[:color] = value
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
opts.on('-j', '--json', 'Will parse json keys as var names, and values as numbers') do |value|
|
|
124
|
+
options[:json] = value
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
end.parse!
|
|
128
|
+
|
|
129
|
+
required_options = [:width, :label, :char, :color]
|
|
130
|
+
required_options.each do |option|
|
|
131
|
+
unless options[option]
|
|
132
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
|
133
|
+
exit 1
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
if options[:color] == 'yes'
|
|
138
|
+
options[:color] = true
|
|
139
|
+
else
|
|
140
|
+
options[:color] = false
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
if options[:width] < 1
|
|
144
|
+
$stderr.puts "Width can not be less than 1."
|
|
145
|
+
exit 1
|
|
146
|
+
end
|
|
79
147
|
|
|
80
148
|
hash = {}
|
|
81
149
|
|
|
82
150
|
STDIN.each_line do |line|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
151
|
+
if options[:json]
|
|
152
|
+
line = JSON.parse(line)
|
|
153
|
+
line.each do |key, value|
|
|
154
|
+
hash[key] ||= []
|
|
155
|
+
hash[key] << value.to_f
|
|
156
|
+
end
|
|
157
|
+
else
|
|
158
|
+
chunks = line.split(/\s+/)
|
|
159
|
+
hash[chunks[0]] ||= []
|
|
160
|
+
hash[chunks[0]] << chunks[1].to_f
|
|
161
|
+
end
|
|
86
162
|
end
|
|
87
163
|
|
|
88
164
|
total = 0
|
|
@@ -91,12 +167,20 @@ hash.keys.each do |key|
|
|
|
91
167
|
total += array.product
|
|
92
168
|
end
|
|
93
169
|
|
|
94
|
-
hash.keys.
|
|
170
|
+
hash.keys.sort do |a, b|
|
|
171
|
+
hash[a].product <=> hash[b].product
|
|
172
|
+
end.reverse.each do |key|
|
|
95
173
|
array = hash[key]
|
|
96
|
-
p = Percentage.new(total, array.product,
|
|
174
|
+
p = Percentage.new(total, array.product, options[:width])
|
|
97
175
|
|
|
98
176
|
template = "%s %s"
|
|
99
|
-
|
|
177
|
+
|
|
178
|
+
if options[:color]
|
|
179
|
+
bindings = [p.to_bar(options[:color], options[:char], options[:label]), key.to_ansi.yellow.to_s]
|
|
180
|
+
else
|
|
181
|
+
bindings = [p.to_bar(options[:color], options[:char], options[:label]), key]
|
|
182
|
+
end
|
|
183
|
+
|
|
100
184
|
puts template % bindings
|
|
101
185
|
end
|
|
102
186
|
|
data/bin/ix-remove
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'isna'
|
|
5
|
+
|
|
6
|
+
options = {}
|
|
7
|
+
|
|
8
|
+
OptionParser.new do |opts|
|
|
9
|
+
|
|
10
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
|
11
|
+
|
|
12
|
+
opts.on('-f', '--file []', 'File with entries to be removed.') do |value|
|
|
13
|
+
options[:file] = value
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end.parse!
|
|
17
|
+
|
|
18
|
+
required_options = [:file]
|
|
19
|
+
required_options.each do |option|
|
|
20
|
+
unless options[option]
|
|
21
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
|
22
|
+
exit 1
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
unless File.exist?(options[:file])
|
|
27
|
+
$stderr.puts "File #{options[:file]} does not exist."
|
|
28
|
+
exit 1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
inputs = []
|
|
32
|
+
entries = []
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
File.read(options[:file]).each_line do |line|
|
|
36
|
+
entries << line
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
STDIN.each_line do |line|
|
|
40
|
+
inputs << line
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
(inputs - entries).each do |item|
|
|
44
|
+
puts item.chomp
|
|
45
|
+
end
|
|
46
|
+
|
data/bin/ix-rjust
ADDED
data/bin/ix-rulers
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
|
|
5
|
+
options = {}
|
|
6
|
+
options[:padding] = 5
|
|
7
|
+
options[:count] = 0
|
|
8
|
+
|
|
9
|
+
OptionParser.new do |opts|
|
|
10
|
+
|
|
11
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
|
12
|
+
|
|
13
|
+
opts.on('-w', '--width [NUMBER]', 'Width of the horizontal ruler (custom).') do |value|
|
|
14
|
+
options[:width] = value.to_i
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
opts.on('-p', '--padding [NUMBER]', 'Padding for numbers on the left.') do |value|
|
|
18
|
+
options[:padding] = value.to_i
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
opts.on('-c', '--count [NUMBER]', 'Count lines starting from.') do |value|
|
|
22
|
+
options[:count] = value.to_i
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end.parse!
|
|
26
|
+
|
|
27
|
+
required_options = [:padding, :count]
|
|
28
|
+
required_options.each do |option|
|
|
29
|
+
unless options[option]
|
|
30
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
|
31
|
+
exit 1
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class Ruler
|
|
36
|
+
attr_accessor :length
|
|
37
|
+
def initialize(length)
|
|
38
|
+
@length = length
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# we print the number of the column
|
|
42
|
+
# in various rows:
|
|
43
|
+
# for example first row will print:
|
|
44
|
+
# 00000000000
|
|
45
|
+
# 00000000011
|
|
46
|
+
# 12345678901
|
|
47
|
+
def to_s
|
|
48
|
+
items = (@length + 1).times.map do |item|
|
|
49
|
+
item.to_s.rjust(5, '0').chars
|
|
50
|
+
end
|
|
51
|
+
items.transpose.map(&:join).join("\n")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
if options[:width]
|
|
57
|
+
Ruler.new(options[:width].to_i).to_s.lines.each do |line|
|
|
58
|
+
puts (' ' * (options[:padding] + 2)) + line
|
|
59
|
+
end
|
|
60
|
+
STDIN.each_line do |line|
|
|
61
|
+
puts "#{options[:count].to_s.rjust(options[:padding], '0')} | #{line}"
|
|
62
|
+
options[:count] += 1
|
|
63
|
+
end
|
|
64
|
+
else
|
|
65
|
+
lines = []
|
|
66
|
+
STDIN.each_line do |line|
|
|
67
|
+
lines << line
|
|
68
|
+
end
|
|
69
|
+
exit 0 if lines.empty?
|
|
70
|
+
options[:width] = lines.map(&:length).max
|
|
71
|
+
Ruler.new(options[:width].to_i).to_s.lines.each do |line|
|
|
72
|
+
puts (' ' * (options[:padding] + 2)) + line
|
|
73
|
+
end
|
|
74
|
+
lines.each do |line|
|
|
75
|
+
puts "#{options[:count].to_s.rjust(options[:padding], '0')} |#{line}"
|
|
76
|
+
options[:count] += 1
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'time'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
def parse_s3_log_line(line)
|
|
7
|
+
|
|
8
|
+
# Split the log line by spaces, respecting quoted strings
|
|
9
|
+
parts = line.scan(/"([^"]+)"|(\S+)/).flatten.compact
|
|
10
|
+
|
|
11
|
+
{
|
|
12
|
+
bucket_owner: parts[0],
|
|
13
|
+
bucket: parts[1],
|
|
14
|
+
time: parts[2] + parts[3], # Remove the brackets around the time
|
|
15
|
+
remote_ip: parts[4],
|
|
16
|
+
requester: parts[5],
|
|
17
|
+
request_id: parts[6],
|
|
18
|
+
operation: parts[7],
|
|
19
|
+
key: parts[8],
|
|
20
|
+
request_uri: parts[9],
|
|
21
|
+
http_status: parts[10].to_i,
|
|
22
|
+
error_code: parts[11],
|
|
23
|
+
bytes_sent: parts[12].to_i,
|
|
24
|
+
object_size: parts[13],
|
|
25
|
+
total_time: parts[14].to_i,
|
|
26
|
+
turnaround_time: parts[15].to_i,
|
|
27
|
+
referer: parts[16],
|
|
28
|
+
user_agent: parts[17],
|
|
29
|
+
version_id: parts[18]
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Read from standard input
|
|
34
|
+
ARGF.each_line do |line|
|
|
35
|
+
parsed_log = parse_s3_log_line(line)
|
|
36
|
+
puts parsed_log.to_json
|
|
37
|
+
end
|
|
38
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
require 'optparse'
|
|
6
|
+
|
|
7
|
+
options = {}
|
|
8
|
+
|
|
9
|
+
OptionParser.new do |opts|
|
|
10
|
+
|
|
11
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
|
12
|
+
|
|
13
|
+
opts.on('-k', '--key [NAME]', 'Key in json to look for a timestamp.') do |value|
|
|
14
|
+
options[:key] = value
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end.parse!
|
|
18
|
+
|
|
19
|
+
required_options = [:key]
|
|
20
|
+
required_options.each do |option|
|
|
21
|
+
unless options[option]
|
|
22
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
|
23
|
+
exit 1
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
times = []
|
|
28
|
+
distances = []
|
|
29
|
+
previous = nil
|
|
30
|
+
|
|
31
|
+
STDIN.each_line do |line|
|
|
32
|
+
object = JSON.parse(line)
|
|
33
|
+
times << object[options[:key]]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
times.sort do |a, b|
|
|
37
|
+
a <=> b
|
|
38
|
+
end.each do |time|
|
|
39
|
+
if previous
|
|
40
|
+
distances << time - previous
|
|
41
|
+
end
|
|
42
|
+
previous = time
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
distances.each do |distance|
|
|
46
|
+
puts "distance #{distance}"
|
|
47
|
+
end
|
data/bin/ix-timestamp2
CHANGED
|
@@ -19,16 +19,14 @@ STDIN.each_line do |line|
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
object = {
|
|
22
|
-
:timestamp => timestamp.to_s.rjust(20, ' '),
|
|
23
22
|
:time => Time.at(timestamp).to_s.rjust(20, ' '),
|
|
24
|
-
:elapsed => format('%1.
|
|
25
|
-
:diff => format('%2.
|
|
23
|
+
:elapsed => format('%1.3f', (timestamp - start)).to_s.rjust(9, ' '),
|
|
24
|
+
:diff => format('%2.3f', (timestamp - prev)).to_s.rjust(9, ' '),
|
|
26
25
|
:lineno => (('| ') + (lineno.to_s)).ljust(5, ' '),
|
|
27
26
|
:message => json['message']
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
if colors
|
|
31
|
-
object[:timestamp] = object[:timestamp].to_s.to_ansi.yellow.to_s
|
|
32
30
|
object[:time] = object[:time].to_s.to_ansi.cyan.to_s
|
|
33
31
|
object[:elapsed] = object[:elapsed].to_s.to_ansi.pink.to_s
|
|
34
32
|
|
|
@@ -47,10 +45,10 @@ STDIN.each_line do |line|
|
|
|
47
45
|
object[:lineno] = object[:lineno].to_s.to_ansi.cyan.to_s
|
|
48
46
|
end
|
|
49
47
|
|
|
50
|
-
puts format("%<
|
|
48
|
+
puts format("%<time>s %<elapsed>s %<diff>s %<lineno>s %<message>s", object)
|
|
51
49
|
prev = timestamp
|
|
52
50
|
rescue => e
|
|
53
|
-
|
|
51
|
+
# puts e.message
|
|
54
52
|
end
|
|
55
53
|
end
|
|
56
54
|
|