Skip to content

Commit

Permalink
check-redis-memory-percentage: Use total memory if max is 0 (sensu-pl…
Browse files Browse the repository at this point in the history
…ugins#29)

* check-redis-memory-percentage: Use total memory if max is 0

* check-redis-memory-percentage: Changing memory casting and using fdiv
  • Loading branch information
stevenviola authored and majormoses committed May 10, 2017
1 parent c715464 commit 11d6985
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]
### Changed
- check-redis-memory-percentage: Handle case where maxmemory is 0 (@stevenviola)

## [1.1.1] - 2017-05-05
### Fixed
- updated gemspec to avoid deprecation warnings in redis client for Fixnum
Expand Down
8 changes: 6 additions & 2 deletions bin/check-redis-memory-percentage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ def run
redis = Redis.new(options)

redis_info = redis.info
memory_in_use = redis_info.fetch('used_memory').to_f.div(1024).to_f # used memory in KB (KiloBytes)
total_memory = redis_info.fetch('maxmemory', system_memory).to_f.div(1024).to_f # max memory (if specified) in KB
max_memory = redis_info.fetch('maxmemory', 0).to_i
if max_memory == 0
max_memory = redis_info.fetch('total_system_memory', system_memory).to_i
end
memory_in_use = redis_info.fetch('used_memory').to_i.fdiv(1024) # used memory in KB (KiloBytes)
total_memory = max_memory.fdiv(1024) # max memory (if specified) in KB

used_memory = ((memory_in_use / total_memory) * 100).round(2)
warn_memory = config[:warn_mem]
Expand Down

0 comments on commit 11d6985

Please sign in to comment.