容器監(jiān)控實(shí)踐—Dockbix

一.概述

Dockbix意為docker+zabbix,即使用zabbix來監(jiān)控docker容器的插件或者模塊,既然有專業(yè)的cadvisor、prometheus等容器監(jiān)控方案,為什么還要用傳統(tǒng)的zabbix呢?

  • 在docker剛出現(xiàn)時(shí),還沒有專業(yè)的容器監(jiān)控方案
  • 公司已有zabbix的成熟實(shí)踐,想直接集成到zabbix中(雖然不太優(yōu)雅)

使用zabbix來監(jiān)控docker有幾種方案,比如:

  • 自己寫agent,利用docker的api獲取stats信息,暴露api接口給zabbix采集
  • 使用zabbix的Module,將docker的采集展示集成到現(xiàn)有的zabbix系統(tǒng)中

如何使用

寫API

python sdk:https://docker-py.readthedocs.io/en/stable/containers.html#docker.models.containers.Container.stats

stats(**kwargs)
Stream statistics for this container. Similar to the docker stats command.

Parameters: 
decode (bool) – If set to true, stream will be decoded into dicts on the fly. Only applicable if stream is True. False by default.
stream (bool) – If set to false, only the current stats will be returned instead of a stream. True by default.
Raises: 
docker.errors.APIError – If the server returns an error.

如計(jì)算cpu:

def calculate_cpu_percent(d):
    cpu_count = len(d["cpu_stats"]["cpu_usage"]["percpu_usage"])
    cpu_percent = 0.0
    cpu_delta = float(d["cpu_stats"]["cpu_usage"]["total_usage"]) - \
                float(d["precpu_stats"]["cpu_usage"]["total_usage"])
    system_delta = float(d["cpu_stats"]["system_cpu_usage"]) - \
                   float(d["precpu_stats"]["system_cpu_usage"])
    if system_delta > 0.0:
        cpu_percent = cpu_delta / system_delta * 100.0 * cpu_count
    return cpu_percent

Zabbix Module

通過部署一個(gè)zabbix agent的docker容器來監(jiān)控宿主機(jī)器和宿主機(jī)器上docker的狀態(tài)。

搬運(yùn)下開源項(xiàng)目:https://github.com/monitoringartist/zabbix-docker-monitoring

1.在需要監(jiān)控的宿主機(jī)器上運(yùn)行運(yùn)行Agent容器

docker run \
  --name=dockbix-agent-xxl \
  --net=host \
  --privileged \
  -v /:/rootfs \
  -v /var/run:/var/run \
  --restart unless-stopped \
  -e "ZA_Server=<ZABBIX SERVER IP/DNS NAME/IP RANGE>" \
  -e "ZA_ServerActive=<ZABBIX SERVER IP/DNS NAME>" \
  -d monitoringartist/dockbix-agent-xxl-limited:latest

2.配置監(jiān)控模板

在zabbix server上導(dǎo)入監(jiān)控docker的模版,可用模板包括:

也可以用docker鏡像直接運(yùn)行,來導(dǎo)入模板:monitoringartist/zabbix-templates,如:

docker run --rm \
  -e XXL_apiurl=http://zabbix.org/zabbix \
  -e XXL_apiuser=Admin \
  -e XXL_apipass=zabbix \
  monitoringartist/zabbix-templates

item為:

image

詳細(xì)的metric的值可以參考:https://github.com/monitoringartist/zabbix-docker-monitoring/blob/master/README.md

3.可視化

zabbix的監(jiān)控圖:

image

grafana中也有zabbix的數(shù)據(jù)模板

image

本文為容器監(jiān)控實(shí)踐系列文章,完整內(nèi)容見:container-monitor-book

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容