Skip to content

Commit

Permalink
Add option to inject Mesos master node role into metric fields (#16)
Browse files Browse the repository at this point in the history
* Adding status to mesos-metrics

* slight modification on customized status metric to get proper tagging with InfluxDB

* Adding option to change metrics format based on master role

* Update CHANGELOG
  • Loading branch information
alcasim authored and majormoses committed Jul 10, 2017
1 parent c633f0d commit 23c7572
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

### Added
- metrics-mesos.rb: Added option "include_role" to inject in metric fields whether a master node is leader or standby

## [Unreleased]
## [1.0.0] - 2017-05-05
### Breaking Change
Expand Down
20 changes: 18 additions & 2 deletions bin/metrics-mesos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class MesosMetrics < Sensu::Plugin::Metric::CLI::Graphite
proc: proc(&:to_i),
default: 5

option :include_role,
description: 'Include master role in metrics',
short: '-r INCLUDE_ROLE',
long: '--host INCLUDE_ROLE',
default: 'false'

def run
uri = config[:uri]
case config[:mode]
Expand All @@ -86,9 +92,19 @@ def run
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|
results = JSON.parse(r)
if config[:include_role] == 'true' && config[:mode] == 'master'
add_metric = if results['master/elected'] != 0.0
'leader.'
else
'standby.'
end
else
add_metric = ''
end
results.each do |k, v|
k_copy = k.tr('/', '.')
output([scheme, k_copy].join('.'), v)
output([scheme, add_metric + k_copy].join('.'), v)
end
rescue Errno::ECONNREFUSED
critical "Mesos #{config[:mode]} is not responding"
Expand Down

0 comments on commit 23c7572

Please sign in to comment.