riemann-tools 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +8 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +55 -2
  7. data/Rakefile +17 -3
  8. data/bin/riemann-apache-status +1 -106
  9. data/bin/riemann-bench +2 -70
  10. data/bin/riemann-cloudant +1 -56
  11. data/bin/riemann-consul +1 -106
  12. data/bin/riemann-dir-files-count +1 -55
  13. data/bin/riemann-dir-space +1 -55
  14. data/bin/riemann-diskstats +1 -92
  15. data/bin/riemann-fd +2 -81
  16. data/bin/riemann-freeswitch +2 -119
  17. data/bin/riemann-haproxy +1 -58
  18. data/bin/riemann-health +0 -2
  19. data/bin/riemann-kvminstance +2 -22
  20. data/bin/riemann-md +8 -0
  21. data/bin/riemann-memcached +1 -37
  22. data/bin/riemann-net +0 -2
  23. data/bin/riemann-nginx-status +1 -85
  24. data/bin/riemann-ntp +0 -2
  25. data/bin/riemann-portcheck +1 -44
  26. data/bin/riemann-proc +1 -108
  27. data/bin/riemann-varnish +1 -54
  28. data/bin/riemann-wrapper +113 -0
  29. data/bin/riemann-zookeeper +1 -39
  30. data/bin/riemann-zpool +8 -0
  31. data/lib/riemann/tools/apache_status.rb +107 -0
  32. data/lib/riemann/tools/bench.rb +72 -0
  33. data/lib/riemann/tools/cloudant.rb +57 -0
  34. data/lib/riemann/tools/consul_health.rb +107 -0
  35. data/lib/riemann/tools/dir_files_count.rb +56 -0
  36. data/lib/riemann/tools/dir_space.rb +56 -0
  37. data/lib/riemann/tools/diskstats.rb +94 -0
  38. data/lib/riemann/tools/fd.rb +81 -0
  39. data/lib/riemann/tools/freeswitch.rb +119 -0
  40. data/lib/riemann/tools/haproxy.rb +59 -0
  41. data/lib/riemann/tools/health.rb +150 -19
  42. data/lib/riemann/tools/kvm.rb +23 -0
  43. data/lib/riemann/tools/md.rb +35 -0
  44. data/lib/riemann/tools/mdstat_parser.tab.rb +340 -0
  45. data/lib/riemann/tools/memcached.rb +38 -0
  46. data/lib/riemann/tools/net.rb +2 -1
  47. data/lib/riemann/tools/nginx_status.rb +86 -0
  48. data/lib/riemann/tools/ntp.rb +1 -0
  49. data/lib/riemann/tools/portcheck.rb +45 -0
  50. data/lib/riemann/tools/proc.rb +109 -0
  51. data/lib/riemann/tools/riemann_client_wrapper.rb +43 -0
  52. data/lib/riemann/tools/uptime_parser.tab.rb +323 -0
  53. data/lib/riemann/tools/varnish.rb +55 -0
  54. data/lib/riemann/tools/version.rb +1 -1
  55. data/lib/riemann/tools/zookeeper.rb +40 -0
  56. data/lib/riemann/tools/zpool.rb +29 -0
  57. data/lib/riemann/tools.rb +2 -20
  58. data/riemann-tools.gemspec +10 -1
  59. data/tools/riemann-aws/Rakefile +6 -9
  60. data/tools/riemann-aws/bin/riemann-aws-billing +2 -87
  61. data/tools/riemann-aws/bin/riemann-aws-rds-status +2 -62
  62. data/tools/riemann-aws/bin/riemann-aws-sqs-status +2 -44
  63. data/tools/riemann-aws/bin/riemann-aws-status +2 -77
  64. data/tools/riemann-aws/bin/riemann-elb-metrics +2 -162
  65. data/tools/riemann-aws/bin/riemann-s3-list +2 -81
  66. data/tools/riemann-aws/bin/riemann-s3-status +2 -96
  67. data/tools/riemann-aws/lib/riemann/tools/aws/billing.rb +87 -0
  68. data/tools/riemann-aws/lib/riemann/tools/aws/elb_metrics.rb +163 -0
  69. data/tools/riemann-aws/lib/riemann/tools/aws/rds_status.rb +63 -0
  70. data/tools/riemann-aws/lib/riemann/tools/aws/s3_list.rb +82 -0
  71. data/tools/riemann-aws/lib/riemann/tools/aws/s3_status.rb +97 -0
  72. data/tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb +45 -0
  73. data/tools/riemann-aws/lib/riemann/tools/aws/status.rb +74 -0
  74. data/tools/riemann-chronos/Rakefile +6 -9
  75. data/tools/riemann-chronos/bin/riemann-chronos +1 -154
  76. data/tools/riemann-chronos/lib/riemann/tools/chronos.rb +157 -0
  77. data/tools/riemann-docker/Rakefile +5 -8
  78. data/tools/riemann-docker/bin/riemann-docker +2 -200
  79. data/tools/riemann-docker/lib/riemann/tools/docker.rb +200 -0
  80. data/tools/riemann-elasticsearch/Rakefile +6 -9
  81. data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +1 -167
  82. data/tools/riemann-elasticsearch/lib/riemann/tools/elasticsearch.rb +170 -0
  83. data/tools/riemann-marathon/Rakefile +6 -9
  84. data/tools/riemann-marathon/bin/riemann-marathon +1 -156
  85. data/tools/riemann-marathon/lib/riemann/tools/marathon.rb +159 -0
  86. data/tools/riemann-mesos/Rakefile +6 -9
  87. data/tools/riemann-mesos/bin/riemann-mesos +1 -139
  88. data/tools/riemann-mesos/lib/riemann/tools/mesos.rb +142 -0
  89. data/tools/riemann-munin/Rakefile +5 -8
  90. data/tools/riemann-munin/bin/riemann-munin +1 -36
  91. data/tools/riemann-munin/lib/riemann/tools/munin.rb +37 -0
  92. data/tools/riemann-rabbitmq/Rakefile +6 -9
  93. data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +1 -266
  94. data/tools/riemann-rabbitmq/lib/riemann/tools/rabbitmq.rb +269 -0
  95. data/tools/riemann-riak/Rakefile +5 -8
  96. data/tools/riemann-riak/bin/riemann-riak +1 -316
  97. data/tools/riemann-riak/bin/riemann-riak-keys +0 -1
  98. data/tools/riemann-riak/bin/riemann-riak-ring +0 -1
  99. data/tools/riemann-riak/lib/riemann/tools/riak.rb +317 -0
  100. metadata +61 -7
  101. data/.travis.yml +0 -31
  102. data/tools/riemann-riak/riak_status/key_count.erl +0 -13
  103. data/tools/riemann-riak/riak_status/riak_status.rb +0 -152
  104. data/tools/riemann-riak/riak_status/ringready.erl +0 -9
