Metricbeat监听容器CPU利用率,内存等使用情况,发送给ElasticSearch并展示在kibana

简介:

Metricbeat是一个轻量级的托运工,你可以在服务器上安装它,定期从操作系统和服务器上运行的服务收集指标,Metricbeat取得它收集的指标和统计数据,并将它们发送到你指定的输出,例如Elasticsearch或Logstash。

可以获取系统级的 CPU 使用率、内存、文件系统、磁盘 IO 和网络 IO 统计数据,还可针对系统上的每个进程获得与 top 命令类似的统计数据。

安装Metricbeat之前需要有Elastic Stack ,没有的话需要安装。

安装:

要下载和安装Metricbeat,使用你系统的命令(deb用于Debian/Ubuntu,rpm用于Redhat/Centos/Fedora,mac用于OS X,docker用于任何docker平台,win用于Windows)。

我是linux centos7,有两种下载方式:

1:使用rpm:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-6.4.2-x86_64.rpm
sudo rpm -vi metricbeat-6.4.2-x86_64.rpm

2:下载压缩包:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.5.1-linux-x86_64.tar.gz
tar xzvf metricbeat-7.5.1-linux-x86_64.tar.gz

配置:

启用要运行的模块。如果您接受默认配置而不启用其他模块,则Metricbeat仅收集系统指标。

您可以启用modules.d目录中定义的默认模块配置 (推荐),也可以将模块配置添加到 metricbeat.yml文件中。该modules.d目录包含所有可用Metricbeat模块的默认配置。

以下示例在目录中启用apachemysql

deb and rpm:

metricbeat modules enable apache mysql

mac and linux:

./metricbeat modules enable apache mysql

配置vim metricbeat.yml

配置kibana仪表盘:

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

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:
  host: "172.17.0.2:5601"
setup.dashboards.enabled: true

输出到ElasticSearch:

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

配置 modules.d

配置容器模块被监听的内容:

[root@localhost modules.d]# vim docker.yml

# Module: docker
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.5/metricbeat-module-docker.html

- module: docker
  metricsets:
    - container
    - cpu
    - diskio
    - event
    - healthcheck
    - info
    - memory
    - network
  period: 10s
  hosts: ["unix:///var/run/docker.sock"]

  # If set to true, replace dots in labels with `_`.
  #labels.dedot: false

  # To connect to Docker over TLS you must specify a client and CA certificate.
  #ssl:
    #certificate_authority: "/etc/pki/root/ca.pem"
    #certificate:           "/etc/pki/client/cert.pem"
    #key:                   "/etc/pki/client/cert.key"

启动:

service metricbeat start
service metricbeat restart
service metricbeat status

如上图显示active (running),说明正常启动,配置没有问题。

kibana 可视化:

可以先查看是否启动成功:

curl -XGET 'http://172.17.0.2:9200/metricbeat-*/_search?pretty'

 OK,继续:

网址输入:http://ip:5601查看kibana 的仪表盘:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章