SARG은 오픈 소스 도구로, squid 로그 파일을 분석하고 HTML 형식의 유저, IP 주소, 가장 자주 사용하는 사이트, 총 频宽 사용량, 경과 시간, 다운로드 정보, 제한 된 사이트 정보, 일일 보고서, 週周 보고서, 개발 보고서를 생성하는 것が 가능합니다.
The SARG 은 인터넷 频宽이 個々의 compute 기기 에서 어떻게 사용되는지 보기 위한 유용한 도구이며, 네트워크 사용자가 어떤 웹사이트에 접근하는지 모니터링할 수 있습니다.

In this article, I will guide you on how to install and configure SARG – Squid Analysis Report Generator on RHEL / CentOS / Fedora and Debian / Ubuntu / Linux Mint systems.
Installing Sarg – Squid Log Analyzer in Linux
I assume that you already installed, configured and tested Squid server as a transparent proxy and DNS for the name resolution in caching mode. If not, please install and configure them first before moving further installation of Sarg.
Important: Please remember without the Squid and DNS setup, no use of installing sarg on the system it will won’t work at all. So, it’s a request to install them first before proceeding further to Sarg installation.
Follow these guides to install DNS and Squid in your Linux systems:
Install Cache-Only DNS Server
- Install Cache Only DSN Server in RHEL/CentOS 7
- RHEL/CentOS 6에 캐시 전용 DSN 서버 설치
- Ubuntu 및 Debian에 캐시 전용 DSN 서버 설치
투명 프록시로 Squid 설치
단계 1: 소스에서 Sarg 설치
기본적으로 ‘sarg’ 패키지는 RedHat 기반 배포판에 포함되어 있지 않으므로 소스 tarball에서 수동으로 컴파일하고 설치해야 합니다. 이를 위해 소스에서 컴파일하기 전에 시스템에 몇 가지 추가적인 사전 요구 패키지를 설치해야 합니다.
RedHat/CentOS/Fedora에서
# yum install –y gcc gd gd-devel make perl-GD wget httpd
필요한 모든 패키지를 설치한 후, 최신 sarg 소스 tarball을 다운로드하거나 다음 wget 명령을 사용하여 아래와 같이 다운로드하고 설치할 수 있습니다.
# wget http://liquidtelecom.dl.sourceforge.net/project/sarg/sarg/sarg-2.3.10/sarg-2.3.10.tar.gz # tar -xvzf sarg-2.3.10.tar.gz # cd sarg-2.3.10 # ./configure # make # make install
Debian/Ubuntu/Linux Mint에서
Debian 기반 배포판에서, sarg パッケージはデフォルトのリポジトリーを使用して、apt-get パッケージマネージャーを通じて簡単にインストールすることができます。
$ sudo apt-get install sarg
第2ステップ: Sarg の設定
今度は、SARGの主な設定ファイルにいくつかのパラメーターを編集する時です。このファイルには、編集するオプションがたくさんありますが、以下のような必要なパラメーターしか編集しません。
- アクセスログのパス
- 出力ディレクトリ
- 日付フォーマット
- 同じ日付のレポートを上書きする。
editorの選択肢でsarg.confファイルを開き、以下のように変更します。
# vi /usr/local/etc/sarg.conf [On RedHat based systems]
$ sudo nano /etc/sarg/sarg.conf [On Debian based systems]
今、squidアクセスログファイルの元のパスを解除注释して追加します。
# sarg.conf # # TAG: access_log file # Where is the access.log file # sarg -l file # access_log /var/log/squid/access.log
次に、出力ディレクトリパスを追加して、そのディレクトリに Squid レポートを保存します。注意: Debian 기반のディストリビューションでは、Apacheウェブルートディレクトリは `/var/www`です。したがって、Linux ディストリビューションの下で正しいウェブルートパスを追加する際には注意してください。
# TAG: output_dir # The reports will be saved in that directory # sarg -o dir # output_dir /var/www/html/squid-reports
レポート用に正しい日付フォーマットを設定します。たとえば、`date_format e`は、`dd/mm/yy`フォーマットでレポートを表示します。
# TAG: date_format # Date format in reports: e (European=dd/mm/yy), u (American=mm/dd/yy), w (Weekly=yy.ww) # date_format e
次に、解除注释してYesに設定します。
# TAG: overwrite_report yes|no # yes - if report date already exist then will be overwritten. # no - if report date already exist then will be renamed to filename.n, filename.n+1 # overwrite_report yes
です! ファイルを保存し閉じます。
第3ステップ: Sarg レポートの生成
設定を完了した後、以下のコマンドを使用して Squid ログレポートを生成します。
# sarg -x [On RedHat based systems]
# sudo sarg -x [On Debian based systems]
サンプル出力
[root@localhost squid]# sarg -x SARG: Init SARG: Loading configuration from /usr/local/etc/sarg.conf SARG: Deleting temporary directory "/tmp/sarg" SARG: Parameters: SARG: Hostname or IP address (-a) = SARG: Useragent log (-b) = SARG: Exclude file (-c) = SARG: Date from-until (-d) = SARG: Email address to send reports (-e) = SARG: Config file (-f) = /usr/local/etc/sarg.conf SARG: Date format (-g) = USA (mm/dd/yyyy) SARG: IP report (-i) = No SARG: Keep temporary files (-k) = No SARG: Input log (-l) = /var/log/squid/access.log SARG: Resolve IP Address (-n) = No SARG: Output dir (-o) = /var/www/html/squid-reports/ SARG: Use Ip Address instead of userid (-p) = No SARG: Accessed site (-s) = SARG: Time (-t) = SARG: User (-u) = SARG: Temporary dir (-w) = /tmp/sarg SARG: Debug messages (-x) = Yes SARG: Process messages (-z) = No SARG: Previous reports to keep (--lastlog) = 0 SARG: SARG: sarg version: 2.3.7 May-30-2013 SARG: Reading access log file: /var/log/squid/access.log SARG: Records in file: 355859, reading: 100.00% SARG: Records read: 355859, written: 355859, excluded: 0 SARG: Squid log format SARG: Period: 2014 Jan 21 SARG: Sorting log /tmp/sarg/172_16_16_55.user_unsort ......
주의: ‘sarg -x’ 명령은 ‘sarg.conf’ 구성 파일을 읽고 스쿼이드 ‘access.log’ 경로를 가져와 HTML 형식의 보고서를 생성합니다.
단계 4: Sarg 보고서 평가
생성된 보고서는 ‘var/www/html/squid-reports/’ 또는 ‘var/www/squid-reports/’에 배치되며 웹 브라우저를 통해 주소를 사용하여 액세스할 수 있습니다.
http://localhost/squid-reports OR http://ip-address/squid-reports
Sarg 주 창

특정 날짜

사용자 보고서

상위 액세스된 사이트

상위 사이트 및 사용자

상위 다운로드

액세스 거부

인증 실패

단계 5: Sarg 보고서 자동 생성
sarg 보고서 생성 프로세스를 cron 작업을 통해 주어진 시간 간격으로 자동화합니다. 예를 들어, 매 시간마다 보고서를 생성하려면 Cron 작업을 구성해야 합니다.
# crontab -e
다음으로 파일의 맨 아래에 다음 줄을 추가합니다. 저장하고 닫습니다.
* */1 * * * /usr/local/bin/sarg -x
위의 Cron 규칙은 매 1시간마다 SARG 보고서를 생성합니다.
참고 링크
그게 다야 SARG! 그동안 Linux에 대한 몇 가지 더 흥미로운 기사를 준비 중이니, 그 동안 TecMint.com을 계속해서 방문하시고 소중한 의견을 남겨주세요.
Source:
https://www.tecmint.com/sarg-squid-analysis-report-generator-and-internet-bandwidth-monitoring-tool/