From 1f707994608301fa542087466a04ac2bdf4d6649 Mon Sep 17 00:00:00 2001 From: flc Date: Thu, 29 Mar 2012 16:04:50 +0200 Subject: [PATCH 1/4] add get_config method to make it a bit flexible --- munin/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/munin/__init__.py b/munin/__init__.py index a3d7798..984895f 100644 --- a/munin/__init__.py +++ b/munin/__init__.py @@ -24,7 +24,7 @@ def __init__(self): def autoconf(self): return False - def config(self): + def get_config(self): conf = [] for k in ('title', 'category', 'args', 'vlabel', 'info', 'scale', 'order'): v = getattr(self, k, None) @@ -39,6 +39,10 @@ def config(self): for arg_name, arg_value in field_args.iteritems(): conf.append('%s.%s %s' % (field_name, arg_name, arg_value)) + return conf + + def config(self): + conf = self.get_config() print "\n".join(conf) def suggest(self): From 2e226d21aef15dcece3c9e8be17c7867c8583f86 Mon Sep 17 00:00:00 2001 From: flc Date: Thu, 29 Mar 2012 16:06:16 +0200 Subject: [PATCH 2/4] add MuninRedisDBPlugin --- munin/redis_db_base.py | 37 +++++++++++++++++++++++++++++++++++++ plugins/redis_db1 | 12 ++++++++++++ plugins/redis_db2 | 12 ++++++++++++ plugins/redis_db3 | 12 ++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 munin/redis_db_base.py create mode 100755 plugins/redis_db1 create mode 100644 plugins/redis_db2 create mode 100644 plugins/redis_db3 diff --git a/munin/redis_db_base.py b/munin/redis_db_base.py new file mode 100644 index 0000000..0588001 --- /dev/null +++ b/munin/redis_db_base.py @@ -0,0 +1,37 @@ +from munin.redis import MuninRedisPlugin + + +class MuninRedisDBPlugin(MuninRedisPlugin): + title = "Redis %(db_name)s" + args = "--base 1000" + vlabel = "num" + info = "%(db_name)s" + fields = ( + ('%(db_name)s_keys', dict( + label = "%(db_name)s_keys", + info = "%(db_name)s_keys", + type = "GAUGE", + )), + ('%(db_name)s_expires', dict( + label = "%(db_name)s_expires", + info = "%(db_name)s_expires", + type = "GAUGE", + )), + ) + + def get_config(self): + conf = super(MuninRedisDBPlugin, self).get_config() + return [c % {'db_name': self.db_name} for c in conf] + + def execute(self): + stats = self.get_info() + r_values = stats[self.db_name] + values = [v.split("=")[1] for v in r_values.split(",")] + ret_values = {} + for index, (k, v) in enumerate(self.fields): + try: + value = values[index] + except IndexError: + value = "U" + ret_values[k % {'db_name': self.db_name}] = value + return ret_values diff --git a/plugins/redis_db1 b/plugins/redis_db1 new file mode 100755 index 0000000..206e345 --- /dev/null +++ b/plugins/redis_db1 @@ -0,0 +1,12 @@ +#!/usr/bin/env python + + +from munin.redis_db_base import MuninRedisDBPlugin + + +class MuninRedisDB1Plugin(MuninRedisDBPlugin): + db_name = "db1" + + +if __name__ == "__main__": + MuninRedisDB1Plugin().run() diff --git a/plugins/redis_db2 b/plugins/redis_db2 new file mode 100644 index 0000000..f26c5f9 --- /dev/null +++ b/plugins/redis_db2 @@ -0,0 +1,12 @@ +#!/usr/bin/env python + + +from munin.redis_db_base import MuninRedisDBPlugin + + +class MuninRedisDB2Plugin(MuninRedisDBPlugin): + db_name = "db2" + + +if __name__ == "__main__": + MuninRedisDB2Plugin().run() diff --git a/plugins/redis_db3 b/plugins/redis_db3 new file mode 100644 index 0000000..ec3596e --- /dev/null +++ b/plugins/redis_db3 @@ -0,0 +1,12 @@ +#!/usr/bin/env python + + +from munin.redis_db_base import MuninRedisDBPlugin + + +class MuninRedisDB3Plugin(MuninRedisDBPlugin): + db_name = "db3" + + +if __name__ == "__main__": + MuninRedisDB3Plugin().run() From 777d755f4b8a58598eac58834337ef18894aa1e9 Mon Sep 17 00:00:00 2001 From: flc Date: Thu, 29 Mar 2012 16:16:17 +0200 Subject: [PATCH 3/4] change mode to executable --- plugins/redis_db2 | 0 plugins/redis_db3 | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 plugins/redis_db2 mode change 100644 => 100755 plugins/redis_db3 diff --git a/plugins/redis_db2 b/plugins/redis_db2 old mode 100644 new mode 100755 diff --git a/plugins/redis_db3 b/plugins/redis_db3 old mode 100644 new mode 100755 From d6dbd363ab2390e49b8a5f6206cbe02c004f1368 Mon Sep 17 00:00:00 2001 From: flc Date: Thu, 29 Mar 2012 16:18:00 +0200 Subject: [PATCH 4/4] handle the case when info for the specified redis db doesn't exist --- munin/redis_db_base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/munin/redis_db_base.py b/munin/redis_db_base.py index 0588001..491e2ee 100644 --- a/munin/redis_db_base.py +++ b/munin/redis_db_base.py @@ -25,8 +25,10 @@ def get_config(self): def execute(self): stats = self.get_info() - r_values = stats[self.db_name] - values = [v.split("=")[1] for v in r_values.split(",")] + r_values = stats.get(self.db_name, None) + values = [] + if r_values is not None: + values = [v.split("=")[1] for v in r_values.split(",")] ret_values = {} for index, (k, v) in enumerate(self.fields): try: