riemann-elasticsearch 0.1.0

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-elasticsearch +91 -0
  5. metadata +88 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 491ca44659943eebc94c4eaa056480a4e7021cef
4
+ data.tar.gz: d1856d1eadb18e55bb1080ccd1bb0b3590f6560d
5
+ SHA512:
6
+ metadata.gz: e90efda09605d6b06cb64c0ed5555fea9a21ee74e547cf6e43e4339d71deb136a9e5a9ad6eaeeb94ce720d5b3795195c88b0b581f4bf02be41bcdba9bba2f88d
7
+ data.tar.gz: 6938d042d812cf60f15180574281a75f1745899b264aa26596e89d9ec2c4aed89612a8f4ae67943c1315709e827881b7c50e1365a4a9880bbf315377b5b222f9
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 Elasticsearch
2
+
3
+ Gathers Elasticsearch metrics and sends them to Riemann.
4
+
5
+ # Getting started
6
+
7
+ ```
8
+ gem install riemann-elasticsearch
9
+ riemann-elasticsearch --help
10
+ ```
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'riemann/tools'
4
+
5
+ class Riemann::Tools::Elasticsearch
6
+ include Riemann::Tools
7
+ require 'faraday'
8
+ require 'json'
9
+ require 'uri'
10
+
11
+ opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
12
+ opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
13
+ opt :path_prefix, 'Elasticsearch path prefix for proxied installations e.g. "els" for target http://localhost/els/_cluster/health', default: "/"
14
+ opt :es_host, 'Elasticsearch host', default: "localhost"
15
+ opt :es_port, 'Elasticsearch port', type: :int, default: 9200
16
+
17
+
18
+ # Handles HTTP connections and GET requests safely
19
+ def safe_get(uri)
20
+ # Handle connection timeouts
21
+ response = nil
22
+ begin
23
+ connection = Faraday.new(uri)
24
+ response = connection.get do |req|
25
+ req.options[:timeout] = options[:read_timeout]
26
+ req.options[:open_timeout] = options[:open_timeout]
27
+ end
28
+ rescue => e
29
+ report(:host => uri.host,
30
+ :service => "elasticsearch health",
31
+ :state => "critical",
32
+ :description => "HTTP connection error: #{e.class} - #{e.message}"
33
+ )
34
+ end
35
+ response
36
+ end
37
+
38
+ def health_url
39
+ path_prefix = options[:path_prefix]
40
+ path_prefix[0] = '' if path_prefix[0]=='/'
41
+ path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
42
+ "http://#{options[:es_host]}:#{options[:es_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/_cluster/health"
43
+ end
44
+
45
+ def tick
46
+ uri = URI(health_url)
47
+ response = safe_get(uri)
48
+
49
+ return if response.nil?
50
+
51
+ if response.status != 200
52
+ report(:host => uri.host,
53
+ :service => "elasticsearch health",
54
+ :state => "critical",
55
+ :description => "HTTP connection error: #{response.status} - #{response.body}"
56
+ )
57
+ else
58
+ # Assuming that a 200 will give json
59
+ json = JSON.parse(response.body)
60
+ cluster_name = json.delete("cluster_name")
61
+ cluster_status = json.delete("status")
62
+ state = case cluster_status
63
+ when "green"
64
+ "ok"
65
+ when "yellow"
66
+ "warning"
67
+ when "red"
68
+ "critical"
69
+ end
70
+
71
+ report(:host => uri.host,
72
+ :service => "elasticsearch health",
73
+ :state => state,
74
+ :description => "Elasticsearch cluster: #{cluster_name} - #{cluster_status}")
75
+
76
+ json.each_pair do |k,v|
77
+ report(:host => uri.host,
78
+ :service => "elasticsearch #{k}",
79
+ :metric => v,
80
+ :description => "Elasticsearch cluster #{k}"
81
+ )
82
+
83
+ end
84
+ end
85
+ end
86
+
87
+
88
+
89
+ end
90
+ Riemann::Tools::Elasticsearch.run
91
+
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riemann-elasticsearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gavin Sandie
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: beach@vicecity.co.uk
57
+ executables:
58
+ - riemann-elasticsearch
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - bin/riemann-elasticsearch
65
+ homepage: https://github.com/riemann/riemann-elasticsearch
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-elasticsearch
84
+ rubygems_version: 2.4.5
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Submits elasticsearch stats to riemann.
88
+ test_files: []