Created
April 6, 2012 15:35
-
-
Save yyuu/2320855 to your computer and use it in GitHub Desktop.
mon monitor plugin to test memcached service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # | |
| # pymemcached.monitor - mon monitor plugin to test memcached service | |
| # | |
| from __future__ import with_statement | |
| import logging | |
| import optparse | |
| import os | |
| import pylibmc | |
| import sys | |
| def main(args): | |
| parser = optparse.OptionParser("usage %prog [OPTIONS]", add_help_option=False) | |
| parser.add_option('-p', '--port', type='int', default=[], action='append', dest='ports', help='memcached port.') | |
| parser.add_option('--help', action='help', help='show this message and exit.') | |
| parser.add_option('-v', '--verbose', default=False, action='store_true', dest='verbose', help='show verbose message.') | |
| (options, args) = parser.parse_args(args) | |
| if options.verbose: | |
| logging.basicConfig(level=logging.DEBUG) | |
| ports = options.ports if 0 < len(options.ports) else [ 11211 ] | |
| f = 0 | |
| for host, port in reduce(lambda xs,x: xs+x, [ [ (h, p) for p in ports ] for h in args[1:] ], []): | |
| try: | |
| client = pylibmc.Client(["%s:%d" % (host, port)]) | |
| stats = client.get_stats() | |
| if options.verbose: | |
| logging.debug("Got stats: %s" % (repr(stats),)) | |
| except pylibmc.SomeErrors, error: | |
| logging.error("Got error: %s" % (error,)) | |
| f += 1 | |
| finally: | |
| pass | |
| sys.exit(0 if f == 0 else 1) | |
| if __name__ == "__main__": | |
| main(sys.argv) | |
| # vim:set ft=python : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment