bin/metrics-mesos.rb in sensu-plugins-mesos-0.1.0 vs bin/metrics-mesos.rb in sensu-plugins-mesos-0.1.1
- old
+ new
@@ -31,10 +31,14 @@
require 'sensu-plugin/metric/cli'
require 'rest-client'
require 'socket'
require 'json'
+# Mesos default ports are defined here: http://mesos.apache.org/documentation/latest/configuration
+MASTER_DEFAULT_PORT = '5050'.freeze
+SLAVE_DEFAULT_PORT = '5051'.freeze
+
class MesosMetrics < Sensu::Plugin::Metric::CLI::Graphite
option :mode,
description: 'master or slave',
short: '-m MODE',
long: '--mode MODE',
@@ -42,31 +46,37 @@
option :scheme,
description: 'Metric naming scheme',
short: '-s SCHEME',
long: '--scheme SCHEME',
- default: "#{Socket.gethostname}"
+ default: Socket.gethostname.to_s
option :server,
description: 'Mesos Host',
short: '-h SERVER',
long: '--host SERVER',
default: 'localhost'
+ option :port,
+ description: "port (default #{MASTER_DEFAULT_PORT} for master, #{SLAVE_DEFAULT_PORT} for slave)",
+ short: '-p PORT',
+ long: '--port PORT',
+ required: false
+
option :timeout,
description: 'timeout in seconds',
short: '-t TIMEOUT',
long: '--timeout TIMEOUT',
proc: proc(&:to_i),
default: 5
def run
case config[:mode]
when 'master'
- port = '5050'
+ port = config[:port] || MASTER_DEFAULT_PORT
uri = '/master/stats.json'
when 'slave'
- port = '5051'
+ port = config[:port] || SLAVE_DEFAULT_PORT
uri = '/slave(1)/stats.json'
end
scheme = "#{config[:scheme]}.mesos-#{config[:mode]}"
begin
r = RestClient::Resource.new("http://#{config[:server]}:#{port}#{uri}", timeout: config[:timeout]).get