qmailログ解析ツール導入(qmailanalog)

最終更新日: 2009.12.29

<<トップページ <<新着情報 <<質問BBS <<逆引き集 <<アンケート <<リンク集 <<サイト内検索 <<管理人へメール <<CentOSで自宅サーバー構築

■概要

qmailのログ解析ツールであるqmailanalogを導入する。
ここでは、毎日自動的に前日分のqmailログを解析して結果をメールサーバー管理者(postmaster)宛にメール送信するようにする。


■qmailanalogインストール

[root@fedora ~]# wget http://cr.yp.to/software/qmailanalog-0.70.tar.gz ← qmailanalogダウンロード

※最新版のURLはダウンロードページで確認すること

[root@fedora ~]# tar zxvf qmailanalog-0.70.tar.gz ← qmailanalog展開

[root@fedora ~]# cd qmailanalog-0.70 ← qmailanalog展開先ディレクトリへ移動

[root@fedora qmailanalog-0.7]# vi error.h ← error.h編集
extern int errno;
↓
#include<errno.h> ← 変更

[root@fedora qmailanalog-0.70]# make && make setup check ← qmailanalogインストール

[root@fedora qmailanalog-0.70]# cd ← qmailanalog展開先ディレクトリを抜ける

[root@fedora ~]# rm -rf qmailanalog-0.70 ← qmailanalog展開先ディレクトリを削除

[root@fedora ~]# rm -f qmailanalog-0.70.tar.gz ← ダウンロードしたqmailanalogを削除

[root@fedora ~]# echo "MANPATH /usr/local/qmailanalog/man" >> /etc/man.config
 ← manコマンドでqmailanalogコマンドのマニュアルを参照できるようにする

■qmailanalog設定

[root@fedora ~]# vi qmailanalog ← qmailanalog実行スクリプト作成
#!/bin/bash

PATH=$PATH:/usr/local/qmailanalog/bin:/var/qmail/bin
LANG=C
MAILLOG=`mktemp`
QMAILLOG=`mktemp`
QMAILREPORT=`mktemp`

# 統計対象設定
# ※不要な場合はコメントアウトする
zoverall=1 # 基本統計
#zddist=1 # メール遅送の集計
zdeferrals=1 # deferrals(配送が先延ばし)されたときの理由の集計
zfailures=1 # 失敗メールの理由
zrecipients=1 # 受け取り先の集計
#zrxdelay=1 # 受け取り先の集計(遅れ具合でソート)
zsenders=1 # 差し出し元の集計
#zsuids=1 # 差し出し元のUID集計
zrhosts=1 # 相手のホストの集計

# 統計出力用関数宣言
report(){
    echo "---------------------------------------------------" >> $QMAILREPORT
    $1 2>/dev/null < $QMAILLOG >> $QMAILREPORT
    echo "---------------------------------------------------" >> $QMAILREPORT
    echo "" >> $QMAILREPORT
}

# 前日分のログを抽出してqmailanalog向けに整形
grep ^"`date --date '1 days ago' +'%b %_d'`" /var/log/maillog.1 >> $MAILLOG
grep ^"`date --date '1 days ago' +'%b %_d'`" /var/log/maillog >> $MAILLOG
awk '{$1="";$2="";$3="";$4="";$5="";print}' < $MAILLOG | matchup > $QMAILLOG 5> /dev/null

# タイトル出力
echo "====================================================" >> $QMAILREPORT
echo "qmail statistics from qmailanalog" >> $QMAILREPORT
echo "Report Date: `date --date '1 days ago' +'%Y/%m/%d(%a)'`" >> $QMAILREPORT
echo "====================================================" >> $QMAILREPORT
echo "" >> $QMAILREPORT

# 各種統計出力
[ "$zoverall" = "1" ] && report zoverall
[ "$zddist" = "1" ] && report zddist
[ "$zdeferrals" = "1" ] && report zdeferrals
[ "$zfailures" = "1" ] && report zfailures
[ "$zrecipients" = "1" ] && report zrecipients
[ "$zrxdelay" = "1" ] && report zrxdelay
[ "$zsenders" = "1" ] && report zsenders
[ "$zsuids" = "1" ] && report zsuids
[ "$zrhosts" = "1" ] && report zrhosts

# 出力結果をpostmaster宛にメール送信
mail -s "qmail statistics" postmaster@`hostname -d` < $QMAILREPORT

# 一時ファイル削除(後始末)
rm -f $MAILLOG $QMAILLOG $QMAILREPORT

[root@fedora ~]# chmod 700 qmailanalog ← qmailanalog実行スクリプトへ実行権限付加

■qmailanalog確認

[root@fedora ~]# ./qmailanalog ← qmailanalog実行スクリプトを実行

以下のようなメールがpostmaster宛に届くことを確認

====================================================
qmail statistics from qmailanalog
Report Date: 2006/01/29(Sun)
====================================================

---------------------------------------------------
Basic statistics

qtime is the time spent by a message in the queue.

ddelay is the latency for a successful delivery to one recipient---the
end of successful delivery, minus the time when the message was queued.

xdelay is the latency for a delivery attempt---the time when the attempt
finished, minus the time when it started. The average concurrency is the
total xdelay for all deliveries divided by the time span; this is a good
measure of how busy the mailer is.