@@ -0,0 +1,170 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'riemann/tools'
4
+
5
+ module Riemann
6
+ module Tools
7
+ class Elasticsearch
8
+ include Riemann::Tools
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,
16
+ 'Elasticsearch path prefix for proxied installations e.g. "els" for target http://localhost/els/_cluster/health', default: '/'.dup
17
+ opt :es_host, 'Elasticsearch host', default: 'localhost'
18
+ opt :es_port, 'Elasticsearch port', type: :int, default: 9200
19
+ opt :es_search_index, 'Elasticsearch index to fetch search statistics for', default: '_all'
20
+
21
+ # Handles HTTP connections and GET requests safely
22
+ def safe_get(uri)
23
+ # Handle connection timeouts
24
+ response = nil
25
+ begin
26
+ connection = Faraday.new(uri)
27
+ response = connection.get do |req|
28
+ req.options[:timeout] = options[:read_timeout]
29
+ req.options[:open_timeout] = options[:open_timeout]
30
+ end
31
+ rescue StandardError => e
32
+ report(
33
+ host: uri.host,
34
+ service: 'elasticsearch health',
35
+ state: 'critical',
36
+ description: "HTTP connection error: #{e.class} - #{e.message}",
37
+ )
38
+ end
39
+ response
40
+ end
41
+
42
+ def make_es_url(path)
43
+ path_prefix = options[:path_prefix]
44
+ path_prefix[0] = '' if path_prefix[0] == '/'
45
+ path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
46
+ "http://#{options[:es_host]}:#{options[:es_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/#{path}"
47
+ end
48
+
49
+ def health_url
50
+ make_es_url('_cluster/health')
51
+ end
52
+
53
+ def indices_url
54
+ make_es_url('_stats/store')
55
+ end
56
+
57
+ def search_url
58
+ es_search_index = options[:es_search_index]
59
+ make_es_url("#{es_search_index}/_stats/search")
60
+ end
61
+
62
+ def bad?(response, uri)
63
+ if response.success?
64
+ false
65
+ else
66
+ report(
67
+ host: uri.host,
68
+ service: 'elasticsearch health',
69
+ state: 'critical',
70
+ description: response.nil? ? 'HTTP response is empty!' : "HTTP connection error: #{response.status} - #{response.body}",
71
+ )
72
+ end
73
+ end
74
+
75
+ def tick_indices
76
+ uri = URI(indices_url)
77
+ response = safe_get(uri)
78
+
79
+ return if bad?(response, uri)
80
+
81
+ # Assuming that a 200 will give json
82
+ json = JSON.parse(response.body)
83
+
84
+ json['indices'].each_pair do |k, v|
85
+ report(
86
+ host: uri.host,
87
+ service: "elasticsearch index/#{k}/primaries/size_in_bytes",
88
+ metric: v['primaries']['store']['size_in_bytes'],
89
+ )
90
+ report(
91
+ host: uri.host,
92
+ service: "elasticsearch index/#{k}/total/size_in_bytes",
93
+ metric: v['total']['store']['size_in_bytes'],
94
+ )
95
+ end
96
+ end
97
+
98
+ def tick_search
99
+ uri = URI(search_url)
100
+ response = safe_get(uri)
101
+
102
+ return if bad?(response, uri)
103
+
104
+ es_search_index = options[:es_search_index]
105
+ # Assuming that a 200 will give json
106
+ json = JSON.parse(response.body)
107
+
108
+ json['_all'].each_pair do |_type, data|
109
+ query = data['search']['query_time_in_millis'].to_f / data['search']['query_total']
110
+ fetch = data['search']['fetch_time_in_millis'].to_f / data['search']['fetch_total']
111
+
112
+ report(
113
+ host: uri.host,
114
+ service: "elasticsearch search/#{es_search_index}/query",
115
+ metric: query,
116
+ )
117
+ report(
118
+ host: uri.host,
119
+ service: "elasticsearch search/#{es_search_index}/fetch",
120
+ metric: fetch,
121
+ )
122
+ end
123
+ end
124
+
125
+ def tick
126
+ begin
127
+ tick_indices
128
+ tick_search
129
+ rescue StandardError => e
130
+ report(
131
+ host: options[:es_host],
132
+ service: 'elasticsearch error',
133
+ state: 'critical',
134
+ description: "Elasticsearch cluster error: #{e.message}",
135
+ )
136
+ end
137
+ uri = URI(health_url)
138
+ response = safe_get(uri)
139
+
140
+ return if bad?(response, uri)
141
+
142
+ # Assuming that a 200 will give json
143
+ json = JSON.parse(response.body)
144
+ cluster_name = json.delete('cluster_name')
145
+ cluster_status = json.delete('status')
146
+ state = {
147
+ 'green' => 'ok',
148
+ 'yellow' => 'warning',
149
+ 'red' => 'critical',
150
+ }[cluster_status]
151
+
152
+ report(
153
+ host: uri.host,
154
+ service: 'elasticsearch health',
155
+ state: state,
156
+ description: "Elasticsearch cluster: #{cluster_name} - #{cluster_status}",
157
+ )
158
+
159
+ json.each_pair do |k, v|
160
+ report(
161
+ host: uri.host,
162
+ service: "elasticsearch #{k}",
163
+ metric: v,
164
+ description: "Elasticsearch cluster #{k}",
165
+ )
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
@@ -11,10 +11,8 @@ ENV['COPYFILE_DISABLE'] = 'true'
11
11
 
