美文网首页
小记:mestricbeat监控docker容器与宿主机服务

小记:mestricbeat监控docker容器与宿主机服务

作者: 薛云龙 | 来源:发表于2018-06-15 10:39 被阅读53次

由于生产环境的搭建部署,我们需要一套对于docker服务的监控。在网上已经翻阅了很多docker监控的方案,由于我们正好使用了elk,这里就通过mestricbeat来做服务监控了。先看一下效果图


支持的可视化服务状态

我们点开一个docker的overview。


docker服务状态监控

快速构建elk

1.首先,你的es和kibana是必不可少的。可以通过下边yaml快速构建el+kibana的服务:
因为yaml中指定了external的decision-platform网络,所以需要你创建的docker的decision-platform网络。

version: "3.6"
services:
    elasticsearch:
     image: elasticsearch:5.6.8
     ports:
       - 9200:9200
     container_name: elasticsearch
     volumes:
       - /data/docker/elasticsearch/data:/usr/share/elasticsearch/data
       - /data/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins
       - /data/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
     environment:
         ES_JAVA_OPTS= "Xms1g -Xmx1g"
     networks:
       - decision-platform

    kibana:
     image: kibana:5.6.8
     ports:
       - 5601:5601
     container_name: kibana
     volumes:
       - /data/docker/kibana/plugins:/usr/share/elasticsearch/plugins
     networks:
       - decision-platform

networks:
  decision-platform:
    external:
      name: decision-platform

快速构建metricbeat

接下来,我们来构造metricbeat。设计到metricbeat的文件可以在我的github上找:https://github.com/xueyunlong123/docker-elk-example
docker-compose文件如下:

version: '2'

services:

  metricbeat:
    build:
      context: metricbeat/
    container_name: metricbeat
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /proc:/hostfs/proc:ro
      - /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro
      - /:/hostfs:ro
      - ./metricbeat/metricbeat.yml:/usr/share/metricbeat/metricbeat.yml:ro
      - ./metricbeat/modules.d:/usr/share/metricbeat/modules.d:ro
      -  /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
    user: "root"
    network_mode: host
    command: -system.hostfs=/hostfs -e
    restart: always

1.简单说明一下几个参数,需要将宿主机的文件映射到docker内部,比如metricbeat.yml配置文件,modules.d支持的modules配置。
2.另外需要注意的一个问题是,需要设置user为root,因为在容器内获取/var/run/docker.sock这个文件时,需要的权限比较大。
我们再继续看,metricbeat相关的配置:


#============================== Kibana =====================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:

  # Kibana Host
  # Scheme and port can be left out and will be set to the default (http and 5601)
  # In case you specify and additional path, the scheme is required: http://localhost:5601/path
  # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
  host: "http://172.18.0.3:5601"

#============================= Elastic Cloud ==================================

# These settings simplify using metricbeat with the Elastic Cloud (https://cloud.elastic.co/).

# The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options.
# You can find the `cloud.id` in the Elastic Cloud web UI.
#cloud.id:

# The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
#cloud.auth:

#================================ Outputs =====================================

# Configure what output to use when sending the data collected by the beat.

#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["http://172.18.0.2:9200"]

  # Optional protocol and basic auth credentials.
  #protocol: "https"
  username: "elastic"
  password: "test"

这里主要是配置kibana和es。
好了。基本到这里,我们把所有服务正常启动,就能够在kibana中的dashboard看到数据了。

相关文章

网友评论

      本文标题:小记:mestricbeat监控docker容器与宿主机服务

      本文链接:https://www.haomeiwen.com/subject/myspeftx.html