Completed messages: 36
Recipients for completed messages: 36
Total delivery attempts for completed messages: 36
Average delivery attempts per completed message: 1
Bytes in completed messages: 107518
Bytes weighted by success: 103122
Average message qtime (s): 0.233266

Total delivery attempts: 237
  success: 34
  failure: 2
  deferral: 201
Total ddelay (s): 7.196789
Average ddelay per success (s): 0.211670
Total xdelay (s): 37.719723
Average xdelay per delivery attempt (s): 0.159155
Time span (days): 0.791144
Average concurrency: 0.000551822
---------------------------------------------------

---------------------------------------------------
Reasons for deferral

One line per reason for deferral. Information on each line:
* del is the number of deliveries that ended for this reason.
* xdelay is the total xdelay on those deliveries.

del  xdelay  reason
201   32.10  maildrop: Unable to open mailbox./
---------------------------------------------------

---------------------------------------------------
Reasons for failure

One line per reason for delivery failure. Information on each line:
* del is the number of deliveries that ended for this reason.
* xdelay is the total xdelay on those deliveries.

del  xdelay  reason
  2    0.44  xxx.xxx.xxx.xxx does not like recipient./Remote host said: 550 5.1.1 ...
   User unknown/Giving up on xxx.xxx.xxx.xxx./
---------------------------------------------------

---------------------------------------------------
Recipients

One line per recipient. Information on each line:
* sbytes is the number of bytes successfully delivered to this recipient.
* mess is the number of messages sent to this recipient (success plus failure).
* tries is the number of delivery attempts (success, failure, deferral).
* xdelay is the total xdelay incurred by this recipient.

sbytes  mess  tries  xdelay  recipient
  5528     2      2    0.00  local.@linux.xxxxxxxx.com
     0     0     11    3.44  local.xxxxxxxx.com-accounting@xxxxxxxx.com
     0     0     11    3.01  local.xxxxxxxx.com-accounts@xxxxxxxx.com
     0     0     11    2.00  local.xxxxxxxx.com-admin@xxxxxxxx.com
     0     0     11    1.96  local.xxxxxxxx.com-administrator@xxxxxxxx.com
     0     0     11    2.87  local.xxxxxxxx.com-advertising@xxxxxxxx.com
     0     0     11    3.44  local.xxxxxxxx.com-billing@xxxxxxxx.com
     0     0     11    2.88  local.xxxxxxxx.com-contact@xxxxxxxx.com
     0     0     42    3.30  local.xxxxxxxx.com-fedora@xxxxxxxx.com
     0     0      6    1.45  local.xxxxxxxx.com-help@xxxxxxxx.com
     0     0     11    2.57  local.xxxxxxxx.com-home@xxxxxxxx.com
     0     0     11    2.83  local.xxxxxxxx.com-majordomo@xxxxxxxx.com
     0     0     54    2.35  local.xxxxxxxx.com-test-ml-ctl@xxxxxxxx.com
 25781    12     12    1.00  local.xxxxxxxx.com-webmaster@xxxxxxxx.com
 12390     9      9    0.81  local.root@fedora.xxxxxxxx.com
     0     2      2    0.44  remote.xxxxxxxx@xxxxxxxx.com
---------------------------------------------------

---------------------------------------------------
Senders

One line per sender. Information on each line:
* mess is the number of messages sent by this sender.
* bytes is the number of bytes sent by this sender.
* sbytes is the number of bytes successfully received from this sender.
* rbytes is the number of bytes from this sender, weighted by recipient.
* recips is the number of recipients (success plus failure).
* tries is the number of delivery attempts (success, failure, deferral).
* xdelay is the total xdelay incurred by this sender.

mess  bytes  sbytes  rbytes  recips  tries    xdelay  sender
   1   1088    1088    1088       1      1  0.136416  0/
   6   6904    6904    6904       6      6  0.492125  0/
   1   1197    1197    1197       1      1  0.278422  1011/
   2   4616    4616    4616       2      2  0.132643  1011/<>
   6   7557    7557    7557       6      6  0.275969  1011/
   2   5528    5528    5528       2      2  0.001703  1017/<#@[]>
   4   8794    4398    8794       4      4  0.619723  1019/<>
---------------------------------------------------

---------------------------------------------------
Recipient hosts

One line per recipient host. Information on each line:
* sbytes is the number of bytes successfully delivered to this host.
* mess is the number of messages sent to this host (success plus failure).
* tries is the number of delivery attempts (success, failure, deferral).
* xdelay is the total xdelay incurred by this host.

sbytes  mess  tries  xdelay  host
 25781    12    213   33.11  xxxxxxxx.com
     0     2      2    0.44  xxxxxxxx.com
 17918    11     11    0.81  linux.xxxxxxxx.com
---------------------------------------------------

■qmailanalog定期自動実行設定

[root@fedora ~]# mv qmailanalog /etc/cron.daily/ ← qmailanalog実行スクリプトを毎日自動実行されるディレクトリへ移動



▲このページのトップへ戻る

LPIロゴ Copyright© 2004-2009 fallenangels, All rights reserved.
ご自由にリンクしてください(連絡は不要です)
本ページへのご意見・ご要望、誤字・脱字・リンク切れ等のご連絡はこちらからお願いします