From 23c7572a31b45afa06dd041874e0331e7028ddd4 Mon Sep 17 00:00:00 2001 From: alcasim Date: Mon, 10 Jul 2017 18:35:12 +0100 Subject: [PATCH] Add option to inject Mesos master node role into metric fields (#16) * 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 --- CHANGELOG.md | 3 +++ bin/metrics-mesos.rb | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 144d2b8..d590313 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/bin/metrics-mesos.rb b/bin/metrics-mesos.rb index eb8882d..07022d5 100755 --- a/bin/metrics-mesos.rb +++ b/bin/metrics-mesos.rb @@ -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] @@ -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"