From: František Dvořák Date: Mon, 16 Mar 2015 14:05:48 +0000 (+0100) Subject: Custom min/max time in the node load analyzer script. X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=ae7f6a6f1dd23470d6e927f7943515730e66a09a;p=hadoop-jobstat.git Custom min/max time in the node load analyzer script. --- diff --git a/chroust.py b/chroust.py index 6f5d5ae..af93919 100755 --- a/chroust.py +++ b/chroust.py @@ -19,6 +19,9 @@ dbuser = 'bookkeeping' dbpassword = '' debug = 0 interval = 24 * 3600 +min = None +max = None +header = 1 db = None st = None @@ -37,7 +40,7 @@ def strp(val): try: - opts, args = getopt.getopt(sys.argv[1:], 'hc:di:', ['help', 'config=', 'dbhost=', 'dbname=', 'dbuser=', 'dbpassword=', 'debug', 'interval=' ]) + opts, args = getopt.getopt(sys.argv[1:], 'hc:di:n:x:H', ['help', 'config=', 'dbhost=', 'dbname=', 'dbuser=', 'dbpassword=', 'debug', 'interval=', 'min=', 'max=', 'no-header' ]) except getopt.GetoptError: print 'Args error' sys.exit(2) @@ -52,7 +55,10 @@ OPTIONS are:\n\ --dbuser\n\ -d, --debug\n\ --dbpassword\n\ - -i, --interval TIME ... time interval" + -i, --interval TIME ... time interval\n\ + -n, --min ............. start time (default: autodetect)\n\ + -x, --max ............. end time (default: autodetect)\n\ + -H, --no-header ....... don't print the header" sys.exit(0) elif opt in ('-c', '--config'): f = open(arg, 'r') @@ -79,6 +85,12 @@ OPTIONS are:\n\ debug = int(arg) elif opt in ('-i', '--interval'): interval = long(arg) + elif opt in ('-n', '--min'): + min = long(arg) * 1000 + elif opt in ('-x', '--max'): + max = long(arg) * 1000 + elif opt in ('-H', '--no-header'): + header = 0 else: print 'Args error' sys.exit(2) @@ -94,10 +106,13 @@ while 1: nodes[data['id']] = data['host'] -st.execute('SELECT MIN(start) AS min, MAX(finish) AS max FROM subjobs') -data = st.fetchone() -min = data['min'] -max = data['max'] +if not min or not max: + st.execute('SELECT MIN(start) AS min, MAX(finish) AS max FROM subjobs') + data = st.fetchone() +if not min: + min = data['min'] +if not max: + max = data['max'] if debug: print 'Min: %s' % strp(min) @@ -110,12 +125,13 @@ max = 1000 * interval * ((max / 1000 + interval - 1) / interval) if debug: print 'Range: %s ... %s' % (strp(min), strp(max)) -usages = list() -usages.append('time') -usages.append('mapred') -for nodeid in sorted(nodes.keys()): - usages.append(nodes[nodeid]) -print "\t".join(usages) +if header: + usages = list() + usages.append('time') + usages.append('mapred') + for nodeid in sorted(nodes.keys()): + usages.append(nodes[nodeid]) + print "\t".join(usages) i = min while i < max: