標籤:nagios 自訂外掛程式 監控docker
1.
環境:
# cat /etc/redhat-release
CentOS release 6.8 (Final)
# uname -r
3.10.5-3.el6.x86_64
Nagios服務端主機:192.168.70.67 密碼:[email protected]!
Nagios用戶端主機:192.168.70.52 密碼:[email protected]!
2.
版本
Nagios版本: nagios-3.5.1
Plugin外掛程式版本: nagios-plugins-1.4.16
Nrpe版本: nrpe-2.12
安裝路徑: /usr/local/nagios
3.
需求分析
實現目的:實現docker容器的記憶體監控
實現工具:監控系統nagios
實現原理:
1,nagios用戶端寫dcoker容器記憶體監控外掛程式,並開啟nrpe守護進程
2,服務端check_nrpe連結用戶端守護進程,取外掛程式執行結果,返回給web介面。
4.
用戶端配置
/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
執行查件:
[[email protected] data]# /usr/local/nagios/libexec/check_docker101
CHECK_MEORY OK - 261 M free
5.
服務端配置
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測試遠端外掛程式:
[[email protected] etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.70.52 -c check_docker101
CHECK_MEORY OK - 261 M free
一切正常。
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/8A/54/wKiom1gtVqrzVXNRAADXke5ImZ0242.png-wh_500x0-wm_3-wmp_4-s_3425479665.png" title="圖片1.png" alt="wKiom1gtVqrzVXNRAADXke5ImZ0242.png-wh_50" />
本文出自 “11262076” 部落格,請務必保留此出處http://11272076.blog.51cto.com/11262076/1873894
nagios——docker容器監控