piwik 는 google analytics 같은 오픈소스 기반의 분석 플랫폼이다.

설치

사전 준비

  1. Web Server 설치 

    yum install httpd mod_ssl
    CODE
  2. php 와 모듈 설치 (RHEL/CentOS 와 Windows 및 Unix 에 php 5.4 설치)

    yum install mod_php php-gd php-mbstring  php-dom php-xml
    CODE
  3. MySQL 설치 (CentOS 6 에 yum 으로 MySQL 5.5 설치 참고)

Piwik 설치

  1. 다운로드
    1. http://piwik.org/download/
  2. 적당한 디렉터리에 압축 해제 (/var/www/lesstif/piwik)

  3. 하위 폴더 생성

    mkdir -p /var/www/lesstif/piwik/tmp/{assets,logs,cache,tcpdf,templates_c}
    chown -R apache:apache /var/www/lesstif/piwik  
    CODE
  4. MySQL 계정 생성

    CREATE DATABASE piwik_db_name_here;
    CREATE USER 'piwik'@'localhost' IDENTIFIED BY 'VeryS2cretPwd';
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON piwik_db_name_here.* TO 'piwik'@'localhost' WITH GRANT OPTION;
    SQL
  5. VirtualHost 설정

    <VirtualHost *:80>
        ServerName lesstif.example.com
    
        DocumentRoot "/var/www/lesstif/"
        ErrorLog logs/lesstif-error_log
        CustomLog logs/lesstif-acces_log combined
    </VirtualHost>
    CODE
  6. 브라우저로 piwik 이 설치된 URL 에 연결(http://lesstif.example.com/piwik) 하여 설치 진행

 

사용

log analytics 툴 사용

JavaScript 기반의 추적이 아닌 웹서버의 access 로그를 분석하는 방법

  1. 소유자가 아파치라 일반 사용자로 실행하면 에러가 발생하므로 acl 변경

    find /var/www/lesstif/piwik/tmp/ -type d |xargs setfacl -m u:lesstif:rwx
    CODE
  2. 로그 파일 분석

    python misc/log-analytics/import_logs.py --url=http://lesstif.example.com/piwik/  --idsite=2 --add-sites-new-hosts --enable-bots --enable-static --enable-http-errors /etc/httpd/logs/lesstif-acces_log
    CODE
    1. --url: Piwik 의 base URL. piwik 이 설치된 URL 을 설정하면 된다.
    2. --idsite: Piwik 관리 콘솔에 등록된 사이트의 ID 를 입력한다. 등록되지 않았으면 좌측의 웹사이트 관리 메뉴에서 추가하자. 

    3. --add-sites-new-hosts :  When a hostname is found in the log file, but not matched to any website in Piwik, automatically create a new website in Piwik with this hostname to import the logs
    4. --enable-bots : Track bots. All bot visits will have a Custom Variable set with name='Bot' and value='$Bot_user_agent_here$'
    5. --enable-static : Track static files (images, css, js, etc.)
    6. --enable-http-errors : Track HTTP errors (status code 4xx or 5xx)
    7. --recorders : Number of simultaneous recoreds(Default 1)

 

 

 

Ref