From ec1aefa16d823299939ae3f7c3027d2d9b0ef2a6 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Sat, 17 Apr 2010 10:42:33 +0200 Subject: [PATCH] Statistiche. --- phcstats.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/phcstats.py b/phcstats.py index ade42f6..97c8fba 100755 --- a/phcstats.py +++ b/phcstats.py @@ -5,6 +5,7 @@ # e restituisce delle statistiche a proposito. import subprocess, time +from optparse import OptionsParser # Qualche variabile globale database_directory = '/home/robol/client_stats/' # Il traling slash ci serve @@ -66,9 +67,34 @@ def UpdateClientsData(client, alive): data = LoadClientData(client) data[time.time()] = alive DumpClientData(client, data) + +def PrintStats(client): + """ + Stampa le statistiche sul client prescelto + """ + data = LoadClientData(client) + uptime = len(filter(lambda s: (s==True), data))/ float(len(filter)) + print "Uptime: %3.3f (%s)" % (100 * uptime, client) + if __name__ == "__main__": - for client in LoadClients(): - UpdateClientsData(client, IsAlive(client)) + + parser = OptionParser() + parser.add_option("-c", "--check", dest="check", + help = "Check if clients are up and update database", + action = "store_true", default=True) + parser.add_option("-s", "--stats", dest="stats", + help = "Print stats about collected informations", + action = "store_true", default = False) + + (options, args) = parser.parse_args() + + if options.check: + for client in LoadClients(): + UpdateClientsData(client, IsAlive(client)) + + if options.stats: + for client in LoadClients(): + PrintStats(client) -- 2.1.4