riemann-marathon 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +10 -0
  4. data/bin/riemann-marathon +97 -0
  5. metadata +88 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43500e67579cb7ec39bd9a9238018aa0daf848f9
4
+ data.tar.gz: a367f509d5bcff1ef724f7fcabc09d51f49c93fe
5
+ SHA512:
6
+ metadata.gz: 75eb9e3ac77ac0e1765c409ee3759c4366b123b1b5dcca1fd9795d54d0e6c2b0168f7e7990a3d5569d404e89d22ec683532517cb6b1ef63c8513f6dd59906a64
7
+ data.tar.gz: 03da585d1db87aed865729b7ea6ace0926334561e4638032016ac96d784b0661ced6038fb44771a71dbc92b280d3139423fe5bc2f63e5e96be0fd9c7d6cdd25b
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Kyle Kingsbury
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # Riemann Marathon
2
+
3
+ Gathers Marathon metrics and sends them to Riemann.
4
+
5
+ # Getting started
6
+
7
+ ```
8
+ gem install riemann-marathon
9
+ riemann-marathon --help
10
+ ```
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'riemann/tools'
4
+
5
+ class Riemann::Tools::Marathon
6
+ include Riemann::Tools
7
+
8
+ require 'faraday'
9
+ require 'json'
10
+ require 'uri'
11
+
12
+ opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
13
+ opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
14
+ opt :path_prefix, 'Marathon path prefix for proxied installations e.g. "marathon" for target http://localhost/marathon/metrics', default: "/"
15
+ opt :marathon_host, 'Marathon host', default: "localhost"
16
+ opt :marathon_port, 'Marathon port', type: :int, default: 8080
17
+
18
+ def initialize
19
+ options[:interval] = 60
20
+ options[:ttl] = 120
21
+ end
22
+
23
+ # Handles HTTP connections and GET requests safely
24
+ def safe_get(uri)
25
+ # Handle connection timeouts
26
+ response = nil
27
+ begin
28
+ connection = Faraday.new(uri)
29
+ response = connection.get do |req|
30
+ req.options[:timeout] = options[:read_timeout]
31
+ req.options[:open_timeout] = options[:open_timeout]
32
+ end
33
+ rescue => e
34
+ report(:host => uri.host,
35
+ :service => "marathon health",
36
+ :state => "critical",
37
+ :description => "HTTP connection error: #{e.class} - #{e.message}"
38
+ )
39
+ end
40
+ response
41
+ end
42
+
43
+ def health_url
44
+ path_prefix = options[:path_prefix]
45
+ path_prefix[0] = '' if path_prefix[0]=='/'
46
+ path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
47
+ "http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/metrics"
48
+ end
49
+
50
+ def tick
51
+ uri = URI(health_url)
52
+ response = safe_get(uri)
53
+
54
+ return if response.nil?
55
+
56
+ if response.status != 200
57
+ report(:host => uri.host,
58
+ :service => "marathon health",
59
+ :state => "critical",
60
+ :description => "HTTP connection error: #{response.status} - #{response.body}"
61
+ )
62
+ else
63
+ # Assuming that a 200 will give json
64
+ json = JSON.parse(response.body)
65
+ state = "ok"
66
+
67
+ report(:host => uri.host,
68
+ :service => "marathon health",
69
+ :state => state)
70
+
71
+ json.each_pair do |t, d|
72
+ if d.respond_to? :each_pair
73
+ d.each_pair do |service, counters|
74
+ report(:host => uri.host,
75
+ :service => "marathon_metric #{t} #{service}",
76
+ :metric => 1,
77
+ :tags => ["metric_name"]
78
+ )
79
+ if counters.respond_to? :each_pair
80
+ counters.each_pair do |k, v|
81
+ if v.is_a? Numeric
82
+ report(:host => uri.host,
83
+ :service => "marathon #{service} #{k}",
84
+ :metric => v,
85
+ :tags => ["metric", "#{t}"]
86
+ )
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ Riemann::Tools::Marathon.run
97
+
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riemann-marathon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Giulio Eulisse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: riemann-tools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email: giulio.eulisse@cern.ch
57
+ executables:
58
+ - riemann-marathon
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - bin/riemann-marathon
65
+ homepage: https://github.com/riemann/riemann-marathon
66
+ licenses: []
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.7
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project: riemann-marathon
84
+ rubygems_version: 2.4.5
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Submits marathon stats to riemann.
88
+ test_files: []