Skip to content

Commit

Permalink
Fixes a bad appease of the rubocops with using conditional assignements.
Browse files Browse the repository at this point in the history
I was too quick looking to fix up during a live session on updating and glossed over this. They not only needed to check the conditional but store it if there was a match.

Signed-off-by: Ben Abrams <[email protected]>
  • Loading branch information
majormoses committed Jan 25, 2018
1 parent afe2ffd commit 9f28b93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins

## [Unreleased]

### Fixed
- metrics-cassandra-graphite.rb: fixed conditional assignments broken by agressive rubocop rule fix and following the instructions during a demo (@majormoses)

## [2.0.1] - 2018-01-23
### Changed
- no-op change (@majormoses)
Expand Down
14 changes: 7 additions & 7 deletions bin/metrics-cassandra-graphite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,25 @@ def parse_info
# #YELLOW
# TODO: come back and refactor me to be better
info.each_line do |line| # rubocop:disable Metrics/BlockLength
if m == line.match(/^Exceptions\s*:\s+([0-9]+)$/)
if (m = line.match(/^Exceptions\s*:\s+([0-9]+)$/))
output "#{config[:scheme]}.exceptions", m[1], @timestamp
end

if m =+ line.match(/^Load\s*:\s+([0-9.]+)\s+([KMGT]i?B|bytes)$/)# rubocop:disable all
if (m = line.match(/^Load\s*:\s+([0-9.]+)\s+([KMGT]i?B|bytes)$/))
output "#{config[:scheme]}.load", convert_to_bytes(m[1], m[2]), @timestamp
end

if m == line.match(/^Uptime[^:]+:\s+(\d+)$/)
if (m = line.match(/^Uptime[^:]+:\s+(\d+)$/))
output "#{config[:scheme]}.uptime", m[1], @timestamp
end

if m == line.match(/^Heap Memory[^:]+:\s+([0-9.]+)\s+\/\s+([0-9.]+)$/)# rubocop:disable all
if (m = line.match(/^Heap Memory[^:]+:\s+([0-9.]+)\s+\/\s+([0-9.]+)$/))
output "#{config[:scheme]}.heap.used", convert_to_bytes(m[1], 'MB'), @timestamp
output "#{config[:scheme]}.heap.total", convert_to_bytes(m[2], 'MB'), @timestamp
end

# v1.1+
if m == line.match(/^Key Cache[^:]+: size ([0-9]+) \(bytes\), capacity ([0-9]+) \(bytes\), ([0-9]+) hits, ([0-9]+) requests/)# rubocop:disable all
if (m = line.match(/^Key Cache[^:]+: size ([0-9]+) \(bytes\), capacity ([0-9]+) \(bytes\), ([0-9]+) hits, ([0-9]+) requests/))
output "#{config[:scheme]}.key_cache.size", m[1], @timestamp
output "#{config[:scheme]}.key_cache.capacity", m[2], @timestamp
output "#{config[:scheme]}.key_cache.hits", m[3], @timestamp
Expand All @@ -222,15 +222,15 @@ def parse_info
# 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 all
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
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
end

if m == line.match(/^Row Cache[^:]+: size ([0-9]+) \(bytes\), capacity ([0-9]+) \(bytes\), ([0-9]+) hits, ([0-9]+) requests/)# rubocop:disable all
if (m = line.match(/^Row Cache[^:]+: size ([0-9]+) \(bytes\), capacity ([0-9]+) \(bytes\), ([0-9]+) hits, ([0-9]+) requests/))
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
Expand Down

0 comments on commit 9f28b93

Please sign in to comment.