riemann-tools 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 210cb204200a12c61ba5387331a58d573a4cf004
4
+ data.tar.gz: a06f02966d09ba2009d19331da18c91f4e237f2f
5
+ SHA512:
6
+ metadata.gz: c61c8d015c9a1a494ab7e2311cd80d5a774eb1c089f5a2ca891b797aa7c2a4021fe4523f365c97256bfdbae3e6e781f5cafde649271e61fac90eb12b752650bf
7
+ data.tar.gz: 70a6995d1ce99d458b009ec94e28f4b417bfa14f24eeb2862b1073abb48100ec3f0799c70466b99347e6639d6d656367648ac3ff450d5b77558757d38f31db53
data/README.markdown CHANGED
@@ -4,15 +4,73 @@ Riemann Tools
4
4
  Tiny programs to submit events to Riemann.
5
5
 
6
6
  Riemann-health, for example, submits events about the current CPU, load,
7
- memory, and disk use. Bench submits randomly distributed metrics for load
8
- testing. I've got a whole bunch of these internally for monitoring Redis, Riak,
9
- queues, etc. Most have internal configuration dependencies, so it'll be a while
10
- before I can extract them for re-use.
7
+ memory, and disk use. Also available is `riemann-bench`, which submits
8
+ randomly distributed metrics for load testing.
11
9
 
12
10
  Get started
13
- ==========
11
+ ===========
14
12
 
15
13
  ``` bash
16
14
  gem install riemann-tools
17
15
  riemann-health --host my.riemann.server
18
16
  ```
