bin/metrics-mesos.rb in sensu-plugins-mesos-0.1.1 vs bin/metrics-mesos.rb in sensu-plugins-mesos-1.0.0
- old
+ new
@@ -32,12 +32,12 @@
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
+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',
@@ -60,24 +60,29 @@
description: "port (default #{MASTER_DEFAULT_PORT} for master, #{SLAVE_DEFAULT_PORT} for slave)",
short: '-p PORT',
long: '--port PORT',
required: false
+ option :uri,
+ description: 'Endpoint URI',
+ short: '-u URI',
+ long: '--uri URI',
+ default: '/metrics/snapshot'
+
option :timeout,
description: 'timeout in seconds',
short: '-t TIMEOUT',
long: '--timeout TIMEOUT',
proc: proc(&:to_i),
default: 5
def run
+ uri = config[:uri]
case config[:mode]
when 'master'
port = config[:port] || MASTER_DEFAULT_PORT
- uri = '/master/stats.json'
when 'slave'
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
JSON.parse(r).each do |k, v|