Applicable to:
- Plesk for Linux
Question
In the menu Subscriptions > example.com > Statistics (or just Statistics in Power User view), a big amount of POP3/IMAP traffic is shown.
Although, only one mail account is configured in the domains which belong to this subscription.
How to verify POP3/IMAP traffic statistics manually?
Answer
Note: the script takes mail statistics from /var/log/maillog*
files. To make it showing statistics for the last month, adjust maillog rotation in /usr/local/psa/etc/logrotate.conf
If Dovecot is used as POP3/IMAP
-
Connect to the server using SSH.
-
Check if the utility
bc
is installed on the server:# command -V bc
bc is /bin/bcIf the following output is returned,
bc
should be installed as per the following steps:# command -V bc
/bin/command: line 2: command: bc: not found-
For RHEL-based operating systems (CentOS, RHEL, CloudLinux):
# yum install bc
-
For Debian and Ubuntu:
# apt install bc
-
-
Download the script and unpack it:
# wget https://support.plesk.com/hc/en-us/article_attachments/360010836453/verify_pop3_imap_stats.tar.gz
# tar -zxvf verify_pop3_imap_stats.tar.gzClick here to see the content of the scriptCONFIG_TEXT: echo -e "Please specify the name of the subscription: "
read SUBSCRIPTION
MAILLOGS=`echo $(find /var/log/maillog.processed* -maxdepth 0 -type f)`; \
SUBSCRIPTIONID=`plesk db -Ne "select domains.id from domains where domains.name='$SUBSCRIPTION'"`; \
MONTH=`plesk db -Ne "select date_format(max(date), '%b') from DomainsTraffic"`; \
for EMAIL in `plesk db -Ne "SELECT CONCAT(mail_name,'@',name) FROM mail,domains WHERE domains.id=mail.dom_id and domains.id IN (select domains.id from domains where domains.id = '$SUBSCRIPTIONID' or domains.parentDomainId='$SUBSCRIPTIONID' or domains.webspace_id='$SUBSCRIPTIONID')"`; do \
RCVD=0; \
SENT=0; \
DATA_ROW=$(zgrep --no-filename $EMAIL $MAILLOGS | egrep "$MONTH" | egrep "service=pop3|service=imap" | egrep -v 127.0.0. | sed -n -e 's/.*rcvd=//; s/,.*sent=/ /p;' | cut -d ',' -f1); \
RCVD=$(echo "$DATA_ROW" | awk '\
{ SUM += $1} END \
{ print SUM }'); \
SENT=$(echo "$DATA_ROW" | awk '\
{ SUM += $2} END \
{ print SUM }'); \
if [ "$RCVD" -eq "0" ]; then \
echo -e "\nThere aren't POP3/IMAP stats for $EMAIL\n"; \
else \
echo -e "\nPOP3/IMAP stats for $EMAIL\n"; \
echo -e "Bytes:\nSENT=$SENT\nRCVD=$RCVD\n"; \
RCVD1=`echo "scale=3; $RCVD/1024+0.005"|bc -l`; \
SENT1=`echo "scale=3; $SENT/1024+0.005"|bc -l`; \
RCVD1=`echo "scale=2; $RCVD1/1"|bc -l`; \
SENT1=`echo "scale=2; $SENT1/1"|bc -l`; \
echo -e "KiloBytes:\nSENT=$SENT1\nRCVD=$RCVD1\n"; \
RCVD1=`echo "scale=3; $RCVD/1024/1024+0.005"|bc -l`; \
SENT1=`echo "scale=3; $SENT/1024/1024+0.005"|bc -l`; \
RCVD1=`echo "scale=2; $RCVD1/1"|bc -l`; \
SENT1=`echo "scale=2; $SENT1/1"|bc -l`; \
echo -e "MegaBytes:\nSENT=$SENT1\nRCVD=$RCVD1\n"; \
RCVD1=`echo "scale=3; $RCVD/1024/1024/1024+0.005"|bc -l`; \
SENT1=`echo "scale=3; $SENT/1024/1024/1024+0.005"|bc -l`; \
RCVD1=`echo "scale=2; $RCVD1/1"|bc -l`; \
SENT1=`echo "scale=2; $SENT1/1"|bc -l`; \
echo -e "GigaBytes:\nSENT=$SENT1\nRCVD=$RCVD1\n"; \
fi ; \
done -
Execute the script:
# ./verify_pop3_imap_stats.sh
For Courier is used as POP3/IMAP server
-
Connect to the server via SSH.
-
Download the script and unpack it:
# wget https://plesk.zendesk.com/hc/article_attachments/360011194774/courier_traffic.tar.gz
# tar xf courier_traffic.tar.gz -
Run the script with desired start and end dates and a domain name, if required
# ./courier_traffic.py --start 15-08 --end 22-08 --domain example.com --unit MB /var/log/maillog
Note: To see all available options run the script with
-h
option:./courier_traffic.py -h
Comments
2 comments
Is it possible to do the calculation for a period of time. On the web interface statistics does not have a time frame. How can we verify that using db and/or CLI
@Ops-team
In the Plesk interface, the traffic statistics are shown per-month (e.g in August, the statistics for this month are shown, the same for September, October etc.).
You can verify POP3/IMAP statistics in the Plesk database for the particular day(s) using the query like this:
==========
plesk db "select sum(pop3_imap_in+pop3_imap_out) from DomainsTraffic where date='2018-08-21' AND dom_id in (select id from domains where name='example.com')"
==========
The same is applicable to other columns in the table DomainsTraffic.
Please sign in to leave a comment.