# cat /etc/redhat-release
CentOS release 6.8 (Final)
# uname -r
3.10.5-3.el6.x86_64
Nagios服务端主机:192.168.70.67 密码:ikongjian@2016!
Nagios客户端主机:192.168.70.52 密码:ikongjian@2016!
Nagios版本: nagios-3.5.1
Plugin插件版本: nagios-plugins-1.4.16
Nrpe版本: nrpe-2.12
安装路径: /usr/local/nagios
实现目的:实现docker容器的内存监控
实现工具:监控系统nagios
实现原理:
1,nagios客户端写dcoker容器内存监控插件,并开启nrpe守护进程
2,服务端check_nrpe链接客户端守护进程,取插件执行结果,返回给web界面。
/usr/local/nagios/etc/nrpe.cfg
增加以下配置:
command[check_docker101]=/usr/local/nagios/libexec/check_docker101
插件如下:
vim /usr/local/nagios/libexec/check_docker101
#/bin/bash
DOCKER_NAME=`echo $0|awk -F '_' '{print $2}'`
DOCKER_ID=`cat /data/docker_id.txt|grep ${DOCKER_NAME}|awk '{print $2}'`
TOTAL_MEM=`cat /cgroup/memory/docker/${DOCKER_ID}/memory.limit_in_bytes`
USE_MEM=`cat /cgroup/memory/docker/${DOCKER_ID}/memory.usage_in_bytes`
FREE=`echo ${TOTAL_MEM}-${USE_MEM}|bc`
FREE_MB=`expr $FREE/1024/1024|bc`
if [ $FREE_MB -ge 100 ]
then
echo "CHECK_MEORY OK - $FREE_MB M free "
exit 0
elif [ $FREE_MB -lt 100 -a $FREE_MB -gt 30 ]
then
echo "CHECK_MEORY WARNING - $FREE_MB M free"
exit 1
elif [ $FREE_MB -le 30 ]
then
echo "CHECK_MEORY CRITICAL - $FREE_MB M free"
exit 2
else
echo "CHECK_MEORY UNKOWN mem lessest"
exit 3
fi
给权限:
chmod 755 /usr/local/nagios/libexec/check_docker101
chown nagios.nagios /usr/local/nagios/libexec/check_docker101
执行查件:
[root@test6 data]# /usr/local/nagios/libexec/check_docker101
CHECK_MEORY OK - 261 M free
A:配置命令文件——commands.cfg
define command{
command_name check_docker101
command_line $USER1$/check_docker101
}
B:配置主机文件——host.cfg
define host{
use linux-server
host_name docker
alias docker
address 192.168.70.52
max_check_attempts 3
normal_check_interval 2
process_perf_data 1
action_url /nagios/pnp/index.php?host=$HOSTNAME$
}
C:配置服务文件——service.cfg
define service{
use generic-service
host_name docker
service_description docker_mem_101
check_command check_nrpe!check_docker101
process_perf_data 1
}
用check_nrpe测试远端插件:
[root@BI-test etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.70.52 -c check_docker101
CHECK_MEORY OK - 261 M free
一切正常。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。