check_graphite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in check_graphite.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ check_graphite is a nagios module to query graphite
2
+
3
+ ## Example
4
+
5
+ check_graphite -H 'http://my.graphite.host
6
+
7
+ check_graphite -H "http://your.graphite.host/render" -M collectd.somebox.load.load.midterm -w 1 -c 2 -N load
8
+ WARNING|load=1.4400000000000002;;;;
9
+
10
+ check_graphite accepts the following options:
11
+
12
+ * `-H` or `--endpoint`: the graphite HTTP endpoint which can be queried
13
+ * `-M' or `--metric`: the metric expression which will be queried, it can be an expression
14
+ * `-F` or `--from`: time frame for which to query metrics, defaults to "30seconds"
15
+ * `-N` or `--name`: name to give to the metric, defaults to "value"
16
+ * `-w`: warning threshold for the metric
17
+ * `-c`: critical threshold for the metric
18
+ * `-t`: timeout after which the metric should be considered unknown
19
+
20
+ ## How it works
21
+
22
+ check_graphite, asks for a small window of metrics, and computes an average over the last valid
23
+ points collected, it then checks the value against supplied thresholds.
24
+
25
+ NaN values are not taken into account in the average
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'check_graphite'
4
+ CheckGraphite::Command.new.run
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "check_graphite/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "check_graphite"
7
+ s.version = CheckGraphite::VERSION
8
+ s.authors = ["Pierre-Yves Ritschard"]
9
+ s.email = ["pyr@spootnik.org"]
10
+ s.homepage = "https://github.com/pyr/check-graphite"
11
+ s.summary = %q{check_graphite}
12
+ s.description = %q{check values from a graphite server}
13
+
14
+ s.rubyforge_project = "check_graphite"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "nagios_check"
24
+ s.add_runtime_dependency "http"
25
+ end
@@ -0,0 +1,3 @@
1
+ module CheckGraphite
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ require "nagios_check"
2
+ require "json"
3
+ require "http"
4
+ require "check_graphite/version"
5
+
6
+ module CheckGraphite
7
+
8
+ class Command
9
+ include NagiosCheck
10
+
11
+ on "--endpoint ENDPOINT", "-H ENDPOINT", :mandatory
12
+ on "--metric METRIC", "-M METRIC", :mandatory
13
+ on "--from TIMEFRAME", "-F TIMEFRAME", :default => "30seconds"
14
+ on "--name NAME", "-N NAME", :default => :value
15
+
16
+ enable_warning
17
+ enable_critical
18
+ enable_timeout
19
+
20
+ def check
21
+ data = Http.get "#{options.endpoint}?target=#{options.metric}&from=-#{options.from}&format=json"
22
+ raise "no such metric registered" unless data.length > 0
23
+ res = data.first["datapoints"].reduce({:sum => 0.0, :count => 0}) {|acc, e|
24
+ if e[0]
25
+ {:sum => acc[:sum] + e[0], :count => acc[:count] + 1}
26
+ else
27
+ acc
28
+ end
29
+ }
30
+ raise "no valid datapoints" if res[:count] == 0
31
+ store_value options.name, (res[:sum] / res[:count])
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_graphite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pierre-Yves Ritschard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nagios_check
16
+ requirement: &70361640493220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70361640493220
25
+ - !ruby/object:Gem::Dependency
26
+ name: http
27
+ requirement: &70361640492800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70361640492800
36
+ description: check values from a graphite server
37
+ email:
38
+ - pyr@spootnik.org
39
+ executables:
40
+ - check_graphite
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - bin/check_graphite
49
+ - check_graphite.gemspec
50
+ - lib/check_graphite.rb
51
+ - lib/check_graphite/version.rb
52
+ homepage: https://github.com/pyr/check-graphite
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project: check_graphite
72
+ rubygems_version: 1.8.15
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: check_graphite
76
+ test_files: []