[Mailman-Users] Determine List Bandwidth

Bryan Carbonnell carbonnb at gmail.com
Sat Jan 21 21:55:59 CET 2006


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 :) That  and I haven't actually tried
this on my live server, just a backup of the post log file.

Let me know if you see anything that can be improved.

#!/usr/local/bin/python

import os
import re
import datetime
import commands

# Full path to the post log file
FILE = '/full/path/to/post'
# The list of interest
LISTNAME = 'listname'

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
        # 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

  print n, 'posts to %s yesterday' % LISTNAME
  print bw, ' bytes received'

  # Now check and see how many members are subscribed to the listi
  memb = 0
  op = commands.getoutput('/var/mailman/bin/list_members %s' % LISTNAME)
  #print op
  for line in op.splitlines():
      memb = memb + 1
  print memb, " members subscribed"

  # Now get rid of the mebers that are set to nomail
  op = commands.getoutput('/var/mailman/bin/list_members --nomail %s'
% LISTNAME)
  for line in op.splitlines():
      memb = memb - 1

  print memb, " members receiving list mail"

  # Now calculate the bandwidth
  tbw = bw * memb
  print "Approximately ", tbw, " bytes sent"

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