Prometheus-如何监视其他Docker容器 [英] Prometheus - how to monitor other docker containers

查看:622
本文介绍了Prometheus-如何监视其他Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Prometheus 监视我的 docker 容器。我可以使用 Grafana 运行 Prometheus ,但是我不知道如何指示它监视其他Docker容器。
如果可能的话,我想看看一些例子。例如,我在主机上运行了 Ubuntu 容器以及 Gentoo 容器。如何告诉Prometheus监视它们,或者监视内部运行的某些应用程序?
预先感谢您的时间和耐心。

解决方案

您可以使用



简而言之,该想法是使用 cAdvisor 收集有关容器的信息并将其放入 Prometheus 数据库。 Grafana 将查询 Prometheus 数据库并呈现监视图表/值。



要从 cAdvisor收集数据 Prometheus ,您将必须编辑


I want to use Prometheus to monitor my docker containers. I can run Prometheus with Grafana but I do not know how to instruct it to monitor other docker containers. If possible I would like to see some example. For instance I have Ubuntu container running on my host as well as Gentoo container. How can I tell Prometheus to monitor them, or perhaps to monitor some application(s) running inside? Thanks in advance for your time and patience with me.

解决方案

You could use cadvisor, which provides container users an understanding of the resource usage and performance characteristics of their running containers.

A very good article about setting up Prometheus to monitor Docker is using this architecture:

Briefly, the idea is to collect information about containers using cAdvisor and put them into Prometheus database. Grafana will query the Prometheus database and render monitoring charts / values.

To collect data from cAdvisor to Prometheus, you will have to edit a configuration file (prometheus.yml):

scrape_configs:
  - job_name: 'cadvisor'
    scrape_interval: 5s
    static_configs:
      - targets: ['cadvisor:8080']

When you have some data in Prometheus, the you have to use Grafana to view it. A (short) example of monitoring json queries you could import into Grafana is as follow:

Get % of user CPU :

  "targets": [
    {
      "expr": "sum(rate(container_cpu_user_seconds_total{image!=\"\"}[1m])) / count(node_cpu{mode=\"system\"}) * 100",
      "interval": "10s",
      "intervalFactor": 1,
      "legendFormat": "",
      "refId": "A",
      "step": 10
    }
  ]

Get % of RAM used :

  "targets": [
    {
      "expr": "(sum(node_memory_MemTotal) - sum(node_memory_MemFree+node_memory_Buffers+node_memory_Cached) ) / sum(node_memory_MemTotal) * 100",
      "interval": "10s",
      "intervalFactor": 2,
      "legendFormat": "",
      "refId": "A",
      "step": 20
    }
  ]

For complete json data (too long to be posted here), you can clone this repository :

git clone https://github.com/stefanprodan/dockprom

And try to import this Grafana json.

I'm currently using this architecture to monitor a docker swarm mode cluster in production, and here is the output of the monitoring that you can find in the github repository.

这篇关于Prometheus-如何监视其他Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