check_mk自定义监控插件

本文介绍了如何为check_mk创建自定义监控插件,通过示例代码展示了配置过程,如checks的添加,用于监控特定文件计数。内容参考自官方开发文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

客户端:
/usr/lib/check_mk_agent/plugins/filecount
#!/bin/bash
#DIRS="/var/log /tmp"
DIRS="/var/log"
echo '<<<filecount>>>'
for dir in $DIRS
do
   # ls $dir | wc --lines
    count=$(ls $dir | wc --lines)
    echo "$count"
done


cd /usr/lib/check_mk_agent/plugins
chmod +x filecount



服务端:
服务端执行如下命令查看是否能够从客户端获取值
[root@LY-1611-E1 checks]# check_mk -d 10.8.18.53|fgrep -A 5 filecount
<<<filecount>>>
52
<<<postgres_sessions>>>
f 115
t 0
<<<postgres_stat_database:sep(59)>>>


在服务端创建文件filecount
/usr/share/check_mk/checks/filecount
def inventory_filecount_temp(info):
   inventory = []
   for line in info:
      disk = line[0]
      inventory.append( (disk, None) )
   return inventory


def check_filecount_temp(item, params, info):
        for line in info:
                celsius = int(line[0])
                if celsius > 200:
                        return (2, "filecount is %d" % celsius)
                        #return (2, "filecount is %d" % celsius)
                elif celsius > 100:
                        return (1, "filecount50 is %d" % celsius)
                else:
                        return (0, "filecount is %d" % celsius)
        return (3, "Disk %s not found in agent output" % item)


check_info["filecount.temp"] = {
    'check_function':            check_filecount_temp,
    'inventory_function':        inventory_filecount_temp,
    'service_description':       'filecount %s',
}


检查check_mk是否可以识别新增加的check
[root@LY-1611-E1 checks]# check_mk -L|grep filecount
filecount.temp                   tcp     no     yes    filecount %s


[root@LY-1611-E1 checks]# check_mk --checks=filecount.temp -I 10.8.18.53
filecount.temp    1 new checks


查看服务端从客户端获取数据结果
[root@LY-1611-E1 checks]# check_mk -nv 10.8.18.53
Check_mk version 1.2.4
PostgreSQL Daemon Sessions WARN - 109 total(!), 109 running(!)
SMART drive /dev/sda WARN - Temperature40 is 34C
filecount 52         OK - filecount is 52
filecount filecount  OK - filecount is 52
OK - Agent version 1.2.4, execution time 0.2 sec|execution_time=0.190 user_time=0.280 system_time=0.010 children_user_time=0.000 children_system_time=0.000




main.mk中增加监控项

checks += [("10.8.18.53","filecount.temp","filecount",(20,25))]



此文章参考官方网站而写

http://mathias-kettner.de/checkmk_devel_agentbased.html








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值