文章目录
Metricbeat介绍
Metricbeat 是一个轻量级指标采集器,可以从系统或服务收集指标存储到es中,进行试试分析
Metricbeat组成
Metricbeat有2部分组成,一部分是Module,另一部分为Metricset。
Module
收集的对象,如:mysql、redis、nginx、操作系统等;
Metricset
收集指标的集合,如:cpu、memory、network等;
以Redis Module为例:
Metricbeat部署及测试
部署
下载安装包,并解压到 /opt/apps 目录下,目录结构如下
[root@localhost apps]# ll
总用量 329376
drwxr-xr-x. 9 elsearch elsearch 155 6月 23 15:43 elasticsearch-6.5.4
-rw-r--r--. 1 root root 113322649 6月 23 15:24 elasticsearch-6.5.4.tar.gz
lrwxrwxrwx. 1 elsearch elsearch 19 6月 23 15:32 elsearch -> elasticsearch-6.5.4
lrwxrwxrwx. 1 root root 27 6月 28 13:43 filebeat -> filebeat-6.5.4-linux-x86_64
drwxr-xr-x. 7 root root 4096 6月 28 14:58 filebeat-6.5.4-linux-x86_64
-rw-r--r--. 1 root root 11287049 6月 27 19:14 filebeat-6.5.4-linux-x86_64.tar.gz
lrwxrwxrwx. 1 root root 13 6月 23 14:50 jdk -> jdk1.8.0_191/
drwxr-xr-x. 7 10 143 245 10月 6 2018 jdk1.8.0_191
-rw-r--r--. 1 root root 191753373 12月 25 2018 jdk-8u191-linux-x64.tar.gz
lrwxrwxrwx. 1 root root 29 6月 28 18:07 metricbeat -> metricbeat-6.5.4-linux-x86_64
drwxr-xr-x. 4 root root 204 6月 28 18:06 metricbeat-6.5.4-linux-x86_64
-rw-r--r--. 1 root root 19925669 6月 27 20:28 metricbeat-6.5.4-linux-x86_64.tar.gz
lrwxrwxrwx. 1 root root 12 6月 28 13:34 nginx -> nginx-1.12.2
drwxr-xr-x. 9 1001 1001 186 6月 28 13:39 nginx-1.12.2
-rw-r--r--. 1 root root 981687 2月 19 2019 nginx-1.12.2.tar.gz
配置及测试
修改配置文件metricbeat.yml内容如下:
[root@localhost metricbeat]# vi metricbeat.yml
metricbeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 1
index.codec: best_compression
setup.kibana:
output.elasticsearch:
hosts: ["192.168.12.10:9200","192.168.12.11:9200","192.168.12.12:9200"]
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
配置中使用了 modules.d 下的模块,我们可以看到该目录下目前只有 system.yml 文件可用
启动 metricbeat 服务
./metricbeat -e
可以在es中看到采集的系统指标信息
Module 使用
启用nginx Module 并修改配置
[root@localhost metricbeat]# ./metricbeat modules enable nginx
Enabled nginx
修改配置文件 odules.d/nginx.yml 内容如下
- module: nginx
#metricsets:
# - stubstatus
period: 10s
# Nginx hosts
hosts: ["http://192.168.12.10"]
# Path to server status. Default server-status
server_status_path: "nginx-status"
#username: "user"
#password: "secret"
nginx 安装对应的Module
在nginx中,需要开启状态查询,才能查询到指标数据
重新编译安装nginx
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
make
make install
修改 nginx配置 nginx.conf 增加如下配置:
location /nginx-status {
stub_status on;
access_log off;
}
启动nginx 并访问 http://192.168.12.10/nginx-status 可以查询到nginx状态如下
指标说明
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))
启动 metricbeat 并观察es中指标结果
#启动
./metricbeat -e
es中可以看到 采集到的 nginx数据如下