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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 911ac0cc7a790092c918a1c9bad343efa5de859d
4
- data.tar.gz: 24f93e4ea6097e95d06ae1a54b01b3353fd60216
3
+ metadata.gz: 97112bfb0c6266531f411fd2cadb57d062037f38
4
+ data.tar.gz: e5d823d25ee7e47d23032a580bb9e9c2d5a523b2
5
5
  SHA512:
6
- metadata.gz: f6f64620815d8fb0b586fd5c8a501076d1b0786757d5fa7c3420ba8a20671b5fed5e582c7fe7b8a982e101ce34da3d2f17da5131ff32b22bf36a9aabcab16a33
7
- data.tar.gz: 1d38903b296027c9bf6b865a402f83c5df160611e8199baaa5fc19995d1d46fc5c56017e3d50ba3b48d5641133cfc22700890c44ca9982f95ae79c8ed880b598
6
+ metadata.gz: 79dfaa6fe946e8156a9d634b34c2f0f732a7c016869e9d8bd7221fe0661ad41d7b27bd771ef25803f7bca277468415f6dbf0e5db13d581f878fac3063a003539
7
+ data.tar.gz: 5e1354b6b273449fede82400f7474ad555b04ac510e3f1ac1973ace0c1b49c512f403890ac54f9388a01e992b905542f05eb3786bfeb72c062bfb5fafc06d4c8
@@ -1,75 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
- require 'trollop'
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
- opt :cassandra_jmx_host, 'Cassandra JMX host', type: :string, default: "localhost"
19
- opt :cassandra_jmx_port, 'Cassandra JMX port', type: :int, default: 7199
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
- # Initialise Cassandra JMX client
36
- cassandra = Riemann::Cassandra::Client.new opts[:cassandra_jmx_host], opts[:cassandra_jmx_port]
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
- loop do
39
- begin
40
- # Send metric events
12
+ def tick
41
13
  Riemann::Cassandra::METRIC_PARAMS.each do |mp|
42
- metric_event = {
43
- service: "cassandra #{mp[:event][:service]}",
44
- host: opts[:event_host],
45
- metric: cassandra.metric(mp[:attribute], mp[:jmx_path]),
46
- description: mp[:event][:description],
47
- time: Time.now.utc.to_i,
48
- tags: opts[:tags],
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
- # Send health event
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
- # riemann << health_event
68
- # puts health_event
69
- puts "\n"
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
@@ -1,5 +1,5 @@
1
1
  module Riemann
2
2
  module Cassandra
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -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.3
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-21 00:00:00.000000000 Z
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: