語文基礎日誌

如何用SARG日誌分析器來分析

本文已影響 2.46W人 

SARG是一款基於網絡的工具,它可以分析Squid日誌,並以更詳細的方式展示分析。系統管理員可以利用SARG來監視哪些網站被訪問了,並跟蹤訪問量最大的網站和用戶。本文包含了SARG配置工作。SARG提供了很多有用的特性,但是分析一個原始Squid日誌文件並不直接。比如,你如何分析下面Squid日誌中的時間戳和數字?

如何用SARG日誌分析器來分析

1404788984.429 1162 TCP_MISS/302 436 GET - DIRECT/ text/html

1404788985.046 12416 TCP_MISS/200 4169 CONNECT - DIRECT/ -

1404788986.124 174 TCP_MISS/200 955 POST - DIRECT/ application/ocsp-response

1404788989.738 342 TCP_MISS/200 3890 CONNECT - DIRECT/ -

1404788989.757 226 TCP_MISS/200 942 POST - DIRECT/ application/ocsp-response

1404788990.839 3939 TCP_MISS/200 78944 CONNECT - DIRECT/ -

1404788990.846 2148 TCP_MISS/200 118947 CONNECT - DIRECT/ -

1404788990.849 2151 TCP_MISS/200 76809 CONNECT - DIRECT/ -

1404788991.140 611 TCP_MISS/200 110073 CONNECT - DIRECT/ –

我們使用yum來安裝安裝必要的依賴。

# yum install gcc make wget httpd crond

在啓動時加載必要的服務

# service httpd start; service crond start

# chkconfig httpd on; chkconfig crond on

現在我們下載並解壓SARG

上一節教程中,我們展示瞭如何在CentOS上使用Squid配置透明代理。Squid提供了很多有用的特性,但是分析一個原始Squid日誌文件並不直接。比如,你如何分析下面Squid日誌中的`時間戳和數字?

1404788984.429 1162 TCP_MISS/302 436 GET - DIRECT/ text/html

1404788985.046 12416 TCP_MISS/200 4169 CONNECT - DIRECT/ -

1404788986.124 174 TCP_MISS/200 955 POST - DIRECT/ application/ocsp-response

1404788989.738 342 TCP_MISS/200 3890 CONNECT - DIRECT/ -

1404788989.757 226 TCP_MISS/200 942 POST - DIRECT/ application/ocsp-response

1404788990.839 3939 TCP_MISS/200 78944 CONNECT - DIRECT/ -

1404788990.846 2148 TCP_MISS/200 118947 CONNECT - DIRECT/ -

1404788990.849 2151 TCP_MISS/200 76809 CONNECT - DIRECT/ -

1404788991.140 611 TCP_MISS/200 110073 CONNECT - DIRECT/ –

我們使用yum來安裝安裝必要的依賴。

# yum install gcc make wget httpd crond

在啓動時加載必要的服務

# service httpd start; service crond start

# chkconfig httpd on; chkconfig crond on

現在我們下載並解壓SARG

# wget ?

# tar zxvf

# cd sarg-2.3.8

注意: 對於64位的Linux,log.c的源代碼需要用下面的文件打補丁。

1506c1506

< if (fprintf(ufile->file, "%st%st%st%st%"PRIi64"t%st%ldt%sn",dia,hora,ip,url,nbytes,code,elap_time,smartfilter)<=0) {

---

> if (fprintf(ufile->file, "%st%st%st%st%"PRIi64"t%st%ldt%sn",dia,hora,ip,url,(int64_t)nbytes,code,elap_time,smartfilter)<=0) {

1513c1513

< fprintf(fp_log, "%st%st%st%st%st%"PRIi64"t%st%ldt%sn",dia,hora,user,ip,url,nbytes,code,elap_time,smartfilter);

---

> fprintf(fp_log, "%st%st%st%st%st%"PRIi64"t%st%ldt%sn",dia,hora,user,ip,url,(int64_t)nbytes,code,elap_time,smartfilter);

1564c1564

< printf("LEN=t%"PRIi64"n",nbytes);---

> printf("LEN=t%"PRIi64"n",(int64_t)nbytes);

如下繼續並編譯/安裝SARG

# ./configure

# make

# make install

SARG安裝之後,配置文件可以按你的要求修改。下面是一個SARG配置的例子。

# vim /usr/local/etc/

access_log /var/log/squid/

temporary_dir /tmp

output_dir /var/www/html/squid-reports

date_format e ## We use Europian DD-MM-YYYY format here ##

## we don’t want multiple reports for single day/week/month ##

overwrite_report yes

現在是時候測試運行了,我們用調試模式運行sarg來查看是否存在錯誤。

# sarg -x

如果i一切正常,sarg會根系Squid日誌,並在/var/www/html/squid-reports下創建報告。報告也可以在瀏覽器中通過地址http://<服務器ip>/squid-reports/訪問。

SARG可以用於創建日、周、月度報告。時間範圍用“-d”參數來指定,值的形式很可能爲day-n、 week-n 或者 month-n,n的值爲向前推移的天/周/月的數量。比如,使用week-1,SARG會生成之前一星期的報告。使用day-2,SARG會生成之前兩天的報告。

作爲演示,我們會準備一個計劃任務來每天運行SARG。

# vim /etc/y/sarg

#!/bin/sh

/usr/local/bin/sarg -d day-1

文件需要可執行權限。

# chmod 755 /usr/local/bin/sarg

現在SARG應該會每天準備關於Squid管理的流量報告。這些報告可以很容易地通過SARG網絡接口訪問。

以上就是利用SARG工具,來分析分析Squid日誌,並以更詳細的方式展示分析。系統管理員可以利用SARG來監視哪些網站被訪問了,並跟蹤訪問量最大的網站和用戶。

另外小編找來的這篇文章還包含了SARG配置工作。你可以進一步自定義配置來滿足自己的要求。希望能幫助大家,謝謝有點。

猜你喜歡

熱點閱讀

最新文章

推薦閱讀