#!/usr/bin/env python # -*- coding: utf-8 -*- # Représentation des navigateurs utilisés import sys, commands, string, re from time import strftime from operator import add # On prend l'argument pour définir la table à analyser SITE = sys.argv[0].split('_')[1] # nom de la machine import socket HOSTNAME = socket.gethostname() # On traite le fichier de webalizer correspondant FILE = "/var/www/webalizer/%s/webalizer.current" % SITE f = open(FILE, 'r') lines = f.readlines() f.close() navigateurs = {} agent = False for line in lines : #print line if "# -agents-" in line : agent = True if "# End Of Table - agents" in line : break if agent : if line [:2] == "0 " : navigateurs[nom]=int(line[2:]) else : nom = line.strip() total = reduce(add, navigateurs.values()) usage = {} for nav in navigateurs.keys() : pourcentage = navigateurs[nav]*100.0/total if pourcentage > 1 : usage[nav] = pourcentage reste = 100.0 - reduce(add, usage.values()) try : arg = sys.argv[1] except : arg = '' if arg == "config" : print 'host_name web.%s' % HOSTNAME print 'graph_category %s' % SITE print 'graph_title http://%s.crans.org' % SITE print 'graph_args --base 1000 -r --lower-limit 0 --upper-limit 100' print 'graph_scale no' print 'graph_args --base 1000 --lower-limit 0' print 'graph_vlabel % des visites' for key in usage.keys() : nom = key for char in [' ','_','-','/','\\',':',';','.','+','(',')','!','"','\'','@'] : nom = nom.replace(char, '') print '%s.label %s' % (nom, key[:20]) if usage.keys().index(key) == 0 : print '%s.draw AREA' % nom else : print '%s.draw STACK' % nom print 'reste.label Autres' print 'reste.draw STACK' else : for key in usage.keys() : nom = key for char in [' ','_','-','/','\\',':',';','.','+','(',')','!','"','\'','@'] : nom = nom.replace(char, '') print '%s.value %.2f' % (nom, usage[key]) print 'reste.value %.2f' % reste