Metricbeat介紹
Metricbeat是一種輕量級的托運人,可以將其安裝在服務器上,以定期從操作系統和服務器上運行的服務收集指標。Metricbeat會收集它收集的度量標准和統計信息,並將其運送到指定的輸出,例如Elasticsearch或Logstash。
Metricbeat通過從服務器上運行的系統和服務收集指標來幫助您監視服務器。
官網地址:https://www.elastic.co/cn/beats/metricbeat
文檔地址:https://www.elastic.co/guide/en/beats/metricbeat
Metricbeat原理
Metricbeat由模塊和指標集組成。Metricbeat 模塊定義了從特定服務(例如Redis,MySQL等)收集數據的基本邏輯。該模塊指定有關服務的詳細信息,包括如何連接,收集度量的頻率以及收集哪些度量。
每個模塊都有一個或多個指標集。甲metricset是模塊取和結構中的數據的一部分。度量標准集不是將每個度量標准收集為單獨的事件,而是在對遠程系統的單個請求中檢索多個相關度量標准的列表。因此,例如,Redis模塊提供了一個info
度量標准集,該度量標准集通過運行INFO
命令並解析返回的結果來從Redis收集信息和統計信息 。
Metricbeat使用
環境准備
系統環境:CentOS 7.4
ES版本:7.6.1
Kibana版本:7.6.1
1、下載Metricbeat安裝包,metricbeat-7.6.1-linux-x86_64.tar.gz
2、解壓安裝包
命令:tar -zxvf metricbeat-7.6.1-linux-x86_64.tar.gz
3、查看已經啟動的module
查看module命令:./metricbeat modules list
啟動系統模塊命令:./metricbeat modules enable system
關閉系統模塊命令:./metricbeat modules disable system
可以發現只有system模塊已啟動
4、查看system模塊配置
命令:vim modules.d/system.yml
5、編輯metricbeat.yml配置文件
命令:vim metricbeat.yml
1 output.elasticsearch: 2 # Array of hosts to connect to. 3 hosts: ["127.0.0.1:9200"] 4 5 # Authentication credentials - either API key or username/password. 6 #api_key: "id:api_key" 7 username: "elastic" 8 password: "123456"
6、啟動metricbeat
啟動命令:./metricbeat -e (使用默認文件)
啟動命令(指定配置文件):./metricbeat -e -c metricbeat.yml
后台啟動:nohup ./metricbeat -e &
關閉命令:
-
- 查看metricbeat進程:ps -ef|grep metricbeat
- 殺死進程:kill pid
7、查看ES數據
1)ES中增加了索引 metribeat-7.6.1-2020.06.25-000001
2)索引 metribeat-7.6.1-2020.06.25-000001 數據內容如下:

1 { 2 "_index": "metricbeat-7.6.1-2020.06.25-000001", 3 "_type": "_doc", 4 "_id": "1CwB6XIBk_UZVEKb_T3p", 5 "_version": 1, 6 "_score": 1, 7 "_source": { 8 "@timestamp": "2020-06-25T01:05:15.283Z", 9 "metricset": { 10 "period": 10000, 11 "name": "cpu" 12 }, 13 "event": { 14 "module": "system", 15 "duration": 113555, 16 "dataset": "system.cpu" 17 }, 18 "service": { 19 "type": "system" 20 }, 21 "system": { 22 "cpu": { 23 "softirq": { 24 "pct": 0 25 }, 26 "system": { 27 "pct": 0 28 }, 29 "irq": { 30 "pct": 0 31 }, 32 "idle": { 33 "pct": 0 34 }, 35 "iowait": { 36 "pct": 0 37 }, 38 "nice": { 39 "pct": 0 40 }, 41 "total": { 42 "pct": 0 43 }, 44 "user": { 45 "pct": 0 46 }, 47 "steal": { 48 "pct": 0 49 }, 50 "cores": 1 51 } 52 }, 53 "ecs": { 54 "version": "1.4.0" 55 }, 56 "host": { 57 "name": "H__D", 58 "hostname": "H__D", 59 "architecture": "x86_64", 60 "os": { 61 "version": "7 (Core)", 62 "family": "redhat", 63 "name": "CentOS Linux", 64 "kernel": "3.10.0-1062.18.1.el7.x86_64", 65 "codename": "Core", 66 "platform": "centos" 67 }, 68 "id": "f0f31005fb5a436d88e3c6cbf54e25aa", 69 "containerized": false 70 }, 71 "agent": { 72 "id": "e7b63bfc-e555-4e33-b186-9e5bc5b932f3", 73 "version": "7.6.1", 74 "type": "metricbeat", 75 "ephemeral_id": "20796939-2045-4837-a7d7-630629681e50", 76 "hostname": "H__D" 77 } 78 } 79 } { 80 "settings": { 81 "index": { 82 "number_of_shards": "2", 83 "number_of_replicas": "0" 84 } 85 }, 86 "mappings": { 87 "person": { 88 "properties": { 89 "name": { 90 "type": "text" 91 }, 92 "age": { 93 "type": "integer" 94 }, 95 "mail": { 96 "type": "keyword" 97 }, 98 "hobby": { 99 "type": "text" 100 } 101 } 102 } 103 } 104 }
8、還可以拓展配置,將數據到 Kibana儀表板 中展示