系统级监控 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