logstash-cli 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +22 -4
- data/Rakefile +6 -0
- data/lib/logstash-cli/command/grep.rb +19 -7
- data/lib/logstash-cli/version.rb +1 -1
- metadata +5 -4
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -8,17 +8,31 @@ Because let's face it, we're CLI junkies :)
|
|
8
8
|
Mucho inspired by a gist of the eminent @lusis - <https://gist.github.com/1388077>
|
9
9
|
|
10
10
|
## Installation
|
11
|
-
|
11
|
+
### As a gem
|
12
12
|
|
13
|
-
|
13
|
+
$ gem install logstash-cli
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
### From github
|
16
|
+
|
17
|
+
Tested with rvm and ruby-1.8.7
|
18
|
+
|
19
|
+
$ git clone git://github.com/jedi4ever/logstash-cli.git
|
20
|
+
$ cd logstash-cli
|
17
21
|
$ gem install bundler
|
18
22
|
$ bundle install
|
19
23
|
|
20
24
|
## Usage
|
21
25
|
|
26
|
+
### Using the Gem
|
27
|
+
|
28
|
+
$ logstash-cli
|
29
|
+
|
30
|
+
### Using the Github version - through bundler
|
31
|
+
|
32
|
+
$ bundle exec bin/logstash-cli
|
33
|
+
|
34
|
+
## Commandline Options
|
35
|
+
|
22
36
|
Usage:
|
23
37
|
logstash-cli grep PATTERN
|
24
38
|
|
@@ -48,8 +62,12 @@ Install rvm , (no gem yet)
|
|
48
62
|
## Examples
|
49
63
|
|
50
64
|
$ logstash-cli grep --esurl="http://logger-1.jedi.be:9200" '@message:jedi4ever AND program:sshd' --last 5d --format csv --delim ':'
|
65
|
+
|
51
66
|
## TODO
|
52
67
|
|
53
68
|
- find a way to query existing instances
|
54
69
|
- specify last 15m
|
55
70
|
- find a way to get the results by streaming instead of loading all in memory (maybe pagination will help here)
|
71
|
+
- live tailing the output
|
72
|
+
- produce ascii histograms
|
73
|
+
- or sparklines
|
data/Rakefile
ADDED
@@ -31,10 +31,18 @@ module LogstashCli::Command
|
|
31
31
|
|
32
32
|
$stderr.puts "Searching #{es_url}[#{index_prefix}#{from_date}..#{index_prefix}#{to_date}] - #{pattern}"
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
# Total of results to show
|
35
|
+
total_result_size = options[:size]
|
36
|
+
|
37
|
+
# For this index the number of results to show
|
38
|
+
# Previous indexes might already have generate results
|
39
|
+
|
40
|
+
running_result_size = total_result_size.to_i
|
41
|
+
|
42
|
+
# We reverse the order of working ourselves through the index
|
43
|
+
(from_date..to_date).sort.reverse.to_a.each do |date|
|
36
44
|
|
37
|
-
|
45
|
+
es_index = index_prefix+date.to_s.gsub('-','.')
|
38
46
|
|
39
47
|
begin
|
40
48
|
Tire.configure {url es_url}
|
@@ -45,7 +53,7 @@ module LogstashCli::Command
|
|
45
53
|
sort do
|
46
54
|
by :@timestamp, 'desc'
|
47
55
|
end
|
48
|
-
size
|
56
|
+
size running_result_size
|
49
57
|
end
|
50
58
|
rescue Exception => e
|
51
59
|
$stderr.puts e
|
@@ -55,6 +63,10 @@ module LogstashCli::Command
|
|
55
63
|
|
56
64
|
begin
|
57
65
|
result = Array.new
|
66
|
+
|
67
|
+
# Decrease the number of results to get from the next index
|
68
|
+
running_result_size -= search.results.size
|
69
|
+
|
58
70
|
search.results.sort {|a,b| a[:@timestamp] <=> b[:@timestamp] }.each do |res|
|
59
71
|
|
60
72
|
metafields.each do |metafield|
|
@@ -66,9 +78,9 @@ module LogstashCli::Command
|
|
66
78
|
end
|
67
79
|
|
68
80
|
output = case options[:format]
|
69
|
-
|
70
|
-
|
71
|
-
|
81
|
+
when 'csv' then result.to_csv({:col_sep => options[:delim]})
|
82
|
+
when 'json' then result.to_json
|
83
|
+
end
|
72
84
|
#tstamp = Time.iso8601(res[:@timestamp]).localtime.iso8601
|
73
85
|
|
74
86
|
puts output
|
data/lib/logstash-cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Patrick Debois
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-24 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- .rvmrc
|
132
132
|
- Gemfile
|
133
133
|
- README.md
|
134
|
+
- Rakefile
|
134
135
|
- bin/logstash-cli
|
135
136
|
- lib/logstash-cli.rb
|
136
137
|
- lib/logstash-cli/cli.rb
|