12
12
  # Gemspec
13
13
  gemspec = Gem::Specification.new do |s|
14
- s.rubyforge_project = 'riemann-marathon'
15
-
16
14
  s.name = 'riemann-marathon'
17
- s.version = '0.1.3'
15
+ s.version = '0.1.5'
18
16
  s.author = 'Giulio Eulisse'
19
17
  s.email = 'giulio.eulisse@cern.ch'
20
18
  s.homepage = 'https://github.com/riemann/riemann-tools'
@@ -22,15 +20,14 @@ gemspec = Gem::Specification.new do |s|
22
20
  s.summary = 'Submits Marathon stats to riemann.'
23
21
  s.license = 'MIT'
24
22
 
25
- s.add_dependency 'riemann-tools', '>= 0.2.13'
26
- s.add_dependency 'faraday', '>= 0.8.5'
27
- s.add_dependency 'json'
23
+ s.add_runtime_dependency 'riemann-tools', '~> 1.0', '>= 1.1.1'
24
+ s.add_runtime_dependency 'faraday', '~> 2.3', '>= 2.3.0'
25
+ s.add_runtime_dependency 'json', '~> 2.6', '>=2.6.2'
28
26
 
29
- s.files = FileList['bin/*', 'LICENSE', 'README.md'].to_a
27
+ s.files = FileList['bin/*', 'lib/**/*.rb', 'LICENSE', 'README.md'].to_a
30
28
  s.executables |= Dir.entries('bin/')
