[wifi/bornes.py] fournit les plugins munin clients_bornes et canal_bornes
darcs-hash:20090929130309-bd074-93a279de6dde0b9c64117aceec42f12fa3bf4b67.gz
This commit is contained in:
parent
c014a48ee1
commit
42b74ec0e3
1 changed files with 42 additions and 11 deletions
|
@ -10,9 +10,13 @@
|
|||
|
||||
La sortie est la sortie de `uname -v` sur chaque borne."""
|
||||
|
||||
import sys, os, commands
|
||||
import sys, os, commands, re, time
|
||||
from optparse import OptionParser
|
||||
|
||||
LOG = "/var/log/wifi/wifi.log"
|
||||
DELTA = 60*60
|
||||
|
||||
|
||||
def bornes():
|
||||
"""Renvoie la liste des bornes
|
||||
|
||||
|
@ -106,7 +110,7 @@ def bornes_uptime():
|
|||
output.close()
|
||||
return results
|
||||
|
||||
def munin(config, cmd, process=(lambda x: x)):
|
||||
def munin(config, cmd=None, process=(lambda x: x), results=None, buckets=None):
|
||||
"""plugin munin"""
|
||||
|
||||
if 'autoconf' in sys.argv:
|
||||
|
@ -117,17 +121,31 @@ def munin(config, cmd, process=(lambda x: x)):
|
|||
|
||||
if 'config' in sys.argv:
|
||||
print config
|
||||
for borne in names:
|
||||
print "%s.label %s"% (borne, borne)
|
||||
if buckets:
|
||||
for val, lbl in buckets.iteritems():
|
||||
print "%s.label %s" % (lbl, val)
|
||||
else:
|
||||
for borne in names:
|
||||
print "%s.label %s" % (borne, borne)
|
||||
sys.exit(0)
|
||||
|
||||
outputs = {}
|
||||
for name in names:
|
||||
outputs[name] = ssh_exec(name+".wifi", cmd)
|
||||
if not results:
|
||||
res = results = {}
|
||||
for name in names: res[name] = ssh_exec(name+".wifi", cmd)
|
||||
for name in names: results[name] = res[name].read()
|
||||
|
||||
if buckets:
|
||||
bins = {}
|
||||
for (lbl, val) in buckets.iteritems(): bins[val] = 0
|
||||
for name, res in results.iteritems():
|
||||
value = process(res).split('\n', 1)[0].strip()
|
||||
if buckets: bins[buckets[value]] += 1
|
||||
else: print '%s.value %s' % (name, value)
|
||||
|
||||
if buckets:
|
||||
for name, res in bins.iteritems():
|
||||
print '%s.value %s' % (name, res)
|
||||
|
||||
for name, res in outputs.iteritems():
|
||||
value = process(res.read()).split('\n', 1)[0].strip()
|
||||
print '%s.value %s' % (name, value)
|
||||
|
||||
def main():
|
||||
parser = OptionParser(usage=usage)
|
||||
|
@ -192,7 +210,20 @@ graph_vlabel uptime in days"""
|
|||
def process(uptime):
|
||||
if uptime: return str(float (uptime.split()[1]) / (24 * 3600))
|
||||
else: return '0'
|
||||
munin(config, 'cat /proc/uptime', process=process)
|
||||
munin(config, cmd = 'cat /proc/uptime', process=process)
|
||||
elif plugin == 'clients':
|
||||
config = """graph_title Clients connectés
|
||||
graph_args --base 1000 -l 0
|
||||
graph_vlabel Clients connectés"""
|
||||
munin(config, results=bornes_clients())
|
||||
elif plugin == 'canal':
|
||||
config = """graph_title Canaux utilisés
|
||||
graph_args --base 1000 -l 0"""
|
||||
buckets = {'1': 'un', '2': 'deux', '3': 'trois', '4': 'quatre',
|
||||
'5': 'cinq', '6': 'siz', '7': 'sept', '8': 'huit',
|
||||
'9': 'neuf', '10': 'dix', '11': 'onze', '12': 'douze',
|
||||
'13': 'treize', '14': 'quatorze', '0': 'echec' }
|
||||
munin(config, results=bornes_canal(), buckets= buckets)
|
||||
else: raise NotImplementedError
|
||||
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue