zoukankan      html  css  js  c++  java
  • zabbix--高级篇-监控docker服务(一)

    一,配置zabbix 客户端环境

    rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.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=0
    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("
    ","")
                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("
    ","")
            if result == "true":
                print 1
            else:
                print 0
        else:
            cmd = 'docker stats %s --no-stream --format "{{.%s}}"' % (name,action)
            result = os.popen(cmd).read().replace("
    ","")
            if "%" in result:
                print float(result.replace("%",""))
            else:
                print result
    
    
    if __name__ == '__main__':
            try:
                    name, action = sys.argv[1], sys.argv[2]
                    status(name,action)
            except IndexError:
                    discover()
    UserParameter=docker.discovery,/usr/lib/zabbix/alertscripts/docker.py
    UserParameter=docker.[*],/usr/lib/zabbix/alertscripts/docker.py $1 $2

    https://www.cnblogs.com/binglansky/p/9132714.html

  • 相关阅读:
    JSON
    Chromium 修改chrome.exe
    Chromium 修改任务管理器显示的Chromium
    winhttp get请求https
    string wstring 互转
    浏览器指纹在线监测获取网址
    咕了的构造题单总结
    Git 常用命令总结
    C# 网络地址是否有效
    IDEA如何从断点里获取对象所有数据
  • 原文地址:https://www.cnblogs.com/kingle-study/p/10560319.html
Copyright © 2011-2022 走看看