riemann-cassandra 0.1.3-java → 0.1.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/riemann-cassandra +20 -63
- data/lib/riemann/cassandra/version.rb +1 -1
- data/lib/riemann/tools.rb +112 -0
- 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: 97112bfb0c6266531f411fd2cadb57d062037f38
|
4
|
+
data.tar.gz: e5d823d25ee7e47d23032a580bb9e9c2d5a523b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79dfaa6fe946e8156a9d634b34c2f0f732a7c016869e9d8bd7221fe0661ad41d7b27bd771ef25803f7bca277468415f6dbf0e5db13d581f878fac3063a003539
|
7
|
+
data.tar.gz: 5e1354b6b273449fede82400f7474ad555b04ac510e3f1ac1973ace0c1b49c512f403890ac54f9388a01e992b905542f05eb3786bfeb72c062bfb5fafc06d4c8
|
data/bin/riemann-cassandra
CHANGED
@@ -1,75 +1,32 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
3
|
-
require 'socket'
|
4
|
-
require 'riemann/client'
|
2
|
+
require 'riemann/tools'
|
5
3
|
require 'riemann/cassandra'
|
6
4
|
|
7
|
-
opts_parser = Trollop::Parser.new do
|
8
|
-
opt :host, "Riemann host", default: '127.0.0.1'
|
9
|
-
opt :port, "Riemann port", default: 5555
|
10
|
-
opt :event_host, "Event hostname", type: String, default: Socket.gethostname
|
11
|
-
opt :interval, "Seconds between updates", type: :int, default: 5
|
12
|
-
opt :tag, "Tag to add to events", type: String, multi: true
|
13
|
-
opt :ttl, "TTL for events", type: Integer, default: 10
|
14
|
-
opt :attribute, "Attribute to add to the event", type: String, multi: true
|
15
|
-
opt :timeout, "Timeout (in seconds) when waiting for acknowledgements", default: 30
|
16
|
-
opt :tcp, "Use TCP transport instead of UDP (improves reliability, slight overhead.", default: true
|
17
5
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
opts = Trollop::with_standard_exception_handling opts_parser do
|
23
|
-
opts_parser.parse ARGV
|
24
|
-
end
|
25
|
-
|
26
|
-
# Initialise Riemann client
|
27
|
-
riemann = Riemann::Client.new(host: opts[:host], port: opts[:port], timeout: opts[:timeout])
|
28
|
-
|
29
|
-
if opts[:tcp]
|
30
|
-
riemann = riemann.tcp
|
31
|
-
else
|
32
|
-
riemann = riemann.udp
|
33
|
-
end
|
6
|
+
class Riemann::Tools::Cassandra
|
7
|
+
include Riemann::Tools
|
34
8
|
|
35
|
-
|
36
|
-
|
9
|
+
opt :cassandra_jmx_host, 'Cassandra JMX host', type: String, default: "localhost"
|
10
|
+
opt :cassandra_jmx_port, 'Cassandra JMX port', type: Integer, default: 7199
|
37
11
|
|
38
|
-
|
39
|
-
begin
|
40
|
-
# Send metric events
|
12
|
+
def tick
|
41
13
|
Riemann::Cassandra::METRIC_PARAMS.each do |mp|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
ttl: opts[:ttl]
|
50
|
-
}
|
51
|
-
|
52
|
-
riemann << metric_event
|
53
|
-
puts metric_event
|
14
|
+
report service: "cassandra #{mp[:event][:service]}",
|
15
|
+
host: options[:event_host],
|
16
|
+
metric: cassandra.metric(mp[:attribute], mp[:jmx_path]),
|
17
|
+
description: mp[:event][:description],
|
18
|
+
time: Time.now.utc.to_i,
|
19
|
+
tags: options[:tags],
|
20
|
+
ttl: options[:ttl]
|
54
21
|
end
|
22
|
+
end
|
55
23
|
|
56
|
-
|
57
|
-
# health_event = {
|
58
|
-
# service: 'cassandra health',
|
59
|
-
# host: opts[:event_host],
|
60
|
-
# state: 'ok',
|
61
|
-
# description: 'Cassandra status connection ok',
|
62
|
-
# time: Time.now.utc.to_i,
|
63
|
-
# tags: opts[:tags],
|
64
|
-
# ttl: opts[:ttl]
|
65
|
-
# }
|
24
|
+
private
|
66
25
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
rescue => e
|
71
|
-
$stderr.puts "#{e.class} #{e}\n#{e.backtrace.join "\n"}"
|
26
|
+
def cassandra
|
27
|
+
@_cassandra ||= Riemann::Cassandra::Client.new options[:cassandra_jmx_host],
|
28
|
+
options[:cassandra_jmx_port]
|
72
29
|
end
|
73
|
-
|
74
|
-
sleep(opts[:interval])
|
75
30
|
end
|
31
|
+
|
32
|
+
Riemann::Tools::Cassandra.run
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# I copied this one herar because the origil gem depends on other gems which
|
2
|
+
# cannot be built with JRuby. When the clients with those dependecies are
|
3
|
+
# extracted out of the riemann-tools gem I will switch to it.
|
4
|
+
|
5
|
+
module Riemann
|
6
|
+
module Tools
|
7
|
+
require 'trollop'
|
8
|
+
require 'socket'
|
9
|
+
require 'riemann/client'
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.instance_eval do
|
13
|
+
def run
|
14
|
+
new.run
|
15
|
+
end
|
16
|
+
|
17
|
+
def opt(*a)
|
18
|
+
a.unshift :opt
|
19
|
+
@opts ||= []
|
20
|
+
@opts << a
|
21
|
+
end
|
22
|
+
|
23
|
+
def options
|
24
|
+
p = Trollop::Parser.new
|
25
|
+
@opts.each do |o|
|
26
|
+
p.send *o
|
27
|
+
end
|
28
|
+
Trollop::with_standard_exception_handling(p) do
|
29
|
+
p.parse ARGV
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
opt :host, "Riemann host", :default => '127.0.0.1'
|
34
|
+
opt :port, "Riemann port", :default => 5555
|
35
|
+
opt :event_host, "Event hostname", :type => String, default: Socket.gethostname
|
36
|
+
opt :interval, "Seconds between updates", :default => 5
|
37
|
+
opt :tag, "Tag to add to events", :type => String, :multi => true
|
38
|
+
opt :ttl, "TTL for events", :type => Integer
|
39
|
+
opt :attribute, "Attribute to add to the event", :type => String, :multi => true
|
40
|
+
opt :timeout, "Timeout (in seconds) when waiting for acknowledgements", :default => 30
|
41
|
+
opt :tcp, "Use TCP transport instead of UDP (improves reliability, slight overhead.", :default => true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns parsed options (cached) from command line.
|
46
|
+
def options
|
47
|
+
@options ||= self.class.options
|
48
|
+
end
|
49
|
+
alias :opts :options
|
50
|
+
|
51
|
+
def attributes
|
52
|
+
@attributes ||= Hash[options[:attribute].map do |attr|
|
53
|
+
k,v = attr.split(/=/)
|
54
|
+
if k and v
|
55
|
+
[k,v]
|
56
|
+
end
|
57
|
+
end]
|
58
|
+
end
|
59
|
+
|
60
|
+
def report(event)
|
61
|
+
if options[:tag]
|
62
|
+
# Work around a bug with beefcake which can't take frozen strings.
|
63
|
+
event[:tags] = options[:tag].map(&:dup)
|
64
|
+
end
|
65
|
+
|
66
|
+
event[:ttl] ||= (options[:ttl] || (options[:interval] * 2))
|
67
|
+
|
68
|
+
if options[:event_host]
|
69
|
+
event[:host] = options[:event_host].dup
|
70
|
+
end
|
71
|
+
|
72
|
+
event = event.merge(attributes)
|
73
|
+
|
74
|
+
riemann << event
|
75
|
+
end
|
76
|
+
|
77
|
+
def new_riemann_client
|
78
|
+
r = Riemann::Client.new(
|
79
|
+
:host => options[:host],
|
80
|
+
:port => options[:port],
|
81
|
+
:timeout => options[:timeout]
|
82
|
+
)
|
83
|
+
if options[:tcp]
|
84
|
+
r.tcp
|
85
|
+
else
|
86
|
+
r
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def riemann
|
91
|
+
@riemann ||= new_riemann_client
|
92
|
+
end
|
93
|
+
alias :r :riemann
|
94
|
+
|
95
|
+
def run
|
96
|
+
t0 = Time.now
|
97
|
+
loop do
|
98
|
+
begin
|
99
|
+
tick
|
100
|
+
rescue => e
|
101
|
+
$stderr.puts "#{e.class} #{e}\n#{e.backtrace.join "\n"}"
|
102
|
+
end
|
103
|
+
|
104
|
+
# Sleep.
|
105
|
+
sleep(options[:interval] - ((Time.now - t0) % options[:interval]))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def tick
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riemann-cassandra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Deyan Dobrinov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/riemann/cassandra/client.rb
|
86
86
|
- lib/riemann/cassandra/metric_params.rb
|
87
87
|
- lib/riemann/cassandra/version.rb
|
88
|
+
- lib/riemann/tools.rb
|
88
89
|
- riemann-cassandra.gemspec
|
89
90
|
homepage: https://github.com/dobrinov/riemann-cassandra
|
90
91
|
licenses:
|