博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How-to monitor Docker ?
阅读量:5939 次
发布时间:2019-06-19

本文共 4795 字,大约阅读时间需要 15 分钟。

hot3.png

How-to monitor Docker ? 博客分类: Kubernetes docker

The use of containers needs a strong supervision with different metrics than traditional VMs. For monitor Docker hosts, I use a stack of a time-series database,  the data visualiser and finally  to ship our metrics from few hosts.

I'll show you how-to deploy InfluxDB and Grafana on a docker host and install Telegraf on a Debian-based distribution. 

For sure, we can use Telegraf on Docker but personally, I prefer to install it directly on hosts to make it more permanent. 
If docker go wrong, our metrics are already shipped.

For launch my supervision stack, I use Docker-compose, you can install it easily using Python-pip :

apt-get -y install python-pip  pip-install docker-compose

Now, we can create our docker-compose.yml file :

influxdb:   image: tutum/influxdb   restart: always   expose:     - "8090"     - "8099"   ports:     - "127.0.0.1:8083:8083"     - "8086:8086"   volumes:     - /srv/influxdb:/data   environment:     - ADMIN_USER: "telegraf"     - INFLUXDB_INIT_PWD: "Astr0ngPassw0rd"     - PRE_CREATE_DB: "telegraf" grafana:   image: grafana/grafana:latest   restart: always   ports:     - "3000:3000"   volumes:     - /srv/grafana:/var/lib/grafana   environment:     - GF_SECURITY_ADMIN_PASSWORD: "Astr0ngPassw0rd"

This file will create a InfluxDB container with the port 8086 exposed on the Internet (to listen for metrics) with a volume for store data and a Grafana container with a volume for the configuration and the port 3000 exposed for the WebUI.

For security reason, we change InfluxDB admin user and password because we expose our database on Internet, same thing for the Grafana UI.

At this point, we are ready to receive metrics and visualise them. For ship some metrics, I use Telegraf, a small Go tools who ship all metrics we need and add some interesting plugins like Network or Docker.

Let's download the last .deb file and install it on each of our Docker Hosts :

wget https://dl.influxdata.com/telegraf/releases/telegraf_1.0.0-beta3_amd64.deb  dpkg -i telegraf_1.0.0-beta3_amd64.deb

Now, Telegraf is installed, we can now create our configuration file. 

Let's create a new /etc/telegraf/telegraf.conf file :

[agent]  interval = "10s"  round_interval = true  metric_batch_size = 1000  metric_buffer_limit = 10000  collection_jitter = "0s"  flush_interval = "10s"  flush_jitter = "0s"  precision = ""  debug = false  quiet = false  hostname = ""  omit_hostname = false[[outputs.influxdb]]  urls = ["http://
:8086"] # required database = "telegraf" # required retention_policy = "" write_consistency = "any" timeout = "5s" username = "telegraf" password = "Astr0ngPassw0rd"[[inputs.cpu]] percpu = true totalcpu = true fielddrop = ["time_*"][[inputs.disk]] ignore_fs = ["tmpfs", "devtmpfs"][[inputs.diskio]][[inputs.kernel]][[inputs.mem]][[inputs.processes]][[inputs.swap]][[inputs.docker]] endpoint = "unix:///var/run/docker.sock"[[inputs.net]] interfaces = ["eth0"]

This file is quite simple, we take metrics about cpu, disk, io, kernel, mem, processes, swap, network and Docker (this last plugin is very interesting for us).

Before launch Telegraf, we had to add telegraf user to the docker group :

usermod -aG docker telegraf  service telegraf restart

Now, our Telegraf agent is sending hundred metrics to our InfluxDB container. Let's visualise them ! 

Go on  and connect to Grafana with these credentials (admin:Astr0ngPassw0rd) :

Before all, we need to connect Grafana with our InfluxDB instance, for this, add a Data Source :

Now, we can create our first Dashboard, go to Dashboard > New :

After, we can add a graph :

Let's select some metrics (CPU Usage for example) :

Yeah ! we got our first graph. You can now create tons of graphs for CPU, Memory, Disks usage ...

If you want to create a Network graph, you'll see a constant rise of your metrics. It's normal. To have a bytes/s graph you have to write a request like this :

SELECT derivative("bytes_sent", 1s) FROM "net" WHERE "host" = 'docker'

You can print a single value in your Dashboard, for example the number of containers running on our host. This is possible with the Docker plugin of Telegraf.

Let's create a SingleStat in your Panel :

At this point, you can create few nice dashboards showing some interesting information about your containers or your hosts.

For example, here is a graph of this website bandwidth (managed by docker-compose) :

I have finished with this tutorial, I hope it was useful, you can now easily send all your metrics from some Docker hosts to your new Docker supervision Stack.

I suggest you use Grafana behind a TLS reverse-proxy like Nginx. I'm writing an article about that, stay tuned !

 

https://opsnotice.xyz/how-to-monitor-docker-hosts/

转载于:https://my.oschina.net/xiaominmin/blog/1598555

你可能感兴趣的文章
[Android]权限处理
查看>>
Spark bind on port 0. Attempting port 1 问题解决
查看>>
兼容所有浏览器的复制到剪切板功能,悬浮层不能复制问题解决
查看>>
day 20 第一阶段考试总结
查看>>
我的友情链接
查看>>
Centos 7.5 部署DNS
查看>>
yum简介
查看>>
cp讲解
查看>>
MariaDB Galera Cluster 部署(如何快速部署MariaDB集群)
查看>>
如何在 Swift 语言下使用 iOS Charts API 制作漂亮图表?
查看>>
论代码审查的重要性
查看>>
「docker实战篇」python的docker爬虫技术-导学(一)
查看>>
linux日志基础介绍
查看>>
如何关闭SElinux
查看>>
处理器之MMU(三)
查看>>
172.16.82.0/25的含义,IP段,掩码
查看>>
测试之路
查看>>
终于对了
查看>>
RabbitMQ集群
查看>>
Apache防盗链和隐藏版本信息
查看>>