Premessa
In questo documento spiegherò come sfruttare il noto MRTG per monitorare l’attività di Qmail. Sebbene MRTG sia stato realizzato per ottenere delle statistiche sulle condizioni di una rete è anche possibile sfruttarlo, grazie ad un modulo, per monitorare le funzioni vitali di un mail server che usa Qmail.
Risorse Hardware e Software
Per il mio scopo ho utilizzato un vecchio pc, composto da un processore Pentium 166MMX, 32MB di RAM, Hard Disk da 2GB ide, scheda di rete pci 3Com 905-b 10/100Mbit., dal lato software ho utilizzato Slackware 10, Qmail e MRTG.
Procuriamoci i pacchetti necessari
Per facilitarvi nell’impresa vi ho messo a disposizione il mio spazio web, da dove potere prelevare i pacchetti necessari senza andare in giro per la rete magari non trovando le versioni utilizzate in questo documento. Di seguito trovate i link per scaricare i pacchetti:
http://www.webalice.it/alepensato/qmailmrtg.tar.gz
http://www.webalice.it/alepensato/apache-mrtg/apache_1.3.27.tar.gz
http://www.webalice.it/alepensato/apache-mrtg/mrtg-2.10.13.tar.gz
http://www.webalice.it/alepensato/apache-mrtg/gd-2.0.26.tar.gz
http://www.webalice.it/alepensato/apache-mrtg/perl-addons.zip
Compilazione e installazione dei software sorgenti (come root)
Installazione delle librerie GD
Il primo software che installeremo sono le librerie GD, che insieme alle librerie per JPEG, PNG, GIF, permetteranno al software MRTG di creare i grafici relative allo stato del nostro webserver. Eseguite questi comandi passo passo:
cd /tar tar zxvf gd* cd gd* ./configure make && make install ldconfig
Installazione di MRTG
Questo pacchetto, una volta installato, si occuperà di creare i grafici andando a sfruttare il modulo Apache-MRTG che a sua volta consulta il modulo server-status di Apache, per ottenere le informazioni relative al webserver. Eseguite questi comandi passo passo:
cd /tar tar zxvf mrtg* cd mrtg* ./configure –prefix=/usr/local/mrtg make && make install
Installazione del pacchetto Perl-Addons
All’interno del file zip troverete altri pacchetti in formato tar.gz prelevati da CPAN e necessari a far funzionare MRTG, in realtà è solo libwww-perl che si lega a MRTG, ma a sua volta necessita di altri pacchetti per poter funzionare quindi dobbiamo installarli. Seguite l’ordine di installazione dei pacchetti per evitare malfunzionamenti dovuti alle dipendenze tra essi:
cd /tar unzip perl-addons.zip cd perl-addons tar zxvf Convert* cd Convert* perl Makefile.PL && make && make install tar zxvf Period* cd Period* perl Makefile.PL && make && make install tar zxvf DB* cd DB* perl Makefile.PL && make && make install tar zxvf Digest-1* cd Digest-1* perl Makefile.PL && make && make install tar zxvf HTML-Tagset* cd HTML-Tagset* perl Makefile.PL && make && make install tar zxvf HTML-Template* cd HTML-Template* perl Makefile.PL && make && make install tar zxvf HTML-Parser* cd HTML-Parser* perl Makefile.PL && make && make install tar zxvf MIME*3* cd MIME*3* perl Makefile.PL && make && make install tar zxvf MIME*P* cd MIME*P* perl Makefile.PL && make && make install tar zxvf Time* cd Time* perl Makefile.PL && make && make install tar zxvf URI* cd URI* perl Makefile.PL && make && make install tar zxvf libwww* cd libwww* perl Makefile.PL && make && make install
Installazione di Apache
A questo punto dobbiamo installare Apache, il webserver. La procedura di seguito è valida per una installazione minima necessaria per realizzare il nostro scopo, ma se si vuole si possono abilitare altri moduli in base alle proprie necessità . Seguite i seguenti comandi:
cd /tar tar zxvf apache_* cd apache_* ./configure --prefix=/usr/local/apache --enable-module=rewrite --enable-module=status \ --enable-shared=max make && make install mkdir /usr/local/apache/etc
Installazione del modulo Qmail-MRTG
A questo punto siamo pronti per modificare i file di configurazione in modo da poter ottenere i grafici relativi allo stato del webserver. Seguite i seguenti comandi:
cd /tar tar zxvf qmailmrtg.tar.gz cd qmailmrtg* make && make install mkdir /usr/local/apache/htdocs/qmailmrtg vi qmail.mrtg.cfg
Cambiate la sigla FQDN con il nome DNS del vostro server mail, e impostate le corrette diretcory dove si trovano i file di log di Qmail
WorkDir: /usr/local/apache/htdocs/qmailmrtg ############################################################# Title[msg]: Messages - server.home.local MaxBytes[msg]: 10000 AbsMax[msg]: 20000 Options[msg]: gauge Target[msg]: `/usr/local/bin/qmailmrtg7 m /var/log/qmail` PageTop[msg]: server.home.local Messages ShortLegend[msg]: msg YLegend[msg]: msg/hour Legend1[msg]: Total Msg LegendI[msg]: Deliveries: LegendO[msg]: Attempts: WithPeak[msg]: ymwd XSize[msg]: 350 YSize[msg]: 150 #------------------------------------------------------------------- Title[queue-size]: Queue Size - server.home.local MaxBytes[queue-size]: 10000 AbsMax[queue-size]: 100000 Options[queue-size]: gauge Target[queue-size]: `/usr/local/bin/qmailmrtg7 q /var/qmail/queue` PageTop[queue-size]: server.home.local Queue Size ShortLegend[queue-size]: Msg YLegend[queue-size]: msg total Legend1[queue-size]: msg LegendI[queue-size]: msg LegendO[queue-size]: unprocessed msg: WithPeak[queue-size]: ymwd XSize[queue-size]: 350 YSize[queue-size]: 150 #------------------------------------------------------------------- #Title[clamd]: clamd - server.home.local #MaxBytes[clamd]: 10000 #AbsMax[clamd]: 100000 #Options[clamd]: gauge #Target[clamd]: `/usr/local/bin/qmailmrtg7 C /var/log/clamd` #PageTop[clamd]: server.home.local ClamAV #ShortLegend[clamd]: Msg #YLegend[clamd]: viri/hour #Legend1[clamd]: a #LegendI[clamd]: found #LegendO[clamd]: errors: #WithPeak[clamd]: ymwd #XSize[clamd]: 350 #YSize[clamd]: 150 #------------------------------------------------------------------- #Title[spamd]: spamd - server.home.local #MaxBytes[spamd]: 10000 #AbsMax[spamd]: 100000 #Options[spamd]: gauge #Target[spamd]: `/usr/local/bin/qmailmrtg7 S /var/log/spamd` #PageTop[spamd]: server.home.local SpamAssassin #ShortLegend[spamd]: Msg #YLegend[spamd]: spam/hour #Legend1[spamd]: a #LegendI[spamd]: clean #LegendO[spamd]: spam: #WithPeak[spamd]: ymwd #XSize[spamd]: 350 #YSize[spamd]: 150 #------------------------------------------------------------------- Title[concurrency]: Local/Remote Concurrency - server.home.local MaxBytes[concurrency]: 500 AbsMax[concurrency]: 10000 Options[concurrency]: gauge Target[concurrency]: `/usr/local/bin/qmailmrtg7 c /var/log/qmail` PageTop[concurrency]: server.home.local - Local/Remote Concurrency ShortLegend[concurrency]: concurrency YLegend[concurrency]: max concurrency Legend1[concurrency]: concurrency LegendI[concurrency]: local LegendO[concurrency]: remote WithPeak[concurrency]: ymwd XSize[concurrency]: 350 YSize[concurrency]: 150 #------------------------------------------------------------------- Title[messstatus]: Message Status - server.home.local MaxBytes[messstatus]: 10000 AbsMax[messstatus]: 100000 Options[messstatus]: gauge Target[messstatus]: `/usr/local/bin/qmailmrtg7 s /var/log/qmail` PageTop[messstatus]: server.home.local - Message Status ShortLegend[messstatus]: msg YLegend[messstatus]: msg/hour Legend1[messstatus]: msg LegendI[messstatus]: success LegendO[messstatus]: failures WithPeak[messstatus]: ymwd XSize[messstatus]: 350 YSize[messstatus]: 150 #------------------------------------------------------------------- Title[bits]: Bits Transfered - server.home.local MaxBytes[bits]: 1540000 AbsMax[bits]: 100000000 Options[bits]: gauge Target[bits]: `/usr/local/bin/qmailmrtg7 b /var/log/qmail` PageTop[bits]: server.home.local - Bits Transfered ShortLegend[bits]: bits YLegend[bits]: bits/sec Legend1[bits]: bits LegendI[bits]: bits LegendO[bits]: bits WithPeak[bits]: ymwd XSize[bits]: 350 YSize[bits]: 150 #------------------------------------------------------------------- Title[smtp]: SMTP Concurrency - server.home.local MaxBytes[smtp]: 100 AbsMax[smtp]: 500 Options[smtp]: gauge Target[smtp]: `/usr/local/bin/qmailmrtg7 t /var/log/qmail/smtpd` PageTop[smtp]: server.home.local - SMTP Concurrency ShortLegend[smtp]: SMTP YLegend[smtp]: max SMTP Legend1[smtp]: SMTP LegendI[smtp]: SMTP LegendO[smtp]: SMTP WithPeak[smtp]: ymwd XSize[smtp]: 350 YSize[smtp]: 150 #-------------------------------------------------------------------
Title[smtpad]: SMTP Totals - server.home.local MaxBytes[smtpad]: 1000 AbsMax[smtpad]: 100000 Options[smtpad]: gauge Target[smtpad]: `/usr/local/bin/qmailmrtg7 a /var/log/qmail/smtpd` PageTop[smtpad]: server.home.local - SMTP Totals ShortLegend[smtpad]: SMTP YLegend[smtpad]: SMTP/hour Legend1[smtpad]: SMTP LegendI[smtpad]: Allow LegendO[smtpad]: Deny WithPeak[smtpad]: ymwd XSize[smtpad]: 350 YSize[smtpad]: 150 #------------------------------------------------------------------- Title[pop3]: POP3 Concurrency - server.home.local MaxBytes[pop3]: 100 AbsMax[pop3]: 500 Options[pop3]: gauge Target[pop3]: `/usr/local/bin/qmailmrtg7 t /var/log/qmail/pop3d` PageTop[pop3]: server.home.local POP3 Concurrency ShortLegend[pop3]: POP3 YLegend[pop3]: max POP3 Legend1[pop3]: POP3 LegendI[pop3]: POP3 LegendO[pop3]: POP3 WithPeak[pop3]: ymwd XSize[pop3]: 350 YSize[pop3]: 150
#------------------------------------------------------------------- Title[pop3ad]: POP3 Totals - server.home.local MaxBytes[pop3ad]: 1000 AbsMax[pop3ad]: 100000 Options[pop3ad]: gauge Target[pop3ad]: `/usr/local/bin/qmailmrtg7 a /var/log/qmail/pop3d` PageTop[pop3ad]: server.home.local - POP3 Totals ShortLegend[pop3ad]: POP3 YLegend[pop3ad]: POP3/hour Legend1[pop3ad]: POP3 LegendI[pop3ad]: Allow LegendO[pop3ad]: Deny WithPeak[pop3ad]: ymwd XSize[pop3ad]: 350 YSize[pop3ad]: 150 #------------------------------------------------------------------- Title[cpu0]: CPU 0 Usage - server.home.local MaxBytes[cpu0]: 100 AbsMax[cpu0]: 1000 Options[cpu0]: bits Target[cpu0]: `/usr/bin/awk '/cpu0 /{print $2+$3; print $2+$3+$4; print "quite some time"; print "home"}'</proc/stat` PageTop[cpu0]: CPU 0 Usage - server.home.local ShortLegend[cpu0]: %x100 Ylegend[cpu0]: %x100 LegendI[cpu0]: user: LegendO[cpu0]: total: Legend1[cpu0]: Time spent in user mode Legend2[cpu0]: Time spent in user mode + time spent in system mode Legend3[cpu0]: Maximum occurance of time spent in user mode Legend4[cpu0]: Maximum occurance of (time spent in user mode + time spent in system mode) XSize[cpu0]: 350 YSize[cpu0]: 150
#------------------------------------------------------------------- Title[eth0]: eth0 bits - server.home.local Options[eth0]: bits Target[eth0]: `grep eth0 /proc/net/dev | sed 's/eth0://' | awk '{print $1; print $9; print ""; print ""}'` PageTop[eth0]: eth0 bits - server.home.local MaxBytes[eth0]: 100000000 Ylegend[eth0]: bits ShortLegend[eth0]: bits XSize[eth0]: 350 YSize[eth0]: 150 Legend1[eth0]: bits LegendI[eth0]: input LegendO[eth0]: output WithPeak[eth0]: ymwd #------------------------------------------------------------------- Title[eth0p]: eth0 packets - server.home.local Options[eth0p]: bits Target[eth0p]: `grep eth0 /proc/net/dev | sed 's/eth0://' | awk '{print $2; print $10; print ""; print ""}'` PageTop[eth0p]: eth0 packets - server.home.local MaxBytes[eth0p]: 100000000 Ylegend[eth0p]: bits ShortLegend[eth0p]: bits XSize[eth0p]: 350 YSize[eth0p]: 150 Legend1[eth0p]: bits LegendI[eth0p]: input LegendO[eth0p]: output WithPeak[eth0p]: ymwd #------------------------------------------------------------------- Title[mem]: memory used/free - server.home.local Target[mem]: `free | /usr/bin/awk '/Mem: /{print $3*1000; print $4*1000; print ""; print ""}'` PageTop[mem]: memory used/free - server.home.local Options[mem]: gauge MaxBytes[mem]: 50000000000 Ylegend[mem]: mem ShortLegend[mem]: mem XSize[mem]: 350 YSize[mem]: 150 Legend1[mem]: mem LegendI[mem]: used LegendO[mem]: free WithPeak[mem]: ymwd
#------------------------------------------------------------------- Title[swap]: memory swap - server.home.local Target[swap]: `free | /usr/bin/awk '/Swap: /{print $3; print $3; print ""; print ""}'` PageTop[swap]: memory swap - server.home.local Options[swap]: gauge MaxBytes[swap]: 500000 Ylegend[swap]: mem ShortLegend[swap]: mem XSize[swap]: 350 YSize[swap]: 150 Legend1[swap]: mem LegendI[swap]: swap LegendO[swap]: swap WithPeak[swap]: ymwd #------------------------------------------------------------------- Title[load]: system load - server.home.local Target[load]: `uptime | sed 's/,//g' | awk '{print $10*100; print $11*100 ; print ""}'` PageTop[load]: system load - server.home.local Options[load]: gauge MaxBytes[load]: 100000 Ylegend[load]: load x100 ShortLegend[load]: load XSize[load]: 350 YSize[load]: 150 Legend1[load]: load LegendI[load]: 5min LegendO[load]: 15min WithPeak[load]: ymwd
#------------------------------------------------------------------- #Title[ftpd]: ftpd concurrency - server.home.local #MaxBytes[ftpd]: 100 #AbsMax[ftpd]: 500 #Options[ftpd]: gauge #Target[ftpd]: `/usr/local/bin/qmailmrtg7 t /var/log/ftpd` #PageTop[ftpd]: server.home.local - ftpd (concurrency) #ShortLegend[ftpd]: ftpd #YLegend[ftpd]: ftpd #Legend1[ftpd]: ftpd #LegendI[ftpd]: ftpd: #LegendO[ftpd]: #WithPeak[ftpd]: ymwd #XSize[ftpd]: 350 #YSize[ftpd]: 150 #------------------------------------------------------------------- #Title[ftpdad]: ftpd allow/deny - server.home.local #MaxBytes[ftpdad]: 1000 #AbsMax[ftpdad]: 10000 #Options[ftpdad]: gauge #Target[ftpdad]: `/usr/local/bin/qmailmrtg7 a /var/log/ftpd` #PageTop[ftpdad]: server.home.local - ftpd (allow/deny) #ShortLegend[ftpdad]: ftpd #YLegend[ftpdad]: ftpd #Legend1[ftpdad]: ftpd #LegendI[ftpdad]: Allow: #LegendO[ftpdad]: Deny: #WithPeak[ftpdad]: ymwd #XSize[ftpdad]: 350 #YSize[ftpdad]: 150 #-------------------------------------------------------------------
#Title[smtps]: SMTP SSL Concurrency - server.home.local #MaxBytes[smtps]: 100 #AbsMax[smtps]: 500 #Options[smtps]: gauge #Target[smtps]: `/usr/local/bin/qmailmrtg7 t /var/log/qmail/smtpds` #PageTop[smtps]: server.home.local - SMTP Concurrency #ShortLegend[smtps]: SMTP #YLegend[smtps]: max SMTP #Legend1[smtps]: SMTP #LegendI[smtps]: SMTP #LegendO[smtps]: SMTP #WithPeak[smtps]: ymwd #XSize[smtps]: 350 #YSize[smtps]: 150 #------------------------------------------------------------------- #Title[smtpsad]: SMTP SSL Totals - server.home.local #MaxBytes[smtpsad]: 1000 #AbsMax[smtpsad]: 100000 #Options[smtpsad]: gauge #Target[smtpsad]: `/usr/local/bin/qmailmrtg7 a /var/log/qmail/smtpds` #PageTop[smtpsad]: server.home.local - SMTP Totals #ShortLegend[smtpsad]: SMTP #YLegend[smtpsad]: SMTP/hour #Legend1[smtpsad]: SMTP #LegendI[smtpsad]: Allow #LegendO[smtpsad]: Deny #WithPeak[smtpsad]: ymwd #XSize[smtpsad]: 350 #YSize[smtpsad]: 150
#------------------------------------------------------------------- #Title[pop3s]: POP3 SSL Concurrency - server.home.local #MaxBytes[pop3s]: 100 #AbsMax[pop3s]: 500 #Options[pop3s]: gauge #Target[pop3s]: `/usr/local/bin/qmailmrtg7 t /var/log/qmail/pop3ds` #PageTop[pop3s]: server.home.local POP3 Concurrency #ShortLegend[pop3s]: POP3 #YLegend[pop3s]: max POP3 #Legend1[pop3s]: POP3 #LegendI[pop3s]: POP3 #LegendO[pop3s]: POP3 #WithPeak[pop3s]: ymwd #XSize[pop3s]: 350 #YSize[pop3s]: 150 #------------------------------------------------------------------- #Title[pop3sad]: POP3 SSL Totals - server.home.local #MaxBytes[pop3sad]: 1000 #AbsMax[pop3sad]: 100000 #Options[pop3sad]: gauge #Target[pop3sad]: `/usr/local/bin/qmailmrtg7 a /var/log/qmail/pop3ds` #PageTop[pop3sad]: server.home.local - POP3 Totals #ShortLegend[pop3sad]: POP3 #YLegend[pop3sad]: POP3/hour #Legend1[pop3sad]: POP3 #LegendI[pop3sad]: Allow #LegendO[pop3sad]: Deny #WithPeak[pop3sad]: ymwd #XSize[pop3sad]: 350 #YSize[pop3sad]: 150
Modificate anche il file index.html seguendo le stesse istruzioni:
vi index.html
Copiate entrambi i file /index.html e qmail.mrtg.cfg) nella directory /usr/local/apache/htdocs/qmailmrtg
cp qmail.mrtg.cfg index.html /usr/local/apache/htdocs/qmailmrtg/
Adesso lanciamo MRTG in modo che crei i grafici per la prima volta, eseguite lo stesso comando per tre volte:
/usr/local/mrtg/bin/mrtg /usr/local/apache/htdocs/qmailmrtg/qmail.mrtg.cfg
Puntando con un qualsiasi browser grafico all’URL del nostro webserver http://localhost/qmailmrtg/ ci troveremo davanti ad una pagina riepilogativa comprendente dei grafici relativi al webserver come: Uptime, CPULoad, Total Access, Child Status, Idle Server, ecc.