Added number of user for modules in statistics.

This commit is contained in:
Christoph Niethammer 2013-06-12 15:13:38 +00:00
parent 65f0ea276e
commit 9cc4d9a9e6

View file

@ -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]