容器监控实践—Dockbix

栏目: 编程工具 · 发布时间: 6年前

内容简介:Dockbix意为docker+zabbix,即使用zabbix来监控docker容器的插件或者模块,既然有专业的cadvisor、prometheus等容器监控方案,为什么还要用传统的zabbix呢?使用zabbix来监控docker有几种方案,比如:python sdk:

一.概述

Dockbix意为docker+zabbix,即使用zabbix来监控 docker 容器的插件或者模块,既然有专业的cadvisor、prometheus等容器监控方案,为什么还要用传统的zabbix呢?

  • 在docker刚出现时,还没有专业的容器监控方案
  • 公司已有zabbix的成熟实践,想直接集成到zabbix中(虽然不太优雅)

使用zabbix来监控docker有几种方案,比如:

  • 自己写agent,利用docker的api获取stats信息,暴露api接口给zabbix采集
  • 使用zabbix的Module,将docker的采集展示集成到现有的zabbix系统中

如何使用

写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.

如计算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

通过部署一个zabbix agent的docker容器来监控宿主机器和宿主机器上docker的状态。

搬运下开源项目: https://github.com/monitoringartist/zabbix-docker-monitoring

1.在需要监控的宿主机器上运行运行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.配置监控模板

在zabbix server上导入监控docker的模版,可用模板包括:

也可以用docker镜像直接运行,来导入模板: 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为:

容器监控实践—Dockbix

详细的metric的值可以参考: https://github.com/monitoringartist/zabbix-docker-monitoring/blob/master/README.md

3.可视化

zabbix的监控图:

容器监控实践—Dockbix

grafana中也有zabbix的 数据模板

容器监控实践—Dockbix

本文为容器监控实践系列文章,完整内容见: container-monitor-book


以上所述就是小编给大家介绍的《容器监控实践—Dockbix》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

机器学习

机器学习

(美)Tom Mitchell / 曾华军、张银奎、等 / 机械工业出版社 / 2008-3 / 35.00元

《机器学习》展示了机器学习中核心的算法和理论,并阐明了算法的运行过程。《机器学习》综合了许多的研究成果,例如统计学、人工智能、哲学、信息论、生物学、认知科学、计算复杂性和控制论等,并以此来理解问题的背景、算法和其中的隐含假定。《机器学习》可作为计算机专业 本科生、研究生教材,也可作为相关领域研究人员、教师的参考书。一起来看看 《机器学习》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

MD5 加密
MD5 加密

MD5 加密工具

html转js在线工具
html转js在线工具

html转js在线工具