cacti监内网本机TCP连接状况

Cacti是由php开发的网页,运行于LA/NMP平台,可利用SNMP获取数据,周期性的执行能够取得数据的命令,将取回的数据保存至rrd文件当中,利用rrdtool绘出图形。
snmp原理详解
http://blog.csdn.net/shanzhizi/article/details/11606767
http://www.cnblogs.com/xdp-gacl/p/3978825.html
rrdtool原理详解
http://blog.liuts.com/post/215/
LAMP环境已经编译搭建
虚拟主机配置

<VirtualHost *:80>
        DocumentRoot "/web/vhosts/cacti"
        DirectoryIndex index.shtml index.html index.php
        ErrorLog "logs/cacti_error.log"
        CustomLog "logs/cacti_access.log" common
        ProxyRequests Off  ProxyPassMatch^/(.*\.php)$fcgi://127.0.0.1:9000/web/vhosts/cacti/$1 
        <Directory /web/vhosts/cacti >
            Options FollowSymLinks Includes 
            AllowOverride All
            Require all granted
        </Directory>
</VirtualHost>

安装snmp并配置

# yum -y install rrdtool net-snmp net-snmp-libs net-snmp-utils 
修改配置文件/etc/snmp/snmpd.conf中的默认community,后启动服务
eg:   com2sec notConfigUser  127.0.0.1     mypublic
# chkconfig snmpd on 
# service snmpd start 

安装cacti,解压安装包到虚拟主机的根目录

# mkdir -p /web/vhosts/
# tar xvf cacti-0.8.8h.tar.gz -C /web/vhosts/
# ln -sv /web/vhosts/cacti-0.8.8h /web/vhosts/cacti

初始化数据,更新授权

# cd /web/vhosts/cacti
# mysqladmin create cactidb
# mysql cactidb < cacti.sql 
# mysql -e "GRANT ALL ON cactidb.* to cactiuser@localhost IDENTIFIED BY 'cactipasswd'"
# mysqladmin flush-privileges

创建系统用户cactiuser,修改cacti安装目录下rra和log目录的属主属组

# useradd cactiuser
# id cactiuser
uid=501(cactiuser) gid=501(cactiuser) groups=501(cactiuser)
# chown -R cactiuser:cactiuser rra log

修改Cacti配置文件中的mysql连接参数

# cat include/config.php
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactipasswd";
$database_port = "3306";
$database_ssl = false;
$url_path = "/"; #此处修改了cacti默认访问路径,不需要在访问地址后加/cacti

以cactiuser用户身份添加cacti收集数据的任务计划

# echo '*/5 * * * * /usr/local/php/bin/php /web/vhosts/cacti/poller.php &>/dev/null' > /var/spool/cron/cactiuser
# echo "date.timezone = Asia/Shanghai" >> /etc/php.ini 修改php时区
# hwclock -w  #同步硬件时间到系统
# hwclock 
Mon 25 Jul 2016 06:57:17 PM CST  -0.347178 seconds
# date
Mon Jul 25 18:57:20 CST 2016
# service httpd restart
# service snmpd restart

在浏览器中输入http://ip按照提示进行安装
cacti监内网本机TCP连接状况
编辑脚本获取TCP数据

# cd /web/vhosts/cacti/scripts/
# cat tcpcon.sh 
#!/bin/bash
#$1: hostname/ip
#$2:snmp community
SNMPNETSTAT=/usr/bin/snmpnetstat
TF=`mktemp /tmp/$1_tcpcon.XXXXXXX`
$SNMPNETSTAT -v 2c -c $2 -Can -Cp tcp $1 > $TF
EST=`grep -i 'established' $TF |wc -l`
TWAIT=`grep -i 'timewait' $TF |wc -l`
SYNRECV=`grep -i 'synreceived' $TF |wc -l`
echo -n "established:$EST"
echo -n "timewait:$TWAIT"
echo -n "synreceived:$SYNRECV"

Console -> Data Input Methods -> (Edit)
定义Data Input Methods,添加SNMP-TCP connections,数据收集方法为脚本,脚本路径为cacti安装目录下的tcpcon.sh,并传递两个参数
cacti监内网本机TCP连接状况
Console -> Data Templates -> (Edit)
定义数据模板,关联数据输入方法,添加3个数据源
cacti监内网本机TCP连接状况
Console -> Data Sources -> (Edit)定义数据源
cacti监内网本机TCP连接状况
Console -> Graph Templates -> (Edit)定义图像模板
cacti监内网本机TCP连接状况

上一篇:PHP添加zip&&curl扩展


下一篇:zabbix安装配置