[munin/innd_total] Plugin donnant le nombre de posts dans chaque newsgroup
darcs-hash:20090330000916-ddb99-f66977fbf2ad91314fc2a60d7c15db18e8cb9a83.gz
This commit is contained in:
parent
4d5267fb20
commit
dd46ec68bb
1 changed files with 84 additions and 0 deletions
84
munin/innd_total
Executable file
84
munin/innd_total
Executable file
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2009 Michel Blockelet <blockelet@crans.org>
|
||||
|
||||
# This file is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This file is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""Plugin munin pour innd."""
|
||||
|
||||
## Importations
|
||||
import socket
|
||||
import sys
|
||||
|
||||
def recvlines(sock):
|
||||
buff = sock.recv(4096)
|
||||
while buff[-3] != '.':
|
||||
buff += sock.recv(4096)
|
||||
return buff.split('\r')[:-2]
|
||||
|
||||
## Connexion
|
||||
s = socket.socket()
|
||||
s.connect(('localhost', 119))
|
||||
|
||||
## Mise en mode reader (pour utiliser 'listgroup')
|
||||
s.send("mode reader\r\n")
|
||||
s.recv(4096)
|
||||
|
||||
## Récupération des newsgroups et du nombre de posts
|
||||
s.send("list\r\n")
|
||||
newsgroups = []
|
||||
for l in recvlines(s)[1:]:
|
||||
name = l.split()[0]
|
||||
|
||||
# Conversion du nom vers un format accepté par munin
|
||||
cname = name
|
||||
while '.' in cname:
|
||||
(parent, sep, sub) = cname.partition('.')
|
||||
cname = '%s_%s' % (parent[0], sub)
|
||||
cname = cname.replace('-', '_')
|
||||
|
||||
# Récupération du nombre de posts
|
||||
s.send('listgroup %s\r\n' % name)
|
||||
val = len(recvlines(s))
|
||||
|
||||
# On ne garde pas les newsgroups presque vides
|
||||
if val > 5:
|
||||
newsgroups.append((name, cname, val))
|
||||
|
||||
|
||||
## Sortie
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'config':
|
||||
# Configuration du graphe
|
||||
print 'host_name news.crans.org'
|
||||
print 'graph_title Nombre de posts'
|
||||
print 'graph_args --base 1000 --lower-limit 0'
|
||||
print 'graph_vlabel nombre de posts'
|
||||
print 'graph_category News'
|
||||
print 'graph_description Nombre de posts pour chaque newsgroup'
|
||||
(ng0, cng0, val0) = newsgroups[0]
|
||||
print '%s.label %s' % (cng0, ng0)
|
||||
print '%s.draw AREA' % cng0
|
||||
for (ng, cng, val) in newsgroups[1:]:
|
||||
print '%s.label %s' % (cng, ng)
|
||||
print '%s.draw STACK' % cng
|
||||
print 'total.label Total'
|
||||
else:
|
||||
# Envoi des valeurs
|
||||
total = 0
|
||||
for (ng, cng, val) in newsgroups:
|
||||
total += val
|
||||
print '%s.value %d' % (cng, val)
|
||||
print 'total.value %d' % total
|
Loading…
Add table
Add a link
Reference in a new issue