How To: Calculate IMAP/POP3 bandwidth usage per email account in DA

  Control Panel, Email

Use the following script to see POP3/IMAP usage in bytes (it reads /var/log/maillog file and outputs the bandwidth usage for every email user (period of time counted depends on logrotate))

#!/bin/sh
for u in `ls /usr/local/directadmin/data/users`; do
{
echo "$u";
echo -n "POP3: "
grep "($u)" /var/log/maillog | awk '/pop3/ && /retr/ && /Disconnected/ {print $11}' | cut -d/ -f2 | cut -d, -f1 | awk '{sum+=$1} END {printf("%0.0f\n", sum)}'
echo -n "IMAP: "
grep "($u)" /var/log/maillog | awk '/imap/ && /bytes/ && /Disconnected/ {print $10}' | cut -d/ -f2 | cut -d, -f1 | awk '{sum+=$1} END {printf("%0.0f\n", sum)}'
for d in `cat /usr/local/directadmin/data/users/$u/domains.list`; do
{
for eu in `cat /etc/virtual/$d/passwd | cut -d: -f1`; do
{
echo "$eu@$d";
echo -n "POP3: "
grep "($eu@$d)" /var/log/maillog | awk '/pop3/ && /retr/ && /Disconnected/ {print $11}' | cut -d/ -f2 | cut -d, -f1 | awk '{sum+=$1} END {printf("%0.0f\n", sum)}'
echo -n "IMAP: "
grep "($eu@$d)" /var/log/maillog | awk '/imap/ && /bytes/ && /Disconnected/ {print $10}' | cut -d/ -f2 | cut -d, -f1 | awk '{sum+=$1} END {printf("%0.0f\n", sum)}'
}
done;
}
done;
}
done;

exit 0;

If we need to calculate the usage only for one DA user, we just need to replace for u in `ls /usr/local/directadmin/data/users`; do

with:

for u in username; do

whereis username – DA User Name.

The output will be as below:

ac@fusipim.com
POP3: 56129009
IMAP: 0
ben@fusipim.com
POP3: 823443016
IMAP: 0
cheng@fusipim.com
POP3: 83446192
IMAP: 0
chua@fusipim.com
POP3: 3021930
IMAP: 0
crystal@fusipim.com
POP3: 163137778
IMAP: 0
david@fusipim.com
POP3: 318847757
IMAP: 0
design@fusipim.com
POP3: 502527532
IMAP: 0
design2@fusipim.com
POP3: 327430906
IMAP: 0
export@fusipim.com
POP3: 1292318921