[Mailman-Users] Determine List Bandwidth
Bryan Carbonnell
carbonnb at gmail.com
Sun Jan 22 19:27:58 CET 2006
On 21/01/06, Bryan Carbonnell <carbonnb at gmail.com> wrote:
> On 19/01/06, Bryan Carbonnell <carbonnb at gmail.com> wrote:
> > Is there any facility within Mailman to determine the bandwidth used
> > by a specific list?
>
> Since there is no inbuilt way to do this with Mailman, I wrote a
> Python script to parse the POST log and take the size of the posts to
> a specific list and then multiply that by the number of active
> subscribers at the time this script was run.
>
> This gets the "stats" from the day before the script is run.
>
> I also said that I would let everyone know if I found a way to do it,
> here is the script.
>
> Keep in mind that I don't know Python (I spent an awful lot of time
> googling and read Python Docs :)
This is an updated version, which now includes that facility to e-mail
the results.
I have also tried it on my server and it works fine for me. I think
that some of the commands or modules require Python 2.3 or higher.
I have set it up as a cron job, so tomorrow will be the really big
test. If I get an e-mail with the stats, then I know my first Python
program really does work :-)
Again, let me know if you see any way this can be improved.
Also, is there someplace on Sourceforge that I can post this, so that
everyone can "enjoy" it too?
#!/usr/local/bin/python
import os
import re
import datetime
import commands
import smtplib
from email.MIMEText import MIMEText
# Full path to the post log file
FILE = '/var/log/mailman/post'
# The list of interest
LISTNAME = 'LISTNAME'
# E-Mail Address of sender of e-mail
SENDER = "MAILMAN at YOURSERVER.COM"
RECPTS = "SOMEONE at YOURISP.COM"
# Prefix of the Mailman Installation
PREFIX = '/var/mailman'
# No changes should be required below here
# Setup some default values
n = 0
bw = 0
# Get yesterdays date
yesterday = datetime.datetime.today() - datetime.timedelta(days=1)
# check for existence of file
if os.path.exists(FILE):
# open file if it exists
input = open(FILE, 'r')
#Loop through file line by line
for line in input:
# Check to see if we are on a record from yesterday
restr = yesterday.strftime("%b %d ") + "\d\d:\d\d:\d\d" \
+ yesterday.strftime(" %Y")
if re.findall(r'%s' % restr, line):
# Check to see if the listname is in the line
if re.findall(r'%s' % LISTNAME, line):
ret = re.findall(r'size=\d*', line)
ret2 = re.findall(r'\d*', ret[0])
bw = bw + long(ret2[5])
n = n + 1
# Now check and see how many members are subscribed to the listi
membs = 0
op = commands.getoutput('%s/bin/list_members %s' % (PREFIX, LISTNAME))
for line in op.splitlines():
membs = membs + 1
# Now count mebers that are set to nomail
membn = 0
op = commands.getoutput('%s/bin/list_members --nomail %s' % (PREFIX,LISTNAME))
for line in op.splitlines():
membn = membn + 1
# Now calculate members that are receiving mail
membt = membs - membn
# Now calculate the bandwidth
tbw = bw * membt
# Now lets send an e-mail
# Build the body text
msg = '%s posts to %s on %s\n' %(n, LISTNAME, yesterday.strftime('%b %d, %Y'))
msg = msg + '%s bytes received\n' % bw
msg = msg + '%s members subscribed\n' % membs
msg = msg + '%s members receiving list mail\n' % membt
msg = msg + "Approximately %s bytes sent\n" % tbw
msgMIME = MIMEText(msg)
msgMIME['Subject'] = 'Bandwidth of %s - %s' % (LISTNAME,
yesterday.strftime('%b %d, %Y'))
msgMIME['From'] = SENDER
msgMIME['To'] = RECPTS
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP()
s.connect()
s.sendmail(SENDER, RECPTS, msgMIME.as_string())
s.close()
else:
print "log file not found"
--
Bryan Carbonnell - carbonnb at gmail.com
Life's journey is not to arrive at the grave safely in a well
preserved body, but rather to skid in sideways, totally worn out,
shouting "What a great ride!"
More information about the Mailman-Users
mailing list