將 Metricbeat 部署到您所有的 Linux、Windows 和 Mac 主機,並將它連接到 Elasticsearch 就大功告成啦:您可以獲取系統級的 CPU 使用率、內存、文件系統、磁盤 IO 和網絡 IO 統計數據,以及獲得如同系統上 top 命令類似的各個進程的統計數據
1,安裝metricbeat
官網下載rpm包安裝
rpm -ivh /nas/nas/softs/elk/6.5.4/metricbeat-6.5.4-x86_64.rpm
默認開啟了system模塊使用命令查看模塊
metricbeat modules list Enabled: system Disabled: aerospike apache ceph couchbase docker dropwizard elasticsearch envoyproxy etcd golang graphite haproxy http jolokia kafka kibana kubernetes kvm logstash memcached mongodb munin mysql nginx php_fpm postgresql prometheus rabbitmq redis traefik uwsgi vsphere windows zookeeper
PS:Enabled模塊為啟用模塊 Disabled模塊為未啟用模塊
啟用新模塊命令,例如啟用nginx模塊
metricbeat modules enable nginx
修改配置文件監控系統CPU,內存等信息
#包含其他模塊的配置文件
metricbeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 1
index.codec: best_compression
#開啟dashboards
setup.dashboards.enabled: true
#輸出至kibana
setup.kibana:
host: "172.16.90.24:5601"
#輸出至elssticsearch
output.elasticsearch:
hosts: ["172.16.90.24:9200"]
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
啟動metricbeat
systemctl start metricbeat
打開kibana頁面查看自動生成了一些圖表

查看hostview



如果多個主機需要監控系統性能查看


2,設置監控nginx性能
開啟nginx模塊
metricbeat modules enable nginx
修改metricbeat配置文件/etc/metricbeat/modules.d/nginx.yml
- module: nginx metricsets: ["stubstatus"] hosts: ["http://172.16.100.132"] #username: "user" #password: "secret" server_status_path: "status"
PS:監控nginx前提需要開啟nginx狀態模塊並在nginx配置下添加以下配置
server{
listen 80;
server_name 172.16.100.132;
location /status
{
stub_status;
access_log off;
}
}
配置成功在web頁面可以查看到以下信息

重啟metricbeat查看


3,設置監控MySQL
開啟MySQL模塊
metricbeat modules enable mysql
修改配置文件
/etc/metricbeat/modules.d/mysql.yml
- module: mysql
metricsets:
- status
# - galera_status
period: 10s
# Host DSN should be defined as "user:pass@tcp(127.0.0.1:3306)/"
# The username and password can either be set in the DSN or using the username
# and password config options. Those specified in the DSN take precedence.
hosts: ["tcp(172.16.90.180:3306)/"]
# Username of hosts. Empty by default.
username: root
# Password of hosts. Empty by default.
password: secret
kibana頁面查看

4,設置監控redis
開啟redis模塊
metricbeat modules enable redis
修改配置文件
/etc/metricbeat/modules.d/redis.yml
- module: redis hosts: ["172.16.90.181:6379"] metricsets: ["info","keyspace"] enables: true period: 10s password: password
PS:如果redis沒有設置認證則密碼不配置
kibana查看

5,設置監控rabbitmq
開啟rabbitmq模塊
metricbeat modules enable rabbitmq
修改配置文件
/etc/metricbeat/modules.d/rabbitmq.yml
- module: rabbitmq metricsets: ["node", "queue", "connection"] enabled: true period: 10s hosts: ["172.16.90.46:15672"] username: admin password: password
kibana頁面查看

6,設置監控kafka
開啟kafka監控模塊
metricbeat modules enable kafka
修改配置文件
/etc/metricbeat/modules.d/kafka.yml

kibana頁面查看

7,設置監控docker
開啟docker監控模塊
metricbeat modules enable docker
設置生效
metricbeat setup

登錄kibana查看




其他程序監控可參考官方文檔 https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html
