riemann-tools 1.0.0 → 1.2.0

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