简介

定期收集操作系统或应用服务的指标数据
存储到Elasticsearch中,进行实时分析

Metricbeat有2部分组成
一部分是Module,另一部分为Metricset。

  • Module

收集的对象,如:mysql、redis、nginx、操作系统等;

  • Metricset

收集指标的集合,如:cpu、memory、network等;
image.png
支持输出的类型有

  • ElasticSearch
  • LogStash
  • Kafka
  • Redis
  • File
  • Console
  • Cloud

metricbeat也有很多module,需要收集哪个module的信息,即启动该module即可,命令与Filebeat类似

  1. ## module列表
  2. ./metricbeat modules list
  3. ## 启用module
  4. ./metricbeat modules enable 模块名
  5. ## 禁用module
  6. ./metricbeat modules disable 模块名

系统监控指标

默认的model就开了系统监控指标

  1. vim metricbeat.yml

添加如下内容

  1. metricbeat.config.modules:
  2. path: ${path.config}/modules.d/*.yml
  3. reload.enabled: false
  4. setup.template.settings:
  5. index.number_of_shards: 1
  6. index.codec: best_compression
  7. setup.kibana:
  8. output.elasticsearch:
  9. hosts: [""127.0.0.1:9200"]
  10. processors:
  11. - add_host_metadata: ~
  12. - add_cloud_metadata: ~

默认会指定的配置文件,就是在

  1. ${path.config}/modules.d/*.yml

也就是 system.yml文件,我们也可以自行开启其它的收集

启动
在配置完成后,我们通过如下命令启动即可
./metricbeat -e
在ELasticsearch中可以看到,系统的一些指标数据已经写入进去了:
image.png
system module配置

  1. - module: system
  2. period: 10s # 采集的频率,每10秒采集一次
  3. metricsets: # 采集的内容
  4. - cpu
  5. - load
  6. - memory
  7. - network
  8. - process
  9. - process_summary

Metricbeat Module

Metricbeat Module的用法和我们之前学的filebeat的用法差不多

  1. #查看列表
  2. ./metricbeat modules list

能够看到对应的列表

  1. Enabled:
  2. system #默认启用
  3. Disabled:
  4. aerospike
  5. apache
  6. ceph
  7. couchbase
  8. docker
  9. dropwizard
  10. elasticsearch
  11. envoyproxy
  12. etcd
  13. golang
  14. graphite
  15. haproxy
  16. http
  17. jolokia
  18. kafka
  19. kibana
  20. kubernetes
  21. kvm
  22. logstash
  23. memcached
  24. mongodb
  25. munin
  26. mysql
  27. nginx
  28. php_fpm
  29. postgresql
  30. prometheus
  31. rabbitmq
  32. redis
  33. traefik
  34. uwsgi
  35. vsphere
  36. windows

Nginx Module

开启Nginx Module
在nginx中,需要开启状态查询,才能查询到指标数据。

  1. #重新编译nginx
  2. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
  3. make
  4. make install
  5. ./nginx -V #查询版本信息
  6. nginx version: nginx/1.11.6
  7. built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
  8. configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module
  9. #配置nginx
  10. vim nginx.conf
  11. location /nginx-status {
  12. stub_status on;
  13. access_log off;
  14. }
  15. # 重启nginx
  16. ./nginx -s reload

测试
image.png
结果说明:

  • 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))

配置nginx的module

  1. #启用redis module
  2. ./metricbeat modules enable nginx
  3. #修改redis module配置
  4. vim modules.d/nginx.yml

然后修改下面的信息

  1. # Module: nginx
  2. # Docs: https://www.elastic.co/guide/en/beats/metricbeat/6.5/metricbeat-modulenginx.
  3. html
  4. - module: nginx
  5. #metricsets:
  6. # - stubstatus
  7. period: 10s
  8. # Nginx hosts
  9. hosts: ["http://127.0.0.1"]
  10. # Path to server status. Default server-status
  11. server_status_path: "nginx-status"
  12. #username: "user"
  13. #password: "secret"

修改完成后,启动nginx

  1. #启动
  2. ./metricbeat -e

测试
可以看到,nginx的指标数据已经写入到了Elasticsearch
image.png