17
+ Riemann-tools programs
18
+ ======================
19
+
20
+ This repository contains a number of different programs. Some of them
21
+ ship with the `riemann-tools` gem, including:
22
+
23
+ * riemann-apache-status - Apache monitoring.
24
+ * riemann-dir-files-count - File counts.
25
+ * riemann-freeswitch - FreeSwitch monitoring.
26
+ * riemann-memcached - Monitor Memcache.
27
+ * riemann-proc - Linux process monitoring.
28
+ * riemann-bench - Load testing for Riemann.
29
+ * riemann-dir-space - Directory space monitoring.
30
+ * riemann-haproxy - Monitor HAProxy.
31
+ * riemann-net - Network interface monitoring.
32
+ * riemann-varnish - Monitor Varnish.
33
+ * riemann-cloudant - Cloudant monitoring.
34
+ * riemann-diskstats - Disk statistics.
35
+ * riemann-health - General CPU, memory, disk and load monitoring.
36
+ * riemann-nginx-status - Monitor Nginx.
37
+ * riemann-zookeeper - Monitor Zookeeper.
38
+ * riemann-consul - Monitor Consul.
39
+ * riemann-fd - Linux file descriptor use.
40
+ * riemann-kvminstance - Monitor KVM instances.
41
+ * riemann-ntp - Monitor NTP
42
+
43
+ Also contained in the repository are a number of stand-alone monitoring
44
+ tools, which are shipped as separate gems.
45
+
46
+ Riemann stand-alone tools
47
+ =========================
48
+
49
+ Use these tools by installing their individual gems, usually named for
50
+ the specific tool, for example:
51
+
52
+ ```bash
53
+ gem install riemann-aws
54
+ ```
55
+
56
+ To install the AWS tools.
57
+
58
+ * riemann-aws - Monitor various AWS services.
59
+ * riemann-elasticsearch - Monitor Elasticsearch.
60
+ * riemann-mesos - Monitor Mesos.
61
+ * riemann-rabbitmq - Monitor RabbitMQ.
62
+ * riemann-docker - Monitor Docker.
63
+ * riemann-marathon - Monitor Marathon.
64
+ * riemann-munin - Monitor Munin.
65
+ * riemann-riak - Monitor Riak.
66
+
67
+ There are also a number of additional, stand-alone tools, contained in
68
+ the [Riemann GitHub account](https://github.com/riemann/).
69
+
70
+ License
71
+ =======
72
+
73
+ The MIT License
74
+
75
+ Copyright (c) 2011-2016 Kyle Kingsbury
76
+
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Reports service and node status to riemann
4
+
5
+ require File.expand_path('../../lib/riemann/tools', __FILE__)
6
+ require 'socket'
7
+ require 'net/http'
8
+ require 'uri'
9
+ require 'json'
10
+
11
+ class Riemann::Tools::ConsulHealth
12
+ include Riemann::Tools
13
+
14
+ opt :consul_host, "Consul API Host (default to localhost)", :default => "localhost"
15
+ opt :consul_port, "Consul API Host (default to 8500)", :default => "8500"
16
+ opt :prefix, "prefix to use for all service names when reporting", :default => "consul "
17
+ opt :minimum_services_per_node, "minimum services per node (default: 0)", :default => 0
18
+
19
+ def initialize
20
+
21
+ @hostname = opts[:consul_host]
22
+ @prefix = opts[:prefix]
23
+ @minimum_services_per_node = opts[:minimum_services_per_node]
24
+ @underlying_ip = IPSocket.getaddress(@hostname)
25
+ @consul_leader_url = URI.parse("http://" + opts[:consul_host] + ":" + opts[:consul_port] + "/v1/status/leader")
26
+ @consul_services_url = URI.parse("http://" + opts[:consul_host] + ":" + opts[:consul_port] + "/v1/catalog/services")
27
+ @consul_nodes_url = URI.parse("http://" + opts[:consul_host] + ":" + opts[:consul_port] + "/v1/catalog/nodes")
28
+ @consul_health_url_prefix = "http://" + opts[:consul_host] + ":" + opts[:consul_port] + "/v1/health/service/"
29
+
30
+ @last_services_read = Hash.new
31
+
32
+ end
33
+
34
+ def alert(hostname, service, state, metric, description)
35
+
36
+ opts = { :host => hostname,
37
+ :service => service.to_s,
38
+ :state => state.to_s,
39
+ :metric => metric,
40
+ :description => description }
41
+
42
+ report(opts)
43
+ end
44
+
45
+ def get(url)
46
+ Net::HTTP.get_response(url).body
47
+ end
48
+
49
+ def tick
50
+
51
+ leader = get(@consul_leader_url)
52
+ leader_hostname = URI.parse("http://" + leader[1..-2]).hostname
53
+
54
+ if (leader_hostname == @underlying_ip)
55
+ nodes = JSON.parse(get(@consul_nodes_url))
56
+ services = JSON.parse(get(@consul_services_url))
57
+ services_by_nodes = Hash.new
58
+
59
+ for node in nodes
60
+ node_name = node["Node"]
61
+ services_by_nodes[node_name] = 0
62
+ end
63
+
64
+
65
+ # For every service
66
+ for service in services
67
+ service_name = service[0]
68
+ health_url = URI.parse(@consul_health_url_prefix + service_name)
69
+ health_nodes = JSON.parse(get(health_url))
70
+
71
+ totalCount = 0
72
+ okCount = 0
73
+
74
+ for node in health_nodes
75
+ hostname = node["Node"]["Node"]
76
+ ok = node["Checks"].all? {|check| check["Status"] == "passing"}
77
+ alert(hostname, "#{@prefix}#{service_name}", ok ? :ok : :critical, ok ? 1 : 0, JSON.generate(node))
78
+ totalCount += 1
79
+ okCount += ok ? 1 : 0
80
+
81
+ last_services_by_nodes = services_by_nodes[hostname].to_i
82
+ services_by_nodes[hostname] = last_services_by_nodes + 1
83
+ end
84
+
85
+ if (@last_services_read[service_name] != nil)
86
+ lastOk = @last_services_read[service_name]
87
+ if (lastOk != okCount)
88
+ alert("total", "#{@prefix}#{service_name}-count", okCount >= lastOk ? :ok : :critical, okCount, "Number of passing #{service_name} is: #{okCount}/#{totalCount}, Last time it was: #{lastOk}")
89
+ end
90
+ end
91
+
92
+ @last_services_read[service_name] = okCount
93
+
94
+ end
95
+
96
+ # For every node
97
+ for node,count in services_by_nodes
98
+ alert(node, "#{@prefix}total-services", (count >= @minimum_services_per_node) ? :ok : :critical, count, "#{count} services in the specified node")
99
+ end
100
+
101
+ end
102
+
103
+ end
104
+ end
105
+
106
+ Riemann::Tools::ConsulHealth.run
data/bin/riemann-haproxy CHANGED
@@ -26,11 +26,17 @@ class Riemann::Tools::Haproxy
26
26
  :host => @uri.host,
27
27
  :service => "#{ns} #{property}",
28
28
  :metric => metric.to_f,
29
- :state => (['UP', 'OPEN'].include?(row['status']) ? 'ok' : 'critical'),
30
29
  :tags => ['haproxy']
31
30
  )