31
- s.has_rdoc = false
32
29
 
33
- s.required_ruby_version = '>= 1.8.7'
30
+ s.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
34
31
  end
35
32
 
36
33
  Gem::PackageTask.new gemspec do |p|
@@ -3,161 +3,6 @@
3
3
 
4
4
  Process.setproctitle($PROGRAM_NAME)
5
5
 
6
- require 'riemann/tools'
6
+ require 'riemann/tools/marathon'
7
7
 
8
- module Riemann
9
- module Tools
10
- class Marathon
11
- include Riemann::Tools
12
-
13
- require 'faraday'
14
- require 'json'
15
- require 'uri'
16
-
17
- opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
18
- opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
19
- opt :path_prefix,
20
- 'Marathon path prefix for proxied installations e.g. "marathon" for target http://localhost/marathon/metrics', default: '/'
21
- opt :marathon_host, 'Marathon host', default: 'localhost'
22
- opt :marathon_port, 'Marathon port', type: :int, default: 8080
23
-
24
- def initialize
25
- options[:interval] = 60
26
- options[:ttl] = 120
27
- end
28
-
29
- # Handles HTTP connections and GET requests safely
30
- def safe_get(uri)
31
- # Handle connection timeouts
32
- response = nil
33
- begin
34
- connection = Faraday.new(uri)
35
- response = connection.get do |req|
36
- req.options[:timeout] = options[:read_timeout]
37
- req.options[:open_timeout] = options[:open_timeout]
38
- end
39
- rescue StandardError => e
40
- report(
41
- host: uri.host,
42
- service: 'marathon health',
43
- state: 'critical',
44
- description: "HTTP connection error: #{e.class} - #{e.message}",
45
- )
46
- end
47
- response
48
- end
49
-
50
- def health_url
51
- path_prefix = options[:path_prefix]
52
- path_prefix[0] = '' if path_prefix[0] == '/'
53
- path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
54
- "http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/metrics"
55
- end
56
-
57
- def apps_url
58
- path_prefix = options[:path_prefix]
59
- path_prefix[0] = '' if path_prefix[0] == '/'
60
- path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
61
- "http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/v2/apps"
62
- end
63
-
64
- def tick
65
- tick_health
66
- tick_apps
67
- end
68
-
69
- def tick_health
70
- uri = URI(health_url)
71
- response = safe_get(uri)
72
-
73
- return if response.nil?
74
-
75
- if response.status != 200
76
- report(
77
- host: uri.host,
78
- service: 'marathon health',
79
- state: 'critical',
80
- description: "HTTP connection error: #{response.status} - #{response.body}",
81
- )
82
- else
83
- # Assuming that a 200 will give json
84
- json = JSON.parse(response.body)
85
- state = 'ok'
86
-
87
- report(
88
- host: uri.host,
89
- service: 'marathon health',
90
- state: state,
91
- )
92
-
93
- json.each_pair do |t, d|
94
- next unless d.respond_to? :each_pair
95
-
96
- d.each_pair do |service, counters|
97
- report(
98
- host: uri.host,
99
- service: "marathon_metric #{t} #{service}",
100
- metric: 1,
101
- tags: ['metric_name'],
102
- ttl: 600,
103
- )
104
- next unless counters.respond_to? :each_pair
105
-
106
- counters.each_pair do |k, v|
107
- next unless v.is_a? Numeric
108
-
109
- report(
110
- host: uri.host,
111
- service: "marathon #{service} #{k}",
112
- metric: v,
113
- tags: ['metric', t.to_s],
114
- ttl: 600,
115
- )
116
- end
117
- end
118
- end
119
- end
120
- end
121
-
122
- def tick_apps
123
- uri = URI(apps_url)
124
- response = safe_get(uri)
125
-
126
- return if response.nil?
127
-
128
- if response.status != 200
129
- report(
130
- host: uri.host,
131
- service: 'marathon health',
132
- state: 'critical',
133
- description: "HTTP connection error: #{response.status} - #{response.body}",
134
- )
135
- else
136
- # Assuming that a 200 will give json
137
- json = JSON.parse(response.body)
138
- state = 'ok'
139
-
140
- report(
141
- host: uri.host,
142
- service: 'marathon health',
143
- state: state,
144
- )
145
-
146
- json['apps'].each do |app|
147
- app.each_pair do |k, v|
148
- next unless v.is_a? Numeric
149
-
150
- report(
151
- host: uri.host,
152
- service: "marathon apps#{app['id']}/#{k}",
153
- metric: v,
154
- ttl: 120,
155
- )
156
- end
157
- end
158
- end
159
- end
160
- end
161
- end
162
- end
163
8
  Riemann::Tools::Marathon.run
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'riemann/tools'
4
+
5
+ module Riemann
6
+ module Tools
7
+ class Marathon
8
+ include Riemann::Tools
9
+
10
+ require 'faraday'
11
+ require 'json'
12
+ require 'uri'
13
+
14
+ opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
15
+ opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
16
+ opt :path_prefix,
17
+ 'Marathon path prefix for proxied installations e.g. "marathon" for target http://localhost/marathon/metrics', default: '/'.dup
18
+ opt :marathon_host, 'Marathon host', default: 'localhost'
19
+ opt :marathon_port, 'Marathon port', type: :int, default: 8080
20
+
21
+ def initialize
22
+ options[:interval] = 60
23
+ options[:ttl] = 120
24
+ end
25
+
26
+ # Handles HTTP connections and GET requests safely
27
+ def safe_get(uri)
28
+ # Handle connection timeouts
29
+ response = nil
30
+ begin
31
+ connection = Faraday.new(uri)
32
+ response = connection.get do |req|
33
+ req.options[:timeout] = options[:read_timeout]
34
+ req.options[:open_timeout] = options[:open_timeout]
35
+ end
36
+ rescue StandardError => e
37
+ report(
38
+ host: uri.host,
39
+ service: 'marathon health',
40
+ state: 'critical',
41
+ description: "HTTP connection error: #{e.class} - #{e.message}",
42
+ )
43
+ end
44
+ response
45
+ end
46
+
47
+ def health_url
48
+ path_prefix = options[:path_prefix]
49
+ path_prefix[0] = '' if path_prefix[0] == '/'
50
+ path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
51
+ "http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/metrics"
52
+ end
53
+
54
+ def apps_url
55
+ path_prefix = options[:path_prefix]
56
+ path_prefix[0] = '' if path_prefix[0] == '/'
57
+ path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
58
+ "http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/v2/apps"
59
+ end
60
+
61
+ def tick
62
+ tick_health
63
+ tick_apps
64
+ end
65
+
66
+ def tick_health
67
+ uri = URI(health_url)
68
+ response = safe_get(uri)
69
+
70
+ return if response.nil?
71
+
72
+ if response.status != 200
73
+ report(
74
+ host: uri.host,
75
+ service: 'marathon health',
76
+ state: 'critical',
77
+ description: "HTTP connection error: #{response.status} - #{response.body}",
78
+ )
79
+ else
80
+ # Assuming that a 200 will give json
81
+ json = JSON.parse(response.body)
82
+ state = 'ok'
83
+
84
+ report(
85
+ host: uri.host,
86
+ service: 'marathon health',
87
+ state: state,
88
+ )
89
+
90
+ json.each_pair do |t, d|
91
+ next unless d.respond_to? :each_pair
92
+
93
+ d.each_pair do |service, counters|
94
+ report(
95
+ host: uri.host,
96
+ service: "marathon_metric #{t} #{service}",
97
+ metric: 1,
98
+ tags: ['metric_name'],
99
+ ttl: 600,
100
+ )
101
+ next unless counters.respond_to? :each_pair
102
+
103
+ counters.each_pair do |k, v|
104
+ next unless v.is_a? Numeric
105
+
106
+ report(
107
+ host: uri.host,
108
+ service: "marathon #{service} #{k}",
109
+ metric: v,
110
+ tags: ['metric', t.to_s],
111
+ ttl: 600,
112
+ )
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ def tick_apps
120
+ uri = URI(apps_url)
121
+ response = safe_get(uri)
122
+
123
+ return if response.nil?
124
+
125
+ if response.status != 200
126
+ report(
127
+ host: uri.host,
128
+ service: 'marathon health',
129
+ state: 'critical',
130
+ description: "HTTP connection error: #{response.status} - #{response.body}",
131
+ )
132
+ else
133
+ # Assuming that a 200 will give json
134
+ json = JSON.parse(response.body)
135
+ state = 'ok'
136
+
137
+ report(
138
+ host: uri.host,
139
+ service: 'marathon health',
140
+ state: state,
141
+ )
142
+
143
+ json['apps'].each do |app|
144
+ app.each_pair do |k, v|
145
+ next unless v.is_a? Numeric
146
+
147
+ report(
148
+ host: uri.host,
149
+ service: "marathon apps#{app['id']}/#{k}",
150
+ metric: v,
151
+ ttl: 120,
152
+ )
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -11,10 +11,8 @@ ENV['COPYFILE_DISABLE'] = 'true'
11
11
 
