系統級監控 Metricbeat
用於從系統和服務收集指標。從 CPU 到內存,從 Redis 到 Nginx,Metricbeat 能夠以一種輕量型的方式,輸送各種系統和服務統計數據。
可以獲取系統級的 CPU 使用率、內存、文件系統、磁盤 IO 和網絡 IO 統計數據,以及獲得如同系統上 top 命令類似的各個進程的統計數據。
1. 下載部署metricbeat:metricbeat-6.6.0-x86_64.rpm
curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-6.6.0-x86_64.rpm
rpm -i metricbeat-6.6.0-x86_64.rpm
可獲取:CPU使用率、內存、文件系統、磁盤IO和網絡IO統計數據
根據這種安裝方式,將產生如下目錄:
rpm格式壓縮包安裝後,一般分爲3個目錄:
/usr/share 下存放軟件安裝的主目錄
/etc/XX 下存放的是metricbeat的配置文件(XX一般爲安裝的軟件名)
/var/log/XX 一般是軟件日誌文件的位置
2. metricbeat目錄結構
2.1 cd /etc/metricbeat/ //查看全部配置文件
其下子目錄modules.d爲metricbeat支持的各種插件的配置文件
2.2 cd /etc/init.d/
metricbeat啓動文件所在目錄
systemctl start metricbeat.service //啓動命令
systemctl stop metricbeat.service //停止命令
systemctl restart metricbeat.service //重新啓動命令
systemctl status metricbeat.service //查看狀態命令
3. 配置metricbeat
3.1 可將metricbeat數據寫入logstash或者ES,配置寫入ES如下操作
# cd /etc/metricbeat/
# vi metricbeat.yml
#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["10.88.**.**:9200"]
3.2 在metricbeat.yml裏打開module模塊的使用
# vi metricbeat.yml
#========================== Modules configuration ============================
metricbeat.config.modules:
# Glob pattern for configuration loading
path: ${path.config}/modules.d/*.yml
# Set to true to enable config reloading
reload.enabled: true
# Period on which files under path should be checked for changes
reload.period: 10s
3.3 配置kibana儀表板
要加載儀表板,可以在metricbeat設置中啓用儀表板加載。當儀表板加載被啓用時,Metricbeat使用Kibana API來加載樣本儀表板。只有當Metricbeat啓動時,纔會嘗試儀表板加載。
# vi metricbeat.yml
#============================== Dashboards =====================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here, or by using the `-setup` CLI flag or the `setup` command.
setup.dashboards.enabled: true
#============================== Kibana =====================================
# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:
# Kibana Host
# Scheme and port can be left out and will be set to the default (http and 5601)
# In case you specify and additional path, the scheme is required: http://localhost:5601/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
host: "10.88.**.**:5601"
4. 啓動metricbeat
4.1 重啓服務
# systemctl restart metricbeat.service
4.2 載入Kibana儀表板
# metricbeat setup -e
出現問題:failed to import index-pattern
# curl -XPUT "http://10.88.0.54:9200/.kibana/_settings" -H 'Content-Type: application/json' -d'
{
"index": {
"blocks": {
"read_only_allow_delete": "false"
}
}
}'
5. 解決module加載
metricbeat modules enable system # 啓用system模塊
啓動docker的指標收集
5.1 # vi metricbeat.reference.yml
檢查如下內容是否放開
#------------------------------- Docker Module -------------------------------
- module: docker
metricsets:
- "container"
- "cpu"
- "diskio"
- "healthcheck"
- "info"
#- "image"
- "memory"
- "network"
hosts: ["unix:///var/run/docker.sock"]
period: 10s
5.2 # systemctl restart metricbeat
5.3 # metricbeat setup -e