Permalink
Browse files

Merge pull request #63 from yjh0502/master

Add redis commands per second monitoring
  • Loading branch information...
2 parents bd76e00 + 09b56c9 commit 72f38f2f229f165dc11bd2aa4ffa1d6c696b733e @dagwieers committed Feb 5, 2014
Showing with 52 additions and 0 deletions.
  1. +52 −0 plugins/dstat_redis.py
View
52 plugins/dstat_redis.py
@@ -0,0 +1,52 @@
+### Author: Jihyun Yu <yjh0502@gmail.com>
+
+global redis_host
+redis_host = os.getenv('DSTAT_REDIS_HOST') or "127.0.0.1"
+
+global redis_port
+redis_port = os.getenv('DSTAT_REDIS_PORT') or "6379"
+
+class dstat_plugin(dstat):
+ def __init__(self):
+ self.type = 'd'
+ self.width = 7
+ self.scale = 10000
+ self.name = 'redis'
+ self.nick = ('tps',)
+ self.vars = ('tps',)
+ self.cmdInfo = '*1\r\n$4\r\ninfo\r\n'
+
+ def get_info(self):
+ global socket
+ import socket
+
+ global redis_host
+ global redis_port
+
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ try:
+ s.settimeout(0.1)
+ s.connect((redis_host, int(redis_port)))
+ s.send(self.cmdInfo)
+ dict = {};
+ for line in s.recv(1024*1024).split('\r\n'):
+ if line == "" or line[0] == '#' or line[0] == '*' or line[0] == '$':
+ continue
+ pair = line.split(':', 2)
+ dict[pair[0]] = pair[1]
+ return dict
+ except:
+ return {}
+ finally:
+ try:
+ s.close()
+ except:
+ pass
+
+ def extract(self):
+ key = "instantaneous_ops_per_sec"
+ dic = self.get_info()
+ if key in dic:
+ self.val['tps'] = int(dic[key])
+
+# vim:ts=4:sw=4:et

0 comments on commit 72f38f2

Please sign in to comment.