diff -ZurN percona-monitoring-plugins-1.1.4.orig/nagios/bin/pmp-check-aws-rds.py percona-monitoring-plugins-1.1.4/nagios/bin/pmp-check-aws-rds.py --- percona-monitoring-plugins-1.1.4.orig/nagios/bin/pmp-check-aws-rds.py 2014-07-21 03:02:08.000000000 -0700 +++ percona-monitoring-plugins-1.1.4/nagios/bin/pmp-check-aws-rds.py 2015-03-26 09:55:35.501649550 -0700 @@ -15,9 +15,11 @@ import pprint import sys -def get_rds_info(indentifier=None): +def get_rds_info(indentifier=None, rds_debug=0): """Function for fetching RDS details""" - rds = boto.connect_rds() + if rds_debug != 0: + boto.set_stream_logger('boto') + rds = boto.connect_rds(debug=rds_debug) try: if indentifier: info = rds.get_all_dbinstances(indentifier)[0] @@ -27,9 +29,11 @@ info = None return info -def get_rds_stats(step, start_time, end_time, metric, indentifier): +def get_rds_stats(step, start_time, end_time, metric, indentifier, rds_debug=0): """Function for fetching RDS statistics from CloudWatch""" - cw = boto.connect_cloudwatch() + if rds_debug != 0: + boto.set_stream_logger('boto') + cw = boto.connect_cloudwatch(debug=rds_debug) result = cw.get_metric_statistics(step, start_time, end_time, @@ -79,6 +83,9 @@ # Parse options parser = optparse.OptionParser() + parser.add_option('-d', '--debug', help='enable debug output', default=0) + parser.add_option('-t', '--time', help='time period to query', type="int", default=5) + parser.add_option('-a', '--avg', help='time average to request', type="int", default=1) parser.add_option('-l', '--list', help='list of all DB instances', action='store_true', default=False, dest='db_list') parser.add_option('-i', '--ident', help='DB instance identifier') @@ -96,7 +103,7 @@ parser.print_help() sys.exit() elif options.db_list: - info = get_rds_info() + info = get_rds_info(rds_debug=options.debug) print 'List of all DB instances:' pprint.pprint(info) sys.exit() @@ -104,7 +111,7 @@ parser.print_help() parser.error('DB identifier is not set.') elif options.info: - info = get_rds_info(options.ident) + info = get_rds_info(options.ident, options.debug) if info: pprint.pprint(vars(info)) else: @@ -119,6 +126,12 @@ elif not options.crit and options.metric != 'status': parser.print_help() parser.error('Critical threshold is not set.') + elif options.avg <= 0 and options.metric != 'status': + parser.print_help() + parser.error('Average must be greater than zero.') + elif options.time <= 0 and options.metric != 'status': + parser.print_help() + parser.error('Time must be greater than zero.') tm = datetime.datetime.utcnow() status = None @@ -127,7 +140,7 @@ # RDS Status if options.metric == 'status': - info = get_rds_info(options.ident) + info = get_rds_info(options.ident, options.debug) if not info: status = UNKNOWN note = 'Unable to get RDS instance' @@ -163,7 +176,7 @@ else: n = i load = get_rds_stats(i * 60, tm - datetime.timedelta(seconds=n * 60), tm, - metrics[options.metric], options.ident) + metrics[options.metric], options.ident, options.debug) if not load: status = UNKNOWN note = 'Unable to get RDS statistics' @@ -204,9 +217,9 @@ parser.print_help() parser.error('Unit is not valid.') - info = get_rds_info(options.ident) - free = get_rds_stats(60, tm - datetime.timedelta(seconds=60), tm, - metrics[options.metric], options.ident) + info = get_rds_info(options.ident, options.debug) + free = get_rds_stats(options.avg * 60, tm - datetime.timedelta(seconds=(options.time * 60)), tm, + metrics[options.metric], options.ident, options.debug) if not info or not free: status = UNKNOWN note = 'Unable to get RDS details and statistics' @@ -275,6 +288,12 @@ -c CRIT, --crit=CRIT critical threshold -u UNIT, --unit=UNIT unit of thresholds for "storage" and "memory" metrics: [percent, GB]. Default: percent + -t TIME, --time=TIME time period (prior to now) to query, in minutes + Default: 5 + -a AVG, --avg=AVG period to request an average over, in minutes + Default: 1 + -d DEBUG, --debug=DEBUG + enable debugging level =head1 REQUIREMENTS