12
12
  # Gemspec
13
13
  gemspec = Gem::Specification.new do |s|
14
- s.rubyforge_project = 'riemann-mesos'
15
-
16
14
  s.name = 'riemann-mesos'
17
- s.version = '0.1.2'
15
+ s.version = '0.1.4'
18
16
  s.author = 'Giulio Eulisse'
19
17
  s.email = 'giulio.eulisse@cern.ch'
20
18
  s.homepage = 'https://github.com/riemann/riemann-tools'
@@ -22,15 +20,14 @@ gemspec = Gem::Specification.new do |s|
22
20
  s.summary = 'Submits mesos stats to riemann.'
23
21
  s.license = 'MIT'
24
22
 
25
- s.add_dependency 'riemann-tools', '>= 0.2.13'
26
- s.add_dependency 'faraday', '>= 0.8.5'
27
- s.add_dependency 'json'
23
+ s.add_runtime_dependency 'riemann-tools', '~> 1.0', '>= 1.1.1'
24
+ s.add_runtime_dependency 'faraday', '~> 2.3', '>= 2.3.0'
25
+ s.add_runtime_dependency 'json', '~> 2.6', '>=2.6.2'
28
26
 
29
- s.files = FileList['bin/*', 'LICENSE', 'README.md'].to_a
27
+ s.files = FileList['bin/*', 'lib/**/*.rb', 'LICENSE', 'README.md'].to_a
30
28
  s.executables |= Dir.entries('bin/')
31
- s.has_rdoc = false
32
29
 
33
- s.required_ruby_version = '>= 1.8.7'
30
+ s.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
34
31
  end
35
32
 
36
33
  Gem::PackageTask.new gemspec do |p|
@@ -3,144 +3,6 @@
3
3
 
4
4
  Process.setproctitle($PROGRAM_NAME)
5
5
 
6
- require 'riemann/tools'
6
+ require 'riemann/tools/mesos'
7
7
 
8
- module Riemann
9
- module Tools
10
- class Mesos
11
- include Riemann::Tools
12
-
13
- require 'faraday'
14
- require 'json'
15
- require 'uri'
16
-
17
- opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
18
- opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
19
- opt :path_prefix,
20
- 'Mesos path prefix for proxied installations e.g. "mesos" for target http://localhost/mesos/metrics/snapshot', default: '/'
21
- opt :mesos_host, 'Mesos host', default: 'localhost'
22
- opt :mesos_port, 'Mesos port', type: :int, default: 5050
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 StandardError => e
35
- report(
36
- host: uri.host,
37
- service: 'mesos health',
38
- state: 'critical',
39
- description: "HTTP connection error: #{e.class} - #{e.message}",
40
- )
41
- end
42
- response
43
- end
44
-
45
- def health_url
46
- path_prefix = options[:path_prefix]
47
- path_prefix[0] = '' if path_prefix[0] == '/'
48
- path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
49
- "http://#{options[:mesos_host]}:#{options[:mesos_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/metrics/snapshot"
50
- end
51
-
52
- def slaves_url
53
- path_prefix = options[:path_prefix]
54
- path_prefix[0] = '' if path_prefix[0] == '/'
55
- path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
56
- "http://#{options[:mesos_host]}:#{options[:mesos_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/master/slaves"
57
- end
58
-
59
- def tick
60
- tick_slaves
61
- uri = URI(health_url)
62
- response = safe_get(uri)
63
-
64
- return if response.nil?
65
-
66
- if response.status != 200
67
- report(
68
- host: uri.host,
69
- service: 'mesos health',
70
- state: 'critical',
71
- description: "HTTP connection error: #{response.status} - #{response.body}",
72
- )
73
- else
74
- # Assuming that a 200 will give json
75
- json = JSON.parse(response.body)
76
- state = 'ok'
77
-
78
- report(
79
- host: uri.host,
80
- service: 'mesos health',
81
- state: state,
82
- )
83
-
84
- json.each_pair do |k, v|
85
- report(
86
- host: uri.host,
87
- service: "mesos #{k}",
88
- metric: v,
89
- )
90
- end
91
- end
92
- end
93
-
94
- def tick_slaves
95
- uri = URI(slaves_url)
96
- response = safe_get(uri)
97
-
98
- return if response.nil?
99
-
100
- if response.status != 200
101
- report(
102
- host: uri.host,
103
- service: 'mesos health',
104
- state: 'critical',
105
- description: "HTTP connection error: #{response.status} - #{response.body}",
106
- )
107
- else
108
- # Assuming that a 200 will give json
109
- json = JSON.parse(response.body)
110
- state = 'ok'
111
-
112
- report(
113
- host: uri.host,
114
- service: 'mesos health',
115
- state: state,
116
- )
117
-
118
- json['slaves'].each do |slave|
119
- next unless slave.respond_to? 'each_pair'
120
-
121
- slave.each_pair do |k, v|
122
- if v.respond_to? 'each_pair'
123
- v.each_pair do |k1, v1|
124
- next unless v1.is_a? Numeric
125
-
126
- report(
127
- host: slave['hostname'],
128
- service: "mesos slave/#{k}/#{k1}",
129
- metric: v1,
130
- )
131
- end
132
- elsif v.is_a? Numeric
133
- report(
134
- host: slave['hostname'],
135
- service: "mesos slave/#{k}",
136
- metric: v,
137
- )
138
- end
139
- end
140
- end
141
- end
142
- end
143
- end
144
- end
145
- end
146
8
  Riemann::Tools::Mesos.run