32
31
  end
33
32
  end
33
+
34
+ report(
35
+ :host => @uri.host,
36
+ :service => "#{ns} state",
37
+ :state => (['UP', 'OPEN'].include?(row['status']) ? 'ok' : 'critical'),
38
+ :tags => ['haproxy']
39
+ )
34
40
  end
35
41
  end
36
42
 
data/bin/riemann-health CHANGED
@@ -27,6 +27,7 @@ class Riemann::Tools::Health
27
27
  case (ostype = `uname -s`.chomp.downcase)
28
28
  when 'darwin'
29
29
  @cores = `sysctl -n hw.ncpu`.to_i
30
+ @df = `df -P -t noiso9660`
30
31
  @cpu = method :darwin_cpu
31
32
  @disk = method :disk
32
33
  @load = method :darwin_load
@@ -34,12 +35,14 @@ class Riemann::Tools::Health
34
35
  darwin_top
35
36
  when 'freebsd'
36
37
  @cores = `sysctl -n hw.ncpu`.to_i
38
+ @df = `df -P -t noiso9660`
37
39
  @cpu = method :freebsd_cpu
38
40
  @disk = method :disk
39
41
  @load = method :freebsd_load
40
42
  @memory = method :freebsd_memory
41
43
  else
42
44
  @cores = cores
45
+ @df = `df -P --exclude-type=iso9660`
43
46
  puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == "linux"
44
47
  @cpu = method :linux_cpu
45
48
  @disk = method :disk
@@ -243,7 +246,7 @@ class Riemann::Tools::Health
243
246
  end
244
247
 
245
248
  def disk
246
- `df -P`.split(/\n/).each do |r|
249
+ @df.split(/\n/).each do |r|
247
250
  f = r.split(/\s+/)
248
251
  next if f[0] == 'Filesystem'
249
252
  next unless f[0] =~ /\// # Needs at least one slash in the mount path
data/bin/riemann-net CHANGED
@@ -6,7 +6,7 @@ require File.expand_path('../../lib/riemann/tools', __FILE__)
6
6
 
7
7
  class Riemann::Tools::Net
8
8
  include Riemann::Tools
9
-
9
+
10
10
  opt :interfaces, "Interfaces to monitor", :type => :strings, :default => nil
11
11
  opt :ignore_interfaces, "Interfaces to ignore", :type => :strings, :default =>['lo']
12
12
 
data/lib/riemann/tools.rb CHANGED
@@ -55,7 +55,7 @@ module Riemann
55
55
  def report(event)
56
56
  if options[:tag]
57
57
  # Work around a bug with beefcake which can't take frozen strings.
58
- event[:tags] = options[:tag].map(&:dup)
58
+ event[:tags] = [*event.fetch(:tags, [])] + options[:tag].map(&:dup)
59
59
  end
60
60
 
61
61
  event[:ttl] ||= (options[:ttl] || (options[:interval] * 2))
@@ -63,7 +63,7 @@ module Riemann
63
63
  if options[:event_host]
64
64
  event[:host] = options[:event_host].dup
65
65
  end
66
-
66
+
67
67
  event = event.merge(attributes)
68
68
 
69
69
  riemann << event
metadata CHANGED
@@ -1,218 +1,126 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
5
- prerelease:
4
+ version: 0.2.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kyle Kingsbury
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-07-17 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: riemann-client
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.2.2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.2.2
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: trollop
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 1.16.2
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 1.16.2
46
41
  - !ruby/object:Gem::Dependency
47
- name: munin-ruby
42
+ name: json
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: 0.2.1
47
+ version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
- version: 0.2.1
62
- - !ruby/object:Gem::Dependency
63
- name: yajl-ruby
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: 1.1.0
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: 1.1.0
78
- - !ruby/object:Gem::Dependency
79
- name: fog
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: 1.4.0
86
- type: :runtime
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: 1.4.0
94
- - !ruby/object:Gem::Dependency
95
- name: faraday
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: 0.8.5
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: 0.8.5
110
- - !ruby/object:Gem::Dependency
111
- name: nokogiri
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: 1.5.6
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: 1.5.6
54
+ version: '0'
126
55
  description: Utilities which submit events to Riemann.
