参考:http://www.tnkyou.com/wk/doku.php?id=collectd
collectd server用于收集collectd agent发送过来的数据,是一个被动的过程!
安装collectd需要支持的插件yum install -y net-snmp-devel(snmp插件依赖这个库)yum install -y rrdtool-devel(rrdtool插件依赖这个库)yum install -y libgcrypt-devel(network插件加密依赖这个库)yum install -y python-devel(依赖这个库)yum install -y perl-devel(编译依赖perl库)yum install -y python-requests(python influxdb plugin 的依赖库)yum install -y liboping-devel (ping 依赖的库)
安装collectdwget http://collectd.org/files/collectd-5.4.2.tar.gztar zxvf collectd-5.4.2.tar.gzcd collectd-5.4.2./configure –prefix=/usr/local/collectd –enable-all-pluginsmake ; make install
修改collectd配置文件cd /usr/local/collectd/etc/cp collectd.conf collectd.conf.bak(collectd.conf文件中具体内容见文章末尾collectd.conf.server)
collectd配置成服务vim /etc/rc.d/init.d/collectd (collectd 文件中具体内容见文章末尾collectd.txt)chmod u+x /etc/rc.d/init.d/collectdchkconfig –add collectdchkconfig collectd onserver collectd {start|stop|restart|status|help}
执行./configure之后会输出一张支持插件的列表(如下图)如果需要安装别的插件需要重新编译collectd
安装collectd (agent)
collectd agent定时收集数据并发送到collectd server,是一个主动的过程!
yum install -y net-snmp
chkconfig snmpd on # snmp设置成开机启动
echo “view systemview included .1”
/etc/snmp/snmpd.conf # 让snmp监控所有字段
service snmpd start
yum install -y net-snmp-utils # snmp客户端工具,用于调试。
常见调试命令
snmpwalk -v 2c -c public 192.168.16.144 # 查看所有字段
snmpwalk -v 2c -c public 192.168.16.144 system # 查看系统字段
其他步骤和安装collectd server一样,但是不需要额外安装插件
安装influxdb
用于接收collectd 发送过来的数据,并写入数据库。并在此基础上提供了查询功能!
wget https://s3.amazonaws.com/influxdb/influxdb-latest-1.x86_64.rpm
rpm -ivh influxdb-latest-1.x8664.rpm - chkconfig influxdb on - service influxdb start - 登录influxdb管理后台 http://192.168.16.146:8083/ - 默认账号:root 密码:root - 创建一个数据库 - curl https://raw.githubusercontent.com/collectd/collectd/master/src/types.db -o /opt/influxdb/shared/types.db # 下载collectd插件支持的数据类型映射表 - vim /opt/influxdb/shared/config.toml(配置influxdb的collectd插件,选择数据库引擎,并重启influxdb) [input
plugins.collectd] enabled = true address = “0.0.0.0” # If not set, is actually set to bind-address. port = 25826 database = “collectd” # types.db can be found in a collectd installation or on github: # https://github.com/collectd/collectd/blob/master/src/types.db typesdb = “/opt/influxdb/shared/types.db”default-engine = “rocksdb” # 选择数据库引擎
influx常用命令
list series
select * from /.*/
select * from “10.0.2.220/interface-eth0/if_octets” where dsname = 'tx'表明用双引号,列值用单引号
安装Grafana
一个纯web显示程序,可以从influxdb数据源读取数据
wget http://grafanarel.s3.amazonaws.com/grafana-1.9.1.tar.gz
tar xzvf grafana-1.9.1.tar.gz
cd grafana-1.9.1.tar.gz
cp config.sample.js config.js
最后将整个目录放到nginx或apache下即可
登录grafana http://192.168.16.146config.js # 取消如下代码的注释datasources: { influxdb: { type: 'influxdb', url: “http://192.168.16.146:8086/db/collectd”, username: 'root', password: 'root', }, },
配置文件
collectd.conf(server端)
----------- global setting ---------------FQDNLookup false # 关闭主机名验证Interval 10 # 全局采样时间间隔Timeout 2 ReadThreads 5 # 开启 5 个读进程WriteThreads 5 # 开启 5 个写进程#------------ simple plugin ----------------LoadPlugin cpuLoadPlugin interfaceLoadPlugin loadLoadPlugin memoryLoadPlugin disk#------------ complex plugin ---------------LoadPlugin snmpLoadPlugin statsd # 默认开启8125端口LoadPlugin rrdtoolLoadPlugin networkLoadPlugin logfile#------------ detail for complux plugin ---------------- LogLevel info # 日志级别 debug|info|notice|warning|err File "/usr/local/collectd/collectd.log" # 日志文件位置 Server "192.168.16.146" "25826" # 自己作为客户端,将数据发送到某个服务器的ip,port # 自己作为服务器,绑定一个接收客户端数据的ip,port SecurityLevel Sign # 验证级别 debug|info|notice|warning|err AuthFile "/usr/local/collectd/etc/authfile.txt" # 验证文件,账号密码以键值对的方式存储,如:upyun: 123 Forward true # 将客户端和本机的数据写入rrd文件 DataDir "/usr/local/collectd/var/lib/collectd/rrd" # 用snmp插件去主动收集客户端数据 Type "users" # 见/usr/local/collectd/share/collectd/types.db Table false Instance "" Shift -1 Values "HOST-RESOURCES-MIB::hrSystemNumUsers.0" # 收集客户端用户登录数 Address "192.168.16.144" # 客户端ip Version 2 # snmp 协议版本 Community "public" # 见/etc/snmp/snmpd.conf中的 community字段 Collect "hr_users" # 收集哪些数据,可以指定多个 Interval 10 # 采样周期,可以覆盖全局变量 Interval
collectd.conf(agentd端)
----------- global setting ---------------FQDNLookup falseInterval 10Timeout 2ReadThreads 5WriteThreads 5#------------ simple plugin ----------------LoadPlugin cpu LoadPlugin interface LoadPlugin loadLoadPlugin memoryLoadPlugin disk##------------ complex plugin ---------------LoadPlugin statsdLoadPlugin networkLoadPlugin logfile##------------ detail for complux plugin ---------------- LogLevel info File "/usr/local/collectd/collectd.log" SecurityLevel Sign # 校验级别,和服务器端保持一致 Username "upyun" # 账号 Password "123" # 密码
collectd(collectd服务配置脚本)