riemann-tools 0.2.11 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.docker/Dockerfile +7 -0
- data/.docker/publish.sh +35 -0
- data/.github/workflows/ci.yml +29 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +31 -0
- data/CHANGELOG.md +393 -0
- data/Gemfile +6 -0
- data/ISSUE_TEMPLATE.md +15 -0
- data/README.markdown +17 -1
- data/Rakefile +21 -0
- data/bin/riemann-apache-status +1 -0
- data/bin/riemann-bench +1 -0
- data/bin/riemann-cloudant +1 -0
- data/bin/riemann-consul +3 -2
- data/bin/riemann-dir-files-count +1 -0
- data/bin/riemann-dir-space +1 -0
- data/bin/riemann-diskstats +1 -0
- data/bin/riemann-fd +1 -0
- data/bin/riemann-freeswitch +1 -0
- data/bin/riemann-haproxy +1 -0
- data/bin/riemann-health +87 -10
- data/bin/riemann-kvminstance +1 -0
- data/bin/riemann-memcached +1 -0
- data/bin/riemann-net +3 -2
- data/bin/riemann-nginx-status +1 -0
- data/bin/riemann-ntp +1 -0
- data/bin/riemann-portcheck +42 -0
- data/bin/riemann-proc +2 -1
- data/bin/riemann-varnish +1 -0
- data/bin/riemann-zookeeper +1 -0
- data/lib/riemann/tools/utils.rb +17 -0
- data/lib/riemann/tools/version.rb +7 -0
- data/lib/riemann/tools.rb +15 -5
- data/riemann-tools.gemspec +39 -0
- data/tools/riemann-aws/LICENSE +21 -0
- data/tools/riemann-aws/README.md +54 -0
- data/tools/riemann-aws/Rakefile.rb +35 -0
- data/tools/riemann-aws/bin/riemann-aws-billing +87 -0
- data/tools/riemann-aws/bin/riemann-aws-rds-status +54 -0
- data/tools/riemann-aws/bin/riemann-aws-sqs-status +44 -0
- data/tools/riemann-aws/bin/riemann-aws-status +71 -0
- data/tools/riemann-aws/bin/riemann-elb-metrics +167 -0
- data/tools/riemann-aws/bin/riemann-s3-list +82 -0
- data/tools/riemann-aws/bin/riemann-s3-status +99 -0
- data/tools/riemann-chronos/LICENSE +21 -0
- data/tools/riemann-chronos/README.md +10 -0
- data/tools/riemann-chronos/Rakefile.rb +35 -0
- data/tools/riemann-chronos/bin/riemann-chronos +144 -0
- data/tools/riemann-docker/LICENSE +21 -0
- data/tools/riemann-docker/README.md +10 -0
- data/tools/riemann-docker/Rakefile.rb +34 -0
- data/tools/riemann-docker/bin/riemann-docker +217 -0
- data/tools/riemann-elasticsearch/LICENSE +21 -0
- data/tools/riemann-elasticsearch/README.md +10 -0
- data/tools/riemann-elasticsearch/Rakefile.rb +35 -0
- data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +166 -0
- data/tools/riemann-marathon/LICENSE +21 -0
- data/tools/riemann-marathon/README.md +10 -0
- data/tools/riemann-marathon/Rakefile.rb +35 -0
- data/tools/riemann-marathon/bin/riemann-marathon +147 -0
- data/tools/riemann-mesos/LICENSE +21 -0
- data/tools/riemann-mesos/README.md +10 -0
- data/tools/riemann-mesos/Rakefile.rb +35 -0
- data/tools/riemann-mesos/bin/riemann-mesos +131 -0
- data/tools/riemann-munin/LICENSE +21 -0
- data/tools/riemann-munin/README.md +10 -0
- data/tools/riemann-munin/Rakefile.rb +34 -0
- data/tools/riemann-munin/bin/riemann-munin +37 -0
- data/tools/riemann-rabbitmq/LICENSE +21 -0
- data/tools/riemann-rabbitmq/README.md +10 -0
- data/tools/riemann-rabbitmq/Rakefile.rb +35 -0
- data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +269 -0
- data/tools/riemann-riak/LICENSE +21 -0
- data/tools/riemann-riak/README.md +10 -0
- data/tools/riemann-riak/Rakefile.rb +34 -0
- data/tools/riemann-riak/bin/riemann-riak +331 -0
- data/tools/riemann-riak/bin/riemann-riak-keys +13 -0
- data/tools/riemann-riak/bin/riemann-riak-ring +9 -0
- data/tools/riemann-riak/riak_status/key_count.erl +13 -0
- data/tools/riemann-riak/riak_status/riak_status.rb +152 -0
- data/tools/riemann-riak/riak_status/ringready.erl +9 -0
- metadata +130 -16
@@ -0,0 +1,144 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
Process.setproctitle($0)
|
3
|
+
|
4
|
+
require 'riemann/tools'
|
5
|
+
|
6
|
+
class Riemann::Tools::Chronos
|
7
|
+
include Riemann::Tools
|
8
|
+
|
9
|
+
require 'faraday'
|
10
|
+
require 'json'
|
11
|
+
require 'uri'
|
12
|
+
|
13
|
+
opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
|
14
|
+
opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
|
15
|
+
opt :path_prefix, 'Chronos path prefix for proxied installations e.g. "chronos" for target http://localhost/chronos/metrics', default: "/"
|
16
|
+
opt :chronos_host, 'Chronos host', default: "localhost"
|
17
|
+
opt :chronos_port, 'Chronos port', type: :int, default: 4400
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
options[:interval] = 60
|
21
|
+
options[:ttl] = 120
|
22
|
+
end
|
23
|
+
|
24
|
+
# Handles HTTP connections and GET requests safely
|
25
|
+
def safe_get(uri)
|
26
|
+
# Handle connection timeouts
|
27
|
+
response = nil
|
28
|
+
begin
|
29
|
+
connection = Faraday.new(uri)
|
30
|
+
response = connection.get do |req|
|
31
|
+
req.options[:timeout] = options[:read_timeout]
|
32
|
+
req.options[:open_timeout] = options[:open_timeout]
|
33
|
+
end
|
34
|
+
rescue => e
|
35
|
+
report(:host => uri.host,
|
36
|
+
:service => "chronos health",
|
37
|
+
:state => "critical",
|
38
|
+
:description => "HTTP connection error: #{e.class} - #{e.message}"
|
39
|
+
)
|
40
|
+
end
|
41
|
+
response
|
42
|
+
end
|
43
|
+
|
44
|
+
def health_url
|
45
|
+
path_prefix = options[:path_prefix]
|
46
|
+
path_prefix[0] = '' if path_prefix[0]=='/'
|
47
|
+
path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
|
48
|
+
"http://#{options[:chronos_host]}:#{options[:chronos_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/metrics"
|
49
|
+
end
|
50
|
+
|
51
|
+
def jobs_url
|
52
|
+
path_prefix = options[:path_prefix]
|
53
|
+
path_prefix[0] = '' if path_prefix[0]=='/'
|
54
|
+
path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
|
55
|
+
"http://#{options[:chronos_host]}:#{options[:chronos_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/scheduler/jobs"
|
56
|
+
end
|
57
|
+
|
58
|
+
def tick
|
59
|
+
tick_health
|
60
|
+
tick_jobs
|
61
|
+
end
|
62
|
+
|
63
|
+
def tick_health
|
64
|
+
uri = URI(health_url)
|
65
|
+
response = safe_get(uri)
|
66
|
+
|
67
|
+
return if response.nil?
|
68
|
+
|
69
|
+
if response.status != 200
|
70
|
+
report(:host => uri.host,
|
71
|
+
:service => "chronos health",
|
72
|
+
:state => "critical",
|
73
|
+
:description => "HTTP connection error: #{response.status} - #{response.body}"
|
74
|
+
)
|
75
|
+
else
|
76
|
+
# Assuming that a 200 will give json
|
77
|
+
json = JSON.parse(response.body)
|
78
|
+
|
79
|
+
report(:host => uri.host,
|
80
|
+
:service => "chronos health",
|
81
|
+
:state => "ok")
|
82
|
+
|
83
|
+
json.each_pair do |t, d|
|
84
|
+
if d.respond_to? :each_pair
|
85
|
+
d.each_pair do |service, counters|
|
86
|
+
report(:host => uri.host,
|
87
|
+
:service => "chronos_metric #{t} #{service}",
|
88
|
+
:metric => 1,
|
89
|
+
:tags => ["metric_name"],
|
90
|
+
:ttl => 600
|
91
|
+
)
|
92
|
+
if counters.respond_to? :each_pair
|
93
|
+
counters.each_pair do |k, v|
|
94
|
+
if v.is_a? Numeric
|
95
|
+
report(:host => uri.host,
|
96
|
+
:service => "chronos #{service} #{k}",
|
97
|
+
:metric => v,
|
98
|
+
:tags => ["metric", "#{t}"],
|
99
|
+
:ttl => 600
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def tick_jobs
|
111
|
+
uri = URI(jobs_url)
|
112
|
+
response = safe_get(uri)
|
113
|
+
|
114
|
+
return if response.nil?
|
115
|
+
|
116
|
+
if response.status != 200
|
117
|
+
report(:host => uri.host,
|
118
|
+
:service => "chronos health",
|
119
|
+
:state => "critical",
|
120
|
+
:description => "HTTP connection error: #{response.status} - #{response.body}"
|
121
|
+
)
|
122
|
+
else
|
123
|
+
# Assuming that a 200 will give json
|
124
|
+
json = JSON.parse(response.body)
|
125
|
+
|
126
|
+
report(:host => uri.host,
|
127
|
+
:service => "chronos health",
|
128
|
+
:state => "ok")
|
129
|
+
|
130
|
+
json.each do |job|
|
131
|
+
job.each_pair do |k, v|
|
132
|
+
if v.is_a? Numeric
|
133
|
+
report(:host => uri.host,
|
134
|
+
:service => "chronos job #{job["name"]} #{k}",
|
135
|
+
:metric => v,
|
136
|
+
:ttl => 120
|
137
|
+
)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
Riemann::Tools::Chronos.run
|
@@ -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.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/package_task'
|
3
|
+
require 'rdoc/task'
|
4
|
+
require 'find'
|
5
|
+
|
6
|
+
# Don't include resource forks in tarballs on Mac OS X.
|
7
|
+
ENV['COPY_EXTENDED_ATTRIBUTES_DISABLE'] = 'true'
|
8
|
+
ENV['COPYFILE_DISABLE'] = 'true'
|
9
|
+
|
10
|
+
# Gemspec
|
11
|
+
gemspec = Gem::Specification.new do |s|
|
12
|
+
s.rubyforge_project = 'riemann-docker'
|
13
|
+
|
14
|
+
s.name = 'riemann-docker'
|
15
|
+
s.version = '0.1.3'
|
16
|
+
s.author = 'Shani Elharrar'
|
17
|
+
s.email = ''
|
18
|
+
s.homepage = 'https://github.com/riemann/riemann-tools'
|
19
|
+
s.platform = Gem::Platform::RUBY
|
20
|
+
s.summary = 'Submits Docker container stats to riemann.'
|
21
|
+
s.license = 'MIT'
|
22
|
+
|
23
|
+
s.add_dependency 'riemann-tools', '>= 0.2.13'
|
24
|
+
s.add_dependency 'docker-api', '>= 1.22.0'
|
25
|
+
|
26
|
+
s.files = FileList['bin/*', 'LICENSE', 'README.md'].to_a
|
27
|
+
s.executables |= Dir.entries('bin/')
|
28
|
+
s.has_rdoc = false
|
29
|
+
|
30
|
+
s.required_ruby_version = '>= 1.8.7'
|
31
|
+
end
|
32
|
+
|
33
|
+
Gem::PackageTask.new gemspec do |p|
|
34
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
Process.setproctitle($0)
|
3
|
+
|
4
|
+
# Reports current CPU, disk, load average, and memory use to riemann.
|
5
|
+
|
6
|
+
require 'riemann/tools'
|
7
|
+
|
8
|
+
class Riemann::Tools::DockerHealth
|
9
|
+
require 'docker'
|
10
|
+
require 'socket'
|
11
|
+
include Riemann::Tools
|
12
|
+
include Docker
|
13
|
+
|
14
|
+
opt :docker_host, "Docker Container Host (see https://github.com/swipely/docker-api#host)", :type => String, :default => nil
|
15
|
+
opt :cpu_warning, "CPU warning threshold (fraction of total jiffies)", :default => 0.9
|
16
|
+
opt :cpu_critical, "CPU critical threshold (fraction of total jiffies)", :default => 0.95
|
17
|
+
opt :disk_warning, "Disk warning threshold (fraction of space used)", :default => 0.9
|
18
|
+
opt :disk_critical, "Disk critical threshold (fraction of space used)", :default => 0.95
|
19
|
+
opt :memory_warning, "Memory warning threshold (fraction of RAM)", :default => 0.85
|
20
|
+
opt :memory_critical, "Memory critical threshold (fraction of RAM)", :default => 0.95
|
21
|
+
opt :host_hostname, "Suffix of host", :type => String, :default => nil
|
22
|
+
opt :checks, "A list of checks to run.", :type => :strings, :default => ['cpu', 'memory', 'disk', 'basic']
|
23
|
+
|
24
|
+
def get_containers
|
25
|
+
Docker::Container.all
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_container_name(container)
|
29
|
+
container.json['Name'][1..-1]
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
|
34
|
+
if (opts[:docker_host] != nil)
|
35
|
+
Docker.url = opts[:docker_host]
|
36
|
+
end
|
37
|
+
|
38
|
+
@hostname = opts[:host_hostname]
|
39
|
+
if (@hostname.nil? || !(@hostname.is_a? String) || @hostname.empty?)
|
40
|
+
@hostname = Socket.gethostname
|
41
|
+
end
|
42
|
+
|
43
|
+
@cpu_coefficient = 1000 * 1000 * 1000
|
44
|
+
|
45
|
+
@limits = {
|
46
|
+
:cpu => {:critical => opts[:cpu_critical], :warning => opts[:cpu_warning]},
|
47
|
+
:disk => {:critical => opts[:disk_critical], :warning => opts[:disk_warning]},
|
48
|
+
:memory => {:critical => opts[:memory_critical], :warning => opts[:memory_warning]}
|
49
|
+
}
|
50
|
+
|
51
|
+
@last_cpu_reads = Hash.new
|
52
|
+
@last_uptime_reads = Hash.new
|
53
|
+
|
54
|
+
opts[:checks].each do |check|
|
55
|
+
case check
|
56
|
+
when 'disk'
|
57
|
+
@disk_enabled = true
|
58
|
+
when 'cpu'
|
59
|
+
@cpu_enabled = true
|
60
|
+
when 'memory'
|
61
|
+
@memory_enabled = true
|
62
|
+
when 'basic'
|
63
|
+
@basic_inspection_enabled = true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def alert(container, service, state, metric, description)
|
69
|
+
|
70
|
+
opts = { :service => service.to_s,
|
71
|
+
:state => state.to_s,
|
72
|
+
:metric => metric.to_f,
|
73
|
+
:description => description }
|
74
|
+
|
75
|
+
if (container != nil)
|
76
|
+
opts[:host] = "#{@hostname}-#{container}"
|
77
|
+
else
|
78
|
+
opts[:host] = @hostname
|
79
|
+
end
|
80
|
+
|
81
|
+
report(opts)
|
82
|
+
end
|
83
|
+
|
84
|
+
def report_pct(container, service, fraction, report = '', name = nil)
|
85
|
+
if fraction
|
86
|
+
|
87
|
+
if (name == nil)
|
88
|
+
name = service
|
89
|
+
end
|
90
|
+
|
91
|
+
if fraction > @limits[service][:critical]
|
92
|
+
alert container, name, :critical, fraction, "#{sprintf("%.2f", fraction * 100)}% #{report}"
|
93
|
+
elsif fraction > @limits[service][:warning]
|
94
|
+
alert container, name, :warning, fraction, "#{sprintf("%.2f", fraction * 100)}% #{report}"
|
95
|
+
else
|
96
|
+
alert container, name, :ok, fraction, "#{sprintf("%.2f", fraction * 100)}% #{report}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
def cpu(id, name, stats)
|
103
|
+
|
104
|
+
current = stats['precpu_stats']['cpu_usage']['total_usage'] / stats['precpu_stats']['cpu_usage']['percpu_usage'].count
|
105
|
+
|
106
|
+
unless current
|
107
|
+
alert name, :cpu, :unknown, nil, 'no total usage found in docker remote api stats'
|
108
|
+
return false
|
109
|
+
end
|
110
|
+
|
111
|
+
current_time = Time.parse(stats['read']);
|
112
|
+
if (@last_cpu_reads[id] != nil)
|
113
|
+
last = @last_cpu_reads[id]
|
114
|
+
used = (current - last[:v]) / (current_time - last[:t]) / @cpu_coefficient
|
115
|
+
|
116
|
+
report_pct name, :cpu, used
|
117
|
+
end
|
118
|
+
|
119
|
+
@last_cpu_reads[id] = { v: current, t: current_time }
|
120
|
+
end
|
121
|
+
|
122
|
+
def memory(id, name, stats)
|
123
|
+
memory_stats = stats['memory_stats']
|
124
|
+
usage = memory_stats['usage'].to_f
|
125
|
+
total = memory_stats['limit'].to_f
|
126
|
+
fraction = (usage / total)
|
127
|
+
|
128
|
+
report_pct name, :memory, fraction, "#{usage} / #{total}"
|
129
|
+
end
|
130
|
+
|
131
|
+
def disk
|
132
|
+
`df -P`.split(/\n/).each do |r|
|
133
|
+
f = r.split(/\s+/)
|
134
|
+
next if f[0] == 'Filesystem'
|
135
|
+
next unless f[0] =~ /\// # Needs at least one slash in the mount path
|
136
|
+
|
137
|
+
# Calculate capacity
|
138
|
+
x = f[4].to_f/100
|
139
|
+
report_pct(nil, :disk, x, "#{f[3].to_i / 1024} mb left", "disk #{f[5]}")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def basic_inspection(id, name, inspection)
|
144
|
+
|
145
|
+
state = inspection['State']
|
146
|
+
json_state = JSON.generate(state)
|
147
|
+
|
148
|
+
running = state['Running']
|
149
|
+
|
150
|
+
alert(name, "status",
|
151
|
+
running ? "ok" : "critical",
|
152
|
+
running ? 1 : 0,
|
153
|
+
json_state)
|
154
|
+
|
155
|
+
if (running)
|
156
|
+
start_time = DateTime.rfc3339(state['StartedAt']).to_time.utc.to_i
|
157
|
+
now = DateTime.now.to_time.utc.to_i
|
158
|
+
uptime = now - start_time
|
159
|
+
|
160
|
+
if (@last_uptime_reads[id] != nil)
|
161
|
+
last = @last_uptime_reads[id]
|
162
|
+
restarted = start_time != last
|
163
|
+
alert(name, "uptime",
|
164
|
+
restarted ? "critical" : "ok",
|
165
|
+
uptime,
|
166
|
+
"last 'StartedAt' measure was #{last} (#{Time.at(last).utc.to_s}), " +
|
167
|
+
"now it's #{start_time} (#{Time.at(start_time).utc.to_s})")
|
168
|
+
end
|
169
|
+
|
170
|
+
@last_uptime_reads[id] = start_time
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def tick
|
175
|
+
|
176
|
+
# Disk is the same in every container
|
177
|
+
if @disk_enabled
|
178
|
+
disk()
|
179
|
+
end
|
180
|
+
|
181
|
+
# Get CPU, Memory and Load of each container
|
182
|
+
containers = get_containers()
|
183
|
+
threads = []
|
184
|
+
|
185
|
+
containers.each do |ctr|
|
186
|
+
threads << Thread.new(ctr) do |container|
|
187
|
+
|
188
|
+
id = container.id
|
189
|
+
name = get_container_name(container)
|
190
|
+
|
191
|
+
stats = Docker::Util.parse_json(container.connection.get("/containers/#{id}/stats", {stream:false}))
|
192
|
+
|
193
|
+
if @basic_inspection_enabled
|
194
|
+
inspection = Docker::Util.parse_json(container.connection.get("/containers/#{id}/json"))
|
195
|
+
basic_inspection(id, name, inspection)
|
196
|
+
end
|
197
|
+
if @cpu_enabled
|
198
|
+
cpu(id, name, stats)
|
199
|
+
end
|
200
|
+
if @memory_enabled
|
201
|
+
memory(id, name, stats)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
threads.each do |thread|
|
207
|
+
begin
|
208
|
+
thread.join
|
209
|
+
rescue => e
|
210
|
+
$stderr.puts "#{e.class} #{e}\n#{e.backtrace.join "\n"}"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
Riemann::Tools::DockerHealth.run
|
217
|
+
|
@@ -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.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/package_task'
|
3
|
+
require 'rdoc/task'
|
4
|
+
require 'find'
|
5
|
+
|
6
|
+
# Don't include resource forks in tarballs on Mac OS X.
|
7
|
+
ENV['COPY_EXTENDED_ATTRIBUTES_DISABLE'] = 'true'
|
8
|
+
ENV['COPYFILE_DISABLE'] = 'true'
|
9
|
+
|
10
|
+
# Gemspec
|
11
|
+
gemspec = Gem::Specification.new do |s|
|
12
|
+
s.rubyforge_project = 'riemann-elasticsearch'
|
13
|
+
|
14
|
+
s.name = 'riemann-elasticsearch'
|
15
|
+
s.version = '0.2.4'
|
16
|
+
s.author = 'Gavin Sandie'
|
17
|
+
s.email = 'beach@vicecity.co.uk'
|
18
|
+
s.homepage = 'https://github.com/riemann/riemann-tools'
|
19
|
+
s.platform = Gem::Platform::RUBY
|
20
|
+
s.summary = 'Submits elasticsearch stats to riemann.'
|
21
|
+
s.license = 'MIT'
|
22
|
+
|
23
|
+
s.add_dependency 'riemann-tools', '>= 0.2.13'
|
24
|
+
s.add_dependency 'faraday', '>= 0.8.5'
|
25
|
+
s.add_dependency 'json'
|
26
|
+
|
27
|
+
s.files = FileList['bin/*', 'LICENSE', 'README.md'].to_a
|
28
|
+
s.executables |= Dir.entries('bin/')
|
29
|
+
s.has_rdoc = false
|
30
|
+
|
31
|
+
s.required_ruby_version = '>= 1.8.7'
|
32
|
+
end
|
33
|
+
|
34
|
+
Gem::PackageTask.new gemspec do |p|
|
35
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
Process.setproctitle($0)
|
3
|
+
|
4
|
+
require 'riemann/tools'
|
5
|
+
|
6
|
+
class Riemann::Tools::Elasticsearch
|
7
|
+
include Riemann::Tools
|
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, 'Elasticsearch path prefix for proxied installations e.g. "els" for target http://localhost/els/_cluster/health', default: "/"
|
15
|
+
opt :es_host, 'Elasticsearch host', default: "localhost"
|
16
|
+
opt :es_port, 'Elasticsearch port', type: :int, default: 9200
|
17
|
+
opt :es_search_index, 'Elasticsearch index to fetch search statistics for', default: "_all"
|
18
|
+
|
19
|
+
|
20
|
+
# Handles HTTP connections and GET requests safely
|
21
|
+
def safe_get(uri)
|
22
|
+
# Handle connection timeouts
|
23
|
+
response = nil
|
24
|
+
begin
|
25
|
+
connection = Faraday.new(uri)
|
26
|
+
response = connection.get do |req|
|
27
|
+
req.options[:timeout] = options[:read_timeout]
|
28
|
+
req.options[:open_timeout] = options[:open_timeout]
|
29
|
+
end
|
30
|
+
rescue => e
|
31
|
+
report(:host => uri.host,
|
32
|
+
:service => "elasticsearch health",
|
33
|
+
:state => "critical",
|
34
|
+
:description => "HTTP connection error: #{e.class} - #{e.message}"
|
35
|
+
)
|
36
|
+
end
|
37
|
+
response
|
38
|
+
end
|
39
|
+
|
40
|
+
def make_es_url(path)
|
41
|
+
path_prefix = options[:path_prefix]
|
42
|
+
path_prefix[0] = '' if path_prefix[0]=='/'
|
43
|
+
path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
|
44
|
+
"http://#{options[:es_host]}:#{options[:es_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/#{path}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def health_url
|
48
|
+
make_es_url("_cluster/health")
|
49
|
+
end
|
50
|
+
|
51
|
+
def indices_url
|
52
|
+
make_es_url("_stats/store")
|
53
|
+
end
|
54
|
+
|
55
|
+
def search_url
|
56
|
+
es_search_index = options[:es_search_index]
|
57
|
+
make_es_url("#{es_search_index}/_stats/search")
|
58
|
+
end
|
59
|
+
|
60
|
+
def is_bad?(response, uri)
|
61
|
+
if response.success?
|
62
|
+
false
|
63
|
+
else
|
64
|
+
report(:host => uri.host,
|
65
|
+
:service => "elasticsearch health",
|
66
|
+
:state => "critical",
|
67
|
+
:description => response.nil? ? "HTTP response is empty!" : "HTTP connection error: #{response.status} - #{response.body}"
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def tick_indices
|
73
|
+
uri = URI(indices_url)
|
74
|
+
response = safe_get(uri)
|
75
|
+
|
76
|
+
return if is_bad?(response, uri)
|
77
|
+
|
78
|
+
# Assuming that a 200 will give json
|
79
|
+
json = JSON.parse(response.body)
|
80
|
+
|
81
|
+
json["indices"].each_pair do |k,v|
|
82
|
+
report(:host => uri.host,
|
83
|
+
:service => "elasticsearch index/#{k}/primaries/size_in_bytes",
|
84
|
+
:metric => v["primaries"]["store"]["size_in_bytes"]
|
85
|
+
)
|
86
|
+
report(:host => uri.host,
|
87
|
+
:service => "elasticsearch index/#{k}/total/size_in_bytes",
|
88
|
+
:metric => v["total"]["store"]["size_in_bytes"]
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def tick_search
|
94
|
+
uri = URI(search_url)
|
95
|
+
response = safe_get(uri)
|
96
|
+
|
97
|
+
return if is_bad?(response, uri)
|
98
|
+
|
99
|
+
es_search_index = options[:es_search_index]
|
100
|
+
# Assuming that a 200 will give json
|
101
|
+
json = JSON.parse(response.body)
|
102
|
+
|
103
|
+
json["_all"].each_pair do |type, data|
|
104
|
+
query = data["search"]["query_time_in_millis"].to_f / data["search"]["query_total"].to_f
|
105
|
+
fetch = data["search"]["fetch_time_in_millis"].to_f / data["search"]["fetch_total"].to_f
|
106
|
+
|
107
|
+
report(:host => uri.host,
|
108
|
+
:service => "elasticsearch search/#{es_search_index}/query",
|
109
|
+
:metric => query
|
110
|
+
)
|
111
|
+
report(:host => uri.host,
|
112
|
+
:service => "elasticsearch search/#{es_search_index}/fetch",
|
113
|
+
:metric => fetch
|
114
|
+
)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def tick
|
119
|
+
begin
|
120
|
+
tick_indices
|
121
|
+
tick_search
|
122
|
+
rescue Exception => e
|
123
|
+
report(:host => options[:es_host],
|
124
|
+
:service => "elasticsearch error",
|
125
|
+
:state => "critical",
|
126
|
+
:description => "Elasticsearch cluster error: #{e.message}")
|
127
|
+
end
|
128
|
+
uri = URI(health_url)
|
129
|
+
response = safe_get(uri)
|
130
|
+
|
131
|
+
return if is_bad?(response, uri)
|
132
|
+
|
133
|
+
# Assuming that a 200 will give json
|
134
|
+
json = JSON.parse(response.body)
|
135
|
+
cluster_name = json.delete("cluster_name")
|
136
|
+
cluster_status = json.delete("status")
|
137
|
+
state = case cluster_status
|
138
|
+
when "green"
|
139
|
+
"ok"
|
140
|
+
when "yellow"
|
141
|
+
"warning"
|
142
|
+
when "red"
|
143
|
+
"critical"
|
144
|
+
end
|
145
|
+
|
146
|
+
report(:host => uri.host,
|
147
|
+
:service => "elasticsearch health",
|
148
|
+
:state => state,
|
149
|
+
:description => "Elasticsearch cluster: #{cluster_name} - #{cluster_status}")
|
150
|
+
|
151
|
+
json.each_pair do |k,v|
|
152
|
+
report(:host => uri.host,
|
153
|
+
:service => "elasticsearch #{k}",
|
154
|
+
:metric => v,
|
155
|
+
:description => "Elasticsearch cluster #{k}"
|
156
|
+
)
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
end
|
165
|
+
Riemann::Tools::Elasticsearch.run
|
166
|
+
|
@@ -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.
|