riemann-tail 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +1 -0
- data/bin/riemann-tail +28 -0
- data/lib/riemann/tail.rb +52 -0
- data/lib/riemann/tail/config.rb +31 -0
- data/lib/riemann/tail/version.rb +5 -0
- data/query.clj +1 -0
- data/riemann-tail-config.rb +22 -0
- data/riemann-tail.gemspec +27 -0
- metadata +139 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Will Farrell
|
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,72 @@
|
|
1
|
+
# Riemann::Tail
|
2
|
+
|
3
|
+
Subscribe to (tail) [Riemann](http://riemann.io "Riemann") event streams from the console.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'riemann-tail'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install riemann-tail
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
`riemann-tail --help`
|
22
|
+
|
23
|
+
Usage:
|
24
|
+
riemann-tail QUERY
|
25
|
+
|
26
|
+
Options:
|
27
|
+
h, [--host=HOST] # Riemann host
|
28
|
+
# Default: localhost
|
29
|
+
p, [--port=PORT] # Riemann port number
|
30
|
+
# Default: 5556
|
31
|
+
c, [--config=CONFIG] # Path to config file
|
32
|
+
# Default: riemann-tail-config.rb
|
33
|
+
f, [--from-file], [--no-from-file] # Read query from file instead of command
|
34
|
+
|
35
|
+
Subscribe to (tail) a riemann event stream based on QUERY
|
36
|
+
|
37
|
+
Example configuration file (provided as `riemann-tail-config.rb`)
|
38
|
+
|
39
|
+
Riemann::Tail.configure do |c|
|
40
|
+
c.format :host, :blue
|
41
|
+
c.format :metric, [:to_s, :cyan]
|
42
|
+
|
43
|
+
c.format :tags, :light_black do |t|
|
44
|
+
t.join(", ")
|
45
|
+
end
|
46
|
+
|
47
|
+
c.format :time, :light_black do |t|
|
48
|
+
t.localtime.strftime("%T")
|
49
|
+
end
|
50
|
+
|
51
|
+
c.format :state, [:downcase, :bold] do |s|
|
52
|
+
case s
|
53
|
+
when /fail|err/i then s.red
|
54
|
+
when /warn/i then s.yellow
|
55
|
+
else s.green
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
c.line_format = "%{time}#{">".light_black} %{state} %{host} %{service} %{tags} %{metric}\n #{">".light_black} %{description}"
|
60
|
+
end
|
61
|
+
|
62
|
+
Example query file (provided as `query.clj`)
|
63
|
+
|
64
|
+
tagged "log"
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it ( http://github.com/<my-github-username>/riemann-tail/fork )
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/riemann-tail
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
|
5
|
+
require 'thor'
|
6
|
+
require 'riemann/tail'
|
7
|
+
|
8
|
+
Signal.trap 'SIGINT' do
|
9
|
+
puts "interrupted..."
|
10
|
+
Process.exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
class Riemann::Tail::CLI < Thor::Group
|
14
|
+
namespace ""
|
15
|
+
desc "Subscribe to (tail) a riemann event stream based on QUERY"
|
16
|
+
argument :query
|
17
|
+
class_option :host, :aliases => :h, :default => "localhost", :desc => "Riemann host"
|
18
|
+
class_option :port, :aliases => :p, :default => "5556", :desc => "Riemann port number"
|
19
|
+
class_option :config, :aliases => :c, :default => "riemann-tail-config.rb", :desc => "Path to config file"
|
20
|
+
class_option :from_file, :aliases => :f, :type => :boolean, :desc => "Read query from file instead of command"
|
21
|
+
def tail
|
22
|
+
require File.expand_path(options["config"])
|
23
|
+
|
24
|
+
Riemann::Tail.run_query(options["from_file"] ? File.read(query) : query, options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Riemann::Tail::CLI.start(ARGV)
|
data/lib/riemann/tail.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'date'
|
4
|
+
require 'colorize'
|
5
|
+
require 'eventmachine'
|
6
|
+
require 'faye/websocket'
|
7
|
+
|
8
|
+
require "riemann/tail/config"
|
9
|
+
require "riemann/tail/version"
|
10
|
+
|
11
|
+
module Riemann
|
12
|
+
module Tail
|
13
|
+
def self.configure(&block)
|
14
|
+
yield @config = Config.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.run_query(query, options)
|
18
|
+
url = "ws://#{options["host"]}:#{options["port"]}/index?subscribe=true&query=#{URI.encode(query)}"
|
19
|
+
|
20
|
+
EM.run do
|
21
|
+
ws = Faye::WebSocket::Client.new(url)
|
22
|
+
|
23
|
+
ws.on :error do |e|
|
24
|
+
puts "error... #{e.to_s}".red
|
25
|
+
Process.exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
ws.on :close do |e|
|
29
|
+
Process.exit 0
|
30
|
+
end
|
31
|
+
|
32
|
+
ws.on :message do |m|
|
33
|
+
event = JSON.parse(m.data).reduce(@config.defaults.clone) do |o, (k, v)|
|
34
|
+
if k == "time"
|
35
|
+
v = DateTime.parse(v).to_time
|
36
|
+
end
|
37
|
+
|
38
|
+
if fs = @config.formatters[k.to_sym]
|
39
|
+
v = fs[:block].call(v) if fs[:block]
|
40
|
+
v = fs[:methods].reduce(v) { |r, s| r.send(s) } if fs[:methods]
|
41
|
+
end
|
42
|
+
|
43
|
+
o[k.to_sym] = v
|
44
|
+
o
|
45
|
+
end
|
46
|
+
|
47
|
+
puts @config.line_format % event
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Riemann
|
2
|
+
module Tail
|
3
|
+
class Config
|
4
|
+
def initialize
|
5
|
+
@defaults = {}
|
6
|
+
@formatters = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_accessor :line_format, :formatters, :defaults
|
10
|
+
|
11
|
+
def format(field, format, &block)
|
12
|
+
@formatters[field.to_sym] = {
|
13
|
+
methods: (format.is_a?(Array) ? format : [format.to_sym])
|
14
|
+
}
|
15
|
+
@formatters[field.to_sym][:block] = block if block_given?
|
16
|
+
end
|
17
|
+
|
18
|
+
def default(field, value)
|
19
|
+
@defaults[field.to_sym] = value.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def line_format=(format)
|
23
|
+
# hacky way to prevent sprintf (%) from throwing key errors
|
24
|
+
format.scan(/%{([^}]+)}|%<([^>])>/).each do |(m, n)|
|
25
|
+
@defaults[(m||n).to_sym] ||= ""
|
26
|
+
end
|
27
|
+
@line_format = format
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/query.clj
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
tagged "log"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Riemann::Tail.configure do |c|
|
2
|
+
c.format :host, :blue
|
3
|
+
c.format :metric, [:to_s, :cyan]
|
4
|
+
|
5
|
+
c.format :tags, :light_black do |t|
|
6
|
+
t.join(", ")
|
7
|
+
end
|
8
|
+
|
9
|
+
c.format :time, :light_black do |t|
|
10
|
+
t.localtime.strftime("%T")
|
11
|
+
end
|
12
|
+
|
13
|
+
c.format :state, [:downcase, :bold] do |s|
|
14
|
+
case s
|
15
|
+
when /fail|err/i then s.red
|
16
|
+
when /warn/i then s.yellow
|
17
|
+
else s.green
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
c.line_format = "%{time}#{">".light_black} %{state} %{host} %{service} %{tags} %{metric}\n #{">".light_black} %{description}"
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'riemann/tail/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "riemann-tail"
|
8
|
+
spec.version = Riemann::Tail::VERSION
|
9
|
+
spec.authors = ["Will Farrell"]
|
10
|
+
spec.email = ["will@mojotech.com"]
|
11
|
+
spec.summary = %q{Subscribe (tail) Riemann event streams from the console}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/wkf/riemann-tail"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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
|
+
|
21
|
+
spec.add_runtime_dependency 'thor', '~> 0'
|
22
|
+
spec.add_runtime_dependency 'colorize', '~> 0'
|
23
|
+
spec.add_runtime_dependency 'faye-websocket', '~> 0'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riemann-tail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Will Farrell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: colorize
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: faye-websocket
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.5'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.5'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Subscribe (tail) Riemann event streams from the console
|
95
|
+
email:
|
96
|
+
- will@mojotech.com
|
97
|
+
executables:
|
98
|
+
- riemann-tail
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/riemann-tail
|
108
|
+
- lib/riemann/tail.rb
|
109
|
+
- lib/riemann/tail/config.rb
|
110
|
+
- lib/riemann/tail/version.rb
|
111
|
+
- query.clj
|
112
|
+
- riemann-tail-config.rb
|
113
|
+
- riemann-tail.gemspec
|
114
|
+
homepage: https://github.com/wkf/riemann-tail
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.8.23.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Subscribe (tail) Riemann event streams from the console
|
139
|
+
test_files: []
|