Skip to content

Commit

Permalink
Memcached monitoring plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vfuse committed Mar 19, 2018
1 parent bf36d32 commit e24770a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nixstatsagent/nixstatsagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import urllib2


__version__ = '1.1.41'
__version__ = '1.1.42'

__FILEABSDIRNAME__ = os.path.dirname(os.path.abspath(__file__))

Expand Down
104 changes: 104 additions & 0 deletions nixstatsagent/plugins/memcached.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import plugins
import struct
import time
from memcached_stats import MemcachedStats

class Plugin(plugins.BasePlugin):
__name__ = 'memcached'

def run(self, config):
'''
add to /etc/nixstats.ini
[memcached]
enabled=yes
host=127.0.0.1
port=11211
'''

prev_cache = self.get_agent_cache() # Get absolute values from previous check
non_delta = (
'accepting_conns',
'bytes',
'uptime',
'total_items',
'total_connections',
'time_in_listen_disabled_us',
'threads',
'rusage_user',
'rusage_system',
'reserved_fds',
'pointer_size',
'malloc_fails',
'lrutail_reflocked',
'listen_disabled_num',
'limit_maxbytes',
'hash_power_level',
'hash_bytes',
'curr_items',
'curr_connections',
'connection_structures',
'conn_yields',
'reclaimed'
)
delta_keys = (
'auth_cmds',
'auth_errors',
'bytes_read',
'bytes_written',
'touch_misses',
'touch_hits',
'incr_misses',
'incr_hits',
'cas_misses',
'cas_badval',
'incr_hits',
'get_misses',
'get_hits',
'expired_unfetched',
'evictions',
'evicted_unfetched',
'delete_misses',
'delete_hits',
'decr_misses',
'decr_hits',
'crawler_reclaimed',
'crawler_items_checked',
'cmd_touch',
'cmd_get',
'cmd_set',
'cmd_flush',
'cmd_misses',
'cmd_badval',
'cmd_hits'
)

try:
# Connect
mem = MemcachedStats(config.get('memcached', 'host'), config.get('memcached', 'port'))
except:
return "Could not connect to memcached"

results = {}
data = {}
try:
result = mem.stats()
for key, value in result.items():
key = key.lower().strip()
if key in non_delta:
results[key] = float(value)
elif key in delta_keys:
value = float(value)
results[key] = self.absolute_to_per_second(key, float(value), prev_cache)
data[key] = float(value)
else:
pass
except:
return "Could not fetch memcached stats"

data['ts'] = time.time()
self.set_agent_cache(data)
return results


if __name__ == '__main__':
Plugin().execute()
3 changes: 2 additions & 1 deletion nixstatsagent/plugins/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def run(self, config):
uri = os.getenv("uri", "qemu:///system")
values = self.fetch_values(uri)

deltas = {}
for key, value in values.items():
deltas = {}
deltas[key] = {}
for subkey, subvalue in value.items():
deltas[key][subkey] = self.absolute_to_per_second('%s_%s' % (key, subkey), float(subvalue), prev_cache)
last_value['%s_%s' % (key, subkey)] = float(value[subkey])
Expand Down

0 comments on commit e24770a

Please sign in to comment.