Collectd 是一套後端監控軟體,用 C 開發的,很輕量,效能也很好,不過沒有前端。
前端顯示可以靠 Web server + 第三方軟體提供,目前看到是 CGPGraphite 兩套介面還不錯看的前端。因為時間有限,所以暫時不嘗試 Graphite

Install Collectd

Default repository 裡的 collectd 版本是 4.10.1,因為我想要嘗試 aggregate 的功能(但是還沒有成功),必須要用到 5.3(?) 以上的版本

sudo apt-get install python-software-properties
sudo add-apt-repository ppa: catalystit/collectd5-precise
sudo apt-get update
sudo apt-get install collectd

修改 /etc/collectd/collectd.conf (以下設定自行斟酌):

  • 將 FQDNLookup true 註解,並設定 Hostname "your hostname"
  • 設定要 monitor 的 interface

    <Plugin interface>
        Interface "br-ex"
        Interface "ib0"
        IgnoreSelected false
    </Plugin>
    
  • 取消 LoadPlugin network 的註解,並設定 network

    <Plugin network>
        # client setup:
        Server "127.0.0.1" "25826"
        #Server "ff18::efc0:4a42" "25826"
        #<Server "239.192.74.66" "25826">
        #       SecurityLevel Encrypt
        #       Username "user"
        #       Password "secret"
        #       Interface "eth0"
        #</Server>
        TimeToLive "128"
    
        # server setup:
        Listen "0.0.0.0" "25826"
        #Listen "ff18::efc0:4a42" "25826"
        #<Listen "239.192.74.66" "25826">
        #       SecurityLevel Sign
        #       AuthFile "/etc/collectd/passwd"
        #       Interface "eth0"
        #</Listen>
        MaxPacketSize 1024
    
        # proxy setup (client and server as above):
        Forward true
    
        # statistics about the network plugin itself
        ReportStats false
    
        # "garbage collection"
        CacheFlush 1800
    </Plugin>
    

    純 client 的話請勿開啟 server 設定,並將 127.0.0.1 換成 server 的 IP

接下來重新啟動 collectd

sudo service collectd restart

用 netstat 檢查 server 是否 running

user@localhost:~$ sudo netstat -tnlup | grep 25826
udp        0      0 0.0.0.0:25826           0.0.0.0:*                           480/collectd    
user@localhost:~$ 

檢查 /var/lib/collectd/rrd/ 是否有資料出現

sudo ls /var/lib/collectd/rrd/

Install Nginx

先新增 nginx 的 ppa

sudo add-apt-repository ppa: nginx/stable

接下來安裝 nginx

sudo apt-get install nginx

修改 nginx 的 site configuration (e.g. /etc/nginx/sites-available/default)

  1. index 後面加上 index.php
  2. 取下以下區塊的註解,並新增設定值進去

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    
        # With php5-cgi alone
        # fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
  3. 新增一個 location 設定 (options.)

    location /monitor {
         alias /usr/share/nginx/html/monitor;
         autoindex on;
    }
    

然後重新啟動 nginx

sudo service nginx restart

Install PHP5-FPM

先安裝套件

sudo apt-get install php5-fpm

然後修改 /etc/php5/fpm/php.ini :

  1. max_execution_time 設成 600
  2. max_input_time 設成 300
  3. post_max_size 設成 16M
  4. 取消 date.timezone 的註解,並改成 date.timezone = Asia/Taipei
  5. cgi.fix_pathinfo 設為 0

接下來修改 /etc/php5/fpm/pool.d/www.conf :

  1. 將 listen = 127.0.0.1:9000 修改成 listen = /var/run/php5-fpm.sock
  2. 取消以下三行的註解 (option.):
    listen.owner = www-data
    
    listen.group = www-data
    
    listen.mode = 0660
    

啟動 php5-fpm

service php5-fpm restart

Install CGP

(部分參數請自行調整)

sudo apt-get install git
cd /usr/share/nginx/html
sudo git clone https://github.com/pommi/CGP.git
sudo mv CGP monitor
sudo chown -R www-data:www-data monitor/

理論上這個時候就完工了,可以透過網址: http://{{ your ip or web url }}/monitor/index.php 開啟 CGP 畫面。


Customize CGP

cd /usr/share/nginx/html/monitor/conf
sudo cp config.php config.local.php

config.php 不要動,任何設定只需要修改 config.local.php 即可

Host category

$CONFIG['cat']['Controller'] = array('controller');
$CONFIG['cat']['Compute'] = array('compute01', 'compute02', 'compute03');
$CONFIG['cat']['Storage'] = array('storage01', 'storage02', 'storage03');

Overview

$CONFIG['overview'] = array('load', 'memory', 'interface');

Graphic type

$CONFIG['graph_type'] = 'canvas';

Timezone

$CONFIG['default_timezone'] = 'Asia/Taipei';

Reference

  1. Collectd Graph Panel
  2. Graphite - Scalable Realtime Graphing
  3. nginx中php出现白屏解决方法

Comments

comments powered by Disqus