SpamAssassin的统计日志
2008-03-24 13:38:06
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://bingyi.blog.51cto.com/261731/67751 |
之前折腾了一个礼拜,终于把SpamAssassin+Postfix+MySQL搞定,跑在一台双5130,8G内存的机器上,那速度相当惊人(这个还干别的用,光一个邮件网关我可没这么多预算)。
闲下时间来看了看MySQL中的数据,发现这网关还真厉害。每天接收到的邮件有6万多封,其中5万多封被识别为垃圾邮件(我的分数阀值是8.0,如果设得稍低些会给更多的邮件判刑)。
运行到现在已经有半个多月了,在得到了用户的反馈之后,及时的将漏判、误判邮件交给Bayes学习,到现在基本上已经没什么误判的了,但是漏判的还是很多。一日老大向我要这个系统的具体数据,来评定这个系统的效率,我给了老大一份当前的总处理邮件数和已判刑的垃圾邮件数。
突然冒出个想法,如果多建个表,每天甚至每小时将awl的数据汇总到其中,那就可以画出邮件系统处理邮件数量的曲线了。
于是……
偶们的系统是Ubuntu,在MySQL中建了个表:
CREATE TABLE `mail_log` (
`logid` int(11) NOT NULL auto_increment, `mail_all` int(11) NOT NULL default '0', `spam_all` int(11) NOT NULL default '0', `logdate` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`logid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 在系统中做了个计划任务,每半小时将awl中的数据插入到这个表中。
insert into mail_log (add_all,add_spam,mail_all,mail_spam,bayes_seen,bayes_token,logdate) values((select count(*) from awl),(select count(*) from awl where totscore/count>8.0),(select sum(count) from awl),(select sum(count) from awl where totscore/count>8.0),now());
在这个SQL中有个问题,就是以(总分/总数)和阀值来做比较,这样使得数据不准,本来想把SpamAssassin的源代码给该了,后来想想算了,这个比较方法在统计学上还是行得通的。
为了把这个东西表现的更直观,做了个PHP页面,用GD2画了张图:
<?php
require_once("config.php"); require("sys.php"); $link=mysql_connect($db_host,$db_user,$db_pass); mysql_select_db(spam); $sql="select * from mail_log where logdate like '".substr(date("Y-m-d H:i:s", time()),0,10)."%' order by logid asc"; $result=mysql_query($sql); $img = imagecreatetruecolor(1080,800); $bgcol = imagecolorallocate($img,60,60,60); $linecol = imagecolorallocate($img,188,188,188); $allcol = imagecolorallocate($img,0,255,0); $spamcol= imagecolorallocate($img,255,0,0); imagefill($img,0,0,$bgcol); for ($i=40;$i<780;$i+=20) { imagestring($img,3,5,$i-12,(760-$i)/20*100,$linecol); imageline($img,0,$i,1260,$i,$linecol); } for ($i=40;$i<=1060;$i+=20) { imageline($img,$i,40,$i,760,$linecol); } $start_num=0; $i=40; imagesetthickness($img,18); $cur_num=0; while($row=mysql_fetch_array($result)) { if ($start_num==0) { $start_num=$row[mail_all]; $cur_num=$row[mail_all]; } imageline($img,$i+9,760-($row[mail_all]-$cur_num)/5,$i+9,760,$allcol); $i=$i+20; imagestring($img,1,$i-19,750-($row[mail_all]-$cur_num)/5,$row[mail_all]-$cur_num,$allcol); $cur_num=$row[mail_all]; } imagestring($img,5,400,150,"Mail Total:".$cur_num,$allcol); $link=mysql_connect($db_host,$db_user,$db_pass); mysql_select_db(spam); $result=mysql_query("select * from mail_log order by logid asc"); $total=mysql_num_rows($result); $sql="select * from mail_log where logdate like '".substr(date("Y-m-d H:i:s", time()),0,10)."%' order by logid asc"; $result=mysql_query($sql); $start_num=0; $i=40; $cur_num=0; imagesetthickness($img,18); while($row=mysql_fetch_array($result)) { if ($start_num==0) { $start_num=$row[mail_spam]; $cur_num=$row[mail_spam]; } imageline($img,$i+9,760-($row[mail_spam]-$cur_num)/5,$i+9,760,$spamcol); $i=$i+20; imagestring($img,1,$i-19,750-($row[mail_spam]-$cur_num)/5,$row[mail_spam]-$cur_num,$spamcol); imagestring($img,2,$i-19,760,substr($row[logdate],11,2),$spamcol); $cur_num=$row[mail_spam]; } imagestring($img,5,400,100,"Spam Total:".$cur_num,$spamcol); header("Content-type: image/png"); imagepng($img); imagedestroy($img); ?> 这样当天的图标就出来了,自己还算得意……
本文出自 “冰封王座” 博客,请务必保留此出处http://bingyi.blog.51cto.com/261731/67751 本文出自 51CTO.COM技术博客 |
附件下载:
结果图
结果图

bingyizy
博客统计信息
热门文章
最新评论
友情链接