bin/metrics-cassandra-graphite.rb in sensu-plugins-cassandra-2.1.0 vs bin/metrics-cassandra-graphite.rb in sensu-plugins-cassandra-3.0.0

- old
+ new

@@ -1,6 +1,8 @@ #! /usr/bin/env ruby +# frozen_string_literal: true + # # cassandra-graphite # # DESCRIPTION: # This plugin uses Apache Cassandra's `nodetool` to collect metrics @@ -220,11 +222,11 @@ end # cassandra nodetool v3.0+ Changed the key cache output # Key Cache : entries 569669, size 100 MiB, capacity 100 MiB, 35689224 hits, 70654365 requests, 0.505 recent hit rate, 14400 save period in seconds # Key Cache : entries 13291, size 7.83 MB, capacity 50 MB, 119444 hits, 139720 requests, 0.855 recent hit rate, 14400 save period in seconds - if (m = line.match(/^Key Cache[^:]+: entries ([0-9]+), size ([-+]?[0-9]*\.?[0-9]+) ([KMGT]i?B|bytes), capacity ([-+]?[0-9]*\.?[0-9]+) ([KMGT]i?B|bytes), ([0-9]+) hits, ([0-9]+) requests, ([-+]?[0-9]*\.?[0-9]+) recent hit rate/)) # rubocop:disable Metrics/LineLength + if (m = line.match(/^Key Cache[^:]+: entries ([0-9]+), size ([-+]?[0-9]*\.?[0-9]+) ([KMGT]i?B|bytes), capacity ([-+]?[0-9]*\.?[0-9]+) ([KMGT]i?B|bytes), ([0-9]+) hits, ([0-9]+) requests, ([-+]?[0-9]*\.?[0-9]+) recent hit rate/)) # rubocop:disable Layout/LineLength output "#{config[:scheme]}.key_cache.size", convert_to_bytes(m[2], m[3]), @timestamp output "#{config[:scheme]}.key_cache.capacity", convert_to_bytes(m[4], m[5]), @timestamp output "#{config[:scheme]}.key_cache.hits", m[6], @timestamp output "#{config[:scheme]}.key_cache.requests", m[7], @timestamp output "#{config[:scheme]}.key_cache.hit_rate", m[8], @timestamp @@ -234,10 +236,21 @@ output "#{config[:scheme]}.row_cache.size", m[1], @timestamp output "#{config[:scheme]}.row_cache.capacity", m[2], @timestamp output "#{config[:scheme]}.row_cache.hits", m[3], @timestamp output "#{config[:scheme]}.row_cache.requests", m[4], @timestamp end + + # cassandra nodetool v3.0+ Changed the row cache output + # Row Cache : entries 569669, size 100 MiB, capacity 100 MiB, 35689224 hits, 70654365 requests, 0.505 recent hit rate, 14400 save period in seconds + # Row Cache : entries 13291, size 7.83 MB, capacity 50 MB, 119444 hits, 139720 requests, 0.855 recent hit rate, 14400 save period in seconds + if (m = line.match(/^Row Cache[^:]+: entries ([0-9]+), size ([-+]?[0-9]*\.?[0-9]+) ([KMGT]i?B|bytes), capacity ([-+]?[0-9]*\.?[0-9]+) ([KMGT]i?B|bytes), ([0-9]+) hits, ([0-9]+) requests, ([-+]?[0-9]*\.?[0-9]+) recent hit rate/)) # rubocop:disable Layout/LineLength + output "#{config[:scheme]}.row_cache.size", convert_to_bytes(m[2], m[3]), @timestamp + output "#{config[:scheme]}.row_cache.capacity", convert_to_bytes(m[4], m[5]), @timestamp + output "#{config[:scheme]}.row_cache.hits", m[6], @timestamp + output "#{config[:scheme]}.row_cache.requests", m[7], @timestamp + output "#{config[:scheme]}.row_cache.hit_rate", m[8], @timestamp + end end end # nodetool -h localhost tpstats: # Pool Name Active Pending Completed Blocked All time blocked @@ -333,11 +346,11 @@ # # some notes on parsing cfstats output: # - a line preceeded by 1 tab contains keyspace metrics # - a line preceeded by 2 tabs contains column family metrics def parse_cfstats - def get_metric(string) # rubocop:disable NestedMethodDefinition + def get_metric(string) # rubocop:disable Lint/NestedMethodDefinition string.strip! (metric, value) = string.split(': ') if metric.nil? || value.nil? # rubocop:disable Style/GuardClause return [nil, nil] else @@ -348,9 +361,10 @@ metric.downcase! # sanitize metric values for graphite. Numbers only, please. # some versions of nodetool omit the '.' following the 'ms' unit. value = value.chomp(' ms.').chomp(' ms') end + [metric, value] end cfstats = nodetool_cmd('cfstats')