目录
三、MetricBeat
1、下载metricbeat
[root@k8s-fengfan elk2.2.2]# wget https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-6.2.2-linux-x86_64.tar.gz
[root@k8s-fengfan elk2.2.2]# tar xvf metricbeat-6.2.2-linux-x86_64.tar.gz
Metricbeat有2部分组成,一部分是Module,另一部分为Metricset。
- Module
收集的对象,如:mysql、redis、操作系统等;
- Metricset
收集指标的集合,如:cpu、memory、network等;
2、配置监控指标信息
1、配置文件metricbeat.yml
这边测试直接输出到elasticseatch并且配置开启kibana的Dashboard
setup.dashboards.enabled: true
开启自动创建仪表盘监控
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:
host: "k8s-fengfan:5601"
setup.dashboards.enabled: true
output.elasticsearch:
hosts: ["k8s-fengfan:9200"]
#启动命令
[root@k8s-fengfan metricbeat-6.2.2-linux-x86_64]# ./metricbeat -e
2、配置监控
metricbeat默认开启了system模块的监控,这边开启了docker的监控
[root@k8s-fengfan metricbeat-6.2.2-linux-x86_64]# ./metricbeat modules list
Enabled:
docker
system
Disabled:
aerospike
apache
ceph
couchbase
dropwizard
elasticsearch
etcd
golang
graphite
haproxy
http
jolokia
kafka
kibana
kubernetes
logstash
memcached
mongodb
mysql
nginx
php_fpm
postgresql
prometheus
rabbitmq
redis
uwsgi
vsphere
windows
zookeeper
1、监控system模块
开启system监控然后启动metricbeat
# 开启system监控
[root@k8s-fengfan metricbeat-6.2.2-linux-x86_64]# ./metricbeat modules enable system
# 启动metricbeat
[root@k8s-fengfan metricbeat-6.2.2-linux-x86_64]# ./metricbeat -e
system.yml配置
- module: system
period: 10s
metricsets:
- cpu
- load
- memory
- network
- process
- process_summary
#- core
#- diskio
#- socket
processes: ['.*']
process.include_top_n:
by_cpu: 5 # include top 5 processes by CPU
by_memory: 5 # include top 5 processes by memory
- module: system
period: 1m
metricsets:
- filesystem
- fsstat
processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'
- module: system
period: 15m
metricsets:
- uptime
页面展示
1、 [Metricbeat System] Overview
2、[Metricbeat System] Host overview
3、 [Metricbeat System] Containers overview
2、监控docker模块
开启docker监控
# 开启docker监控
[root@k8s-fengfan metricbeat-6.2.2-linux-x86_64]# ./metricbeat modules enable docker
# 启动metricbeat
[root@k8s-fengfan metricbeat-6.2.2-linux-x86_64]# ./metricbeat -e
页面展示
3、监控nginx模块
nginx的监控需要一些额外的配置
nginx应用的nginx.conf配置需要加上以下内容,因为metricbeat的nginx插件默认指定了 server_status_path: "server-status"
location = /server-status{
stub_status;
}
然后重启nginx
# 重启nginx
./sbin/nginx -s reload
# 如果报错 需要重新安装的时候指定一下
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
make && make install
metricbeat的nginx模块配置如下:
- module: nginx metricsets: ["stubstatus"] period: 10s # Nginx hosts hosts: ["http://k8s-fengfan"] # Path to server status. Default server-status server_status_path: "server-status"
# 开启docker监控
[root@k8s-fengfan metricbeat-6.2.2-linux-x86_64]# ./metricbeat modules enable nginx
# 启动metricbeat
[root@k8s-fengfan metricbeat-6.2.2-linux-x86_64]# ./metricbeat -e
页面展示