scripts/munin/webalizer_
salles c1b71ce77a On ajoute des limites pour le graphe car on sait que c'est entre 0 et 100
darcs-hash:20060502133124-72cb0-1421a57aca2a390c50807f5f24ec14afd43e691d.gz
2006-05-02 15:31:24 +02:00

73 lines
1.9 KiB
Python
Executable file

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# 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]
# 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/total
if pourcentage > 1 :
usage[nav] = pourcentage
reste = 100 - reduce(add, usage.values())
try :
arg = sys.argv[1]
except :
arg = ''
if arg == "config" :
print 'host_name web'
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)
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 %s' % (nom, usage[key])
print 'reste.value %s' % reste