127
56
  email: aphyr@aphyr.com
128
57
  executables:
129
- - riemann-aws-status
130
- - riemann-munin
131
- - riemann-dir-space
132
- - riemann-zookeeper
133
- - riemann-resmon
58
+ - riemann-apache-status
134
59
  - riemann-bench
135
- - riemann-aws-rds-status
136
- - riemann-proc
137
- - riemann-freeswitch
138
- - riemann-aws-billing
139
- - riemann-elb-metrics
140
- - riemann-riak
141
- - riemann-health
60
+ - riemann-cloudant
61
+ - riemann-consul
142
62
  - riemann-dir-files-count
143
- - riemann-varnish
144
- - riemann-memcached
145
- - riemann-haproxy
146
- - riemann-elasticsearch
147
- - riemann-riak-keys
63
+ - riemann-dir-space
148
64
  - riemann-diskstats
149
65
  - riemann-fd
150
- - riemann-riak-ring
151
- - riemann-cloudant
152
- - riemann-nginx-status
153
- - riemann-rabbitmq
154
- - riemann-ntp
66
+ - riemann-freeswitch
67
+ - riemann-haproxy
68
+ - riemann-health
155
69
  - riemann-kvminstance
70
+ - riemann-memcached
156
71
  - riemann-net
157
- - riemann-apache-status
72
+ - riemann-nginx-status
73
+ - riemann-ntp
74
+ - riemann-proc
75
+ - riemann-varnish
76
+ - riemann-zookeeper
158
77
  extensions: []
159
78
  extra_rdoc_files: []
160
79
  files:
161
- - lib/riemann/tools.rb
80
+ - LICENSE
81
+ - README.markdown
162
82
  - bin/riemann-apache-status
163
- - bin/riemann-aws-billing
164
- - bin/riemann-aws-rds-status
165
- - bin/riemann-aws-status
166
83
  - bin/riemann-bench
167
84
  - bin/riemann-cloudant
85
+ - bin/riemann-consul
168
86
  - bin/riemann-dir-files-count
169
87
  - bin/riemann-dir-space
170
88
  - bin/riemann-diskstats
171
- - bin/riemann-elasticsearch
172
- - bin/riemann-elb-metrics
173
89
  - bin/riemann-fd
174
90
  - bin/riemann-freeswitch
175
91
  - bin/riemann-haproxy
176
92
  - bin/riemann-health
177
93
  - bin/riemann-kvminstance
178
94
  - bin/riemann-memcached
179
- - bin/riemann-munin
180
95
  - bin/riemann-net
181
96
  - bin/riemann-nginx-status
182
97
  - bin/riemann-ntp
183
98
  - bin/riemann-proc
184
- - bin/riemann-rabbitmq
185
- - bin/riemann-resmon
186
- - bin/riemann-riak
187
- - bin/riemann-riak-keys
188
- - bin/riemann-riak-ring
189
99
  - bin/riemann-varnish
190
100
  - bin/riemann-zookeeper
191
- - LICENSE
192
- - README.markdown
101
+ - lib/riemann/tools.rb
193
102
  homepage: https://github.com/aphyr/riemann-tools
194
103
  licenses:
195
104
  - MIT
105
+ metadata: {}
196
106
  post_install_message:
197
107
  rdoc_options: []
198
108
  require_paths:
199
109
  - lib
200
110
  required_ruby_version: !ruby/object:Gem::Requirement
201
- none: false
202
111
  requirements:
203
- - - ! '>='
112
+ - - ">="
204
113
  - !ruby/object:Gem::Version
205
114
  version: 1.8.7
206
115
  required_rubygems_version: !ruby/object:Gem::Requirement
207
- none: false
208
116
  requirements:
209
- - - ! '>='
117
+ - - ">="
210
118
  - !ruby/object:Gem::Version
211
119
  version: '0'
212
120
  requirements: []
213
121
  rubyforge_project: riemann-tools
214
- rubygems_version: 1.8.25
122
+ rubygems_version: 2.4.5
215
123
  signing_key:
216
- specification_version: 3
124
+ specification_version: 4
217
125
  summary: Utilities which submit events to Riemann.
218
126
  test_files: []