本次实验紧接上次实验,ganglia节点需要开启,且已经安装Nagios,Nagios安装可参考我前面关于nagios的博客:实战Nagios网络监控(1)——监控本机运行状态和Mysq主机
注:ganglia与nagios可以部署在不同的主机
主机nagios状态如下:
主机ganglia状态如下:
server1
server2
nagios监控远程主机的方式为nagios+nrpe,而ganglia可以使用客户端daemon(Ganglia Monitoring Daemon(gmond))监控远程主机,本次实验为server1上只装有nagios,server1和server2上没有装nrpe服务,服务端server1无法获取server2的主机资源。添加ganglia服务,ganglia集群资源中有server1和server2服务。利用server1上的nagios集成ganglia服务从而让server1上的nagios监控远程主机server2上的资源。
1.ganglia配置
[root@server1 html]# cp /root/ganglia-3.4.0/contrib/check_ganglia.py /usr/local/nagios/libexec/
[root@server1 html]# cd /usr/local/nagios/libexec/
[root@server1 libexec]# chown nagios.nagios check_ganglia.py
注:check_ganglia.py 命令仅在阈值过高时发出警告。如果希望在阈值过低时发出警告(在disk_free 中是这样),则需要修改代码。我更改了文件的最后部分,如下所示:
[root@server1 libexec]# vim check_ganglia.py
89 if critical > warning:
90 if value >= critical:
91 print "CHECKGANGLIA CRITICAL: %s is %.2f" % (metric, value)
92 sys.exit(2)
93 elif value >= warning:
94 print "CHECKGANGLIA WARNING: %s is %.2f" % (metric, value)
95 sys.exit(1)
96 else:
97 print "CHECKGANGLIA OK: %s is %.2f" % (metric, value)
98 sys.exit(0)
99 else:
100 if critical > value:
101 print "CHECKGANGLIA CRITICAL: %s is %.2f" % (metric, value)
102 sys.exit(2)
103 elif warning >= value:
104 print "CHECKGANGLIA WARNING: %s is %.2f" % (metric, value)
105 sys.exit(1)
106 else:
107 print "CHECKGANGLIA OK: %s is %.2f" % (metric, value)
108 sys.exit(0)
[root@server1 libexec]# /usr/local/nagios/libexec/check_ganglia.py -h server2.example.com -m disk_free -w 20 -c 10
CHECKGANGLIA CRITICAL: disk_free is 6.36
2.nagios配置
[root@server1 ~]# cd /usr/local/nagios/etc/objects/
[root@server1 objects]# vim commands.cfg
添加如下内容:
# 'check_ganglia' command definition
define command {
command_name check_ganglia
command_line $USER1$/check_ganglia.py -h $HOSTNAME$ -m $ARG1$ -w $ARG2$ -c $ARG3$
}
[root@server1 objects]# vim templates.cfg
添加如下内容:
define service {
use generic-service
name ganglia-service
hostgroup_name ganglia-servers
service_groups ganglia-metrics
}
[root@server1 objects]# vim hosts.cfg
添加如下内容:
define host{
use linux-server
host_name server2.example.com
alias server2
address 172.25.254.2
icon_image switch.gif
statusmap_image switch.gd2
2d_coords 400,100
3d_coords 400,200,100
}
define hostgroup {
hostgroup_name ganglia-servers
alias ganglia-servers
members server2.example.com
}
[root@server1 objects]# vim services.cfg
添加如下内容:
define servicegroup {
servicegroup_name ganglia-metrics
alias Ganglia Metrics
}
define service{
use ganglia-service
service_description 根分区
check_command check_ganglia!disk_free_percent_rootfs!20!10
}
define service{
use ganglia-service
service_description 系统负载
check_command check_ganglia!load_one!4!5
}
define service{
use ganglia-service
service_description 内存空闲
check_command check_ganglia!mem_free!50000!30000
}
[root@server1 objects]# /etc/init.d/nagios restart
浏览器端刷新查看,servre2端的资源被监控:
等一段时间,状态都变成了OK:
本文转自willis_sun 51CTO博客,原文链接:http://blog.51cto.com/willis/1866634,如需转载请自行联系原作者