From 9cc4d9a9e64f48c13e064e8dc138b00c24a011d0 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Wed, 12 Jun 2013 15:13:38 +0000 Subject: [PATCH] Added number of user for modules in statistics. --- module_stats.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/module_stats.py b/module_stats.py index 2d49843..fcaee95 100755 --- a/module_stats.py +++ b/module_stats.py @@ -10,6 +10,7 @@ from optparse import OptionParser modules = list() modulestats = dict() +moduleusers = dict() logdir = '/sw/laki/hlrs/system/modules/logs/' enddate = datetime.date.today() @@ -20,6 +21,7 @@ parser = OptionParser(usage="%prog [options] [pattern]") parser.add_option("--logdir", metavar="DIR", dest="logdir") parser.add_option("--startdate", metavar="YYYY-MM-DD", dest="startdate") parser.add_option("--enddate", metavar="YYYY-MM-DD", dest="enddate") +parser.add_option("--nohpc", action="store_true", default=False, dest="nohpc", help="Exclude hpc* accounts from stats") (options, args) = parser.parse_args() if options.logdir : logdir = options.logdir @@ -45,11 +47,20 @@ for logfilename in os.listdir(logdir) : for line in f : if ' load' in line and modulepattern in line : module = line.split()[-1] + user = line.split()[-3][5:] # remove user: in front + if options.nohpc and 'hpc' in user : + continue if module not in modules: modules.append(module) modulestats[module] = 1 + moduleusers[module] = dict() + moduleusers[module][user] = 1 else : modulestats[module] = modulestats[module] + 1 + if user not in moduleusers[module] : + moduleusers[module][user] = 1 + else : + moduleusers[module][user] = moduleusers[module][user] + 1 # if ' swap' in line : # print line.split() @@ -57,6 +68,9 @@ for logfilename in os.listdir(logdir) : print "-"*78 print "Module statistics for " + startdate.strftime('%Y-%m-%d') + " - " + enddate.strftime('%Y-%m-%d') print "-"*78 +print "{0:60s}{1:>8s} {2:>8s}".format('module name', '# uses', '# users') +print "-"*78 for (v,m) in sorted( ((v,k) for k,v in modulestats.iteritems()), reverse=True) : - print "{0:70s}{1:>8d}".format(m, v) + print "{0:60s}{1:>8d} {2:>8d}".format(m, v, len(moduleusers[m].keys())) + #print moduleusers[m]