簡介:
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模塊的默認配置。
以下示例在目錄中啓用apache
和mysql
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 的儀表盤: