一,配置zabbix 客户端环境
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel//x86_64/zabbix-release-4.0-.el7.noarch.rpm
yum install zabbix-agent -y
vim /etc/zabbix/zabbix_agentd.conf
##需要改变的内容
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=
Server=192.168.0.214
ServerActive=192.168.0.214
Hostname=k8s1
HostMetadataItem=system.uname
Include=/etc/zabbix/zabbix_agentd.d/*.conf systemctl restart zabbix-agent.service
二,配置脚本
[root@k8s1 alertscripts]# cat docker.py
#!/usr/bin/python
import sys
import os
import json def discover():
d = {}
d['data'] = []
with os.popen("docker ps -a --format {{.Names}}") as pipe:
for line in pipe:
info = {}
info['{#CONTAINERNAME}'] = line.replace("\n","")
d['data'].append(info) print json.dumps(d) def status(name,action):
if action == "ping":
cmd = 'docker inspect --format="{{.State.Running}}" %s' %name
result = os.popen(cmd).read().replace("\n","")
if result == "true":
else:
else:
cmd = 'docker stats %s --no-stream --format "{{.%s}}"' % (name,action)
result = os.popen(cmd).read().replace("\n","")
if "%" in result:
print float(result.replace("%",""))
else:
print result if __name__ == '__main__':
try:
name, action = sys.argv[], sys.argv[]
status(name,action)
except IndexError:
discover()
UserParameter=docker.discovery,/usr/lib/zabbix/alertscripts/docker.py
UserParameter=docker.[*],/usr/lib/zabbix/alertscripts/docker.py $ $
https://www.cnblogs.com/binglansky/p/9132714.html