一、什么是Metricbeat?
- 輕量型指標采集器
- 用於從系統和服務收集指標。Metricbeat能夠以一種輕量型的方式,輸送各種系統和服務統計數據,從CPU 到內存,從Redis到Nginx,不一而足。
- 定期收集操作系統或應用服務的指標數據
- 存儲到Elasticsearch中,進行實時分析
二、Metricbeat組成
Metricbeat有2部分組成,一部分是Module,另一個部分為Metricset
- Module
- 收集的對象:如 MySQL、Redis、Nginx、操作系統等
- Metricset
- 收集指標的集合:如 cpu、memory,network等
以Redis Module為例:
redis安裝:
參考:https://www.cnblogs.com/hsyw/p/13254117.html
三、部署Metricbeat與收集指標
3.1、下載
[root@node1 app]# wget https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-6.5.4-linux-x86_64.tar.gz
3.2、安裝
[root@node1 app]# tar -zxvf metricbeat-6.5.4-linux-x86_64.tar.gz
[root@node1 app]# mv metricbeat-6.5.4-linux-x86_64 metricbeat
3.3、更改配置文件
[root@node1 app]# cd metricbeat
[root@node1 metricbeat]# vim metricbeat.yml
# 第94行,改為ES集群的IP地址們
hosts: ["192.168.1.111","192.168.1.112","192.168.1.113"]ES集群的IP地址們
PS: 默認會指定的模塊配置文件,在${path.config}/modules.d/*.yml ---cd modules.d/
3.4、啟動
[root@node1 metricbeat]# ./metricbeat -e
3.5、頁面查看
可以看到多一個metricbeat-6.5.4-2020.12.06庫
3.6、system module配置
- module: system
period: 10s # 采集的頻率,每10秒采集一次
metricsets: # 采集的內容
- cpu
- load
- memory
- network
- process
- process_summary
四、Metricbeat Module
4.1、查看有那些Module
#查看列表
[root@node1 metricbeat]# ./metricbeat modules list
Enabled: #默認開啟的只有system
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
4.2、開啟Nginx Module
在nginx中,需要開啟狀態查詢,才能查詢到指標數據。
[root@node1 nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
[root@node1 nginx-1.10.1]# make && make install
# nginx 安裝路徑
[root@node1 nginx]# pwd
/usr/local/nginx
# 查看版本、模塊信息
[root@node1 sbin]# ./nginx -V
nginx version: nginx/1.10.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module
#配置nginx、location可存在多個,找到location放在它上方即可(server模塊里面)
[root@node1 nginx]# vim conf/nginx.conf
location /nginx-status {
stub_status on;
access_log off;
}
# 重啟nginx
[root@node1 nginx]# sbin/nginx -s reload
# 頁面訪問
http://192.168.1.129/nginx-status
# 顯示
Active connections: 2
server accepts handled requests
5 5 16
Reading: 0 Writing: 1 Waiting: 1
# 顯示結果說明:
- Active connections:正在處理的活動連接數
- server accepts handled requests
- 第一個 server 表示Nginx啟動到現在共處理了9個連接
- 第二個 accepts 表示Nginx啟動到現在共成功創建 9 次握手
- 第三個 handled requests 表示總共處理了 21 次請求
- 請求丟失數 = 握手數 - 連接數 ,可以看出目前為止沒有丟失請求
- Reading: 0 Writing: 1 Waiting: 1
- Reading:Nginx 讀取到客戶端的 Header 信息數
- Writing:Nginx 返回給客戶端 Header 信息數
- Waiting:Nginx 已經處理完正在等候下一次請求指令的駐留鏈接(開啟keep-alive的情況下,這個值等於
Active - (Reading+Writing))
4.3、配置metricbeat的nginx module
#啟用nginx module
[root@node1 metricbeat]# ./metricbeat modules enable nginx
Enabled nginx
#修改redis module配置
[root@node1 metricbeat]# vim modules.d/nginx.yml
- module: nginx
#metricsets:
# - stubstatus
period: 10s # 10秒采集一次
# Nginx hosts
hosts: ["http://192.168.1.129"] # nginx服務器IP地址
# Path to server status. Default server-status
server_status_path: "nginx-status" # 剛剛配置的名稱
#username: "user"
#password: "secret"
4.4、啟動
[root@node1 metricbeat]# ./metricbeat -e