如何实现对 ELK 各组件的监控?试试 Metricbea
上一章基于 Filebeat 的日志收集使用Filebeat收集文件中的日志,而Metricbeat则是收集服务器存活性监测和系统指标的指标。
1. Filebeat和Metricbeat的区别
特性 | Filebeat | Heartbeat |
---|---|---|
作用 | 收集和转发日志 | 监测服务可用性 |
数据来源 | 服务器上的日志文件 | 远程主机、API、服务 |
主要功能 | 读取日志并发送到 Elasticsearch/Logstash | 定期探测目标地址的可用性 |
协议 | 读取文件 | ICMP(Ping)、TCP、HTTP |
常见用途 | 日志管理 | Uptime 监控 |
2. 配置教程
1.下载地址
Metricbeat下载地址
wget https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.12.1-linux-x86_64.tar.gz
下载和ES对应的版本,防止出错,ES版本的7.12.1版本下载metricbeat的版本也是7.12.1
2. 官方教程
官方安装教程
3. 我的配置
# 下载解压
curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.12.1-linux-x86_64.tar.gz
tar xzvf metricbeat-7.12.1-linux-x86_64.tar.gz
cd metricbeat-7.12.1-linux-x86_64
# 修改配置
vim metricbeat.yml
增加ES的地址
增加kibana地址
# 查看filebeat 模块
./metricbeat modules list
# 启用模块
./metricbeat modules enable system
# 禁用模块
./metricbeat modules disable docker
# 测试配置是否正确
./metricbeat test config
# 将配置写入kibana
./metricbeat setup
# 启动filebeat
./metricbeat -e
如果启动的时候出现了报错(runtime/cgo: pthread_create failed: Operation not permitted),需要metricbeat.yml中增加下面这个配置
seccomp:
default_action: allow
syscalls:
- action: allow
names:
- rseq
启动成功输出一下日志
kibana中会记录系统的cup、内存和docket的使用情况
3.将metricbeat命令设置服务
每次启动的时候比较麻烦,而且终端退出也会导致命令失效,将命令设置systemctl服务。
1.编写系统服务文件
#如果/etc/systemd/system/metricbeat.service有过修改,需要进行更新,执行下面这个命令
#systemctl daemon-reload
#查看服务是否被正确识别
#systemctl list-unit-files|grep metricbeat
[Unit]
#服务描述,写有意义的内容,便于识别
Description=metricbeat service
[Service]
Type=simple
#设置应用的工作目录
ExecStart=/home/wuzhibin/temp/metricbeat-7.12.1-linux-x86_64/metricbeat -e
WorkingDirectory=/home/wuzhibin/temp/metricbeat-7.12.1-linux-x86_64/
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
# 装置服务配置
systemctl daemon-reload
# 查看服务是否被正确识别
systemctl list-unit-files|grep metricbeat
# 启动服务
systemctl start metricbeat
# 停止服务
systemctl stop metricbeat
# 查看服务状态
systemctl status metricbeat-l
# 查看服务日志
journalctl -flu metricbeat
# 开机自启
systemctl enable myapp.service
# 关闭开机自启
systemctl disable myapp.service