1. 程式人生 > 實用技巧 >Metricbeat入門簡介

Metricbeat入門簡介

一、什麼是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