Metricbeat安装及使用

metricbeat简介

  • Metricbeat可以定期收集操作系统和服务器的运行指标(CPU,内存,硬盘,IO,读写速度,进程等等),Metricbeat可以将收集到的指标和数据发送到你指定的输出,比如:elasticsearch,最终达成监视服务器的目标。

metricbeat安装

  • 下载metricbeat rpm包,安装:
下载:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-6.2.1-x86_64.rpm

rpm安装:sudo rpm -vi metricbeat-6.2.1-x86_64.rpm

[root@localhost metricbeat]# curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-6.2.1-x86_64.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8798k  100 8798k    0     0  29566      0  0:05:04  0:05:04 --:--:-- 25001
[root@localhost metricbeat]# sudo rpm -vi metricbeat-6.2.1-x86_64.rpm
warning: metricbeat-6.2.1-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing packages for installation...
metricbeat-6.2.1-1
  • 配置metricbeat:
vi /etc/metricbeat/metricbeat.yml

内容如下:(官网有详细配置说明,此配置只做参考)

metricbeat.modules:
- 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

# 直接发送elasticsearch
output.elasticsearch:
  hosts: ["172.30.1.45:9200"]

# 要加载仪表板,可以在metricbeat设置中启用仪表板加载。当仪表板加载被启用时,Metricbeat使用Kibana API来加载样本仪表板。只有当Metricbeat启动时,才会尝试仪表板加载。
# 设置kibana服务地址
setup.kibana.host: "172.30.1.45:5601"
# 加载默认的仪表盘样式
setup.dashboards.enabled: true
# 设置如果存在模板,则不覆盖原有模板
setup.template.overwrite: false
  • 启动服务(前提是es和kibana已经启动):sudo service metricbeat start(或者:/etc/init.d/metricbeat start
[root@localhost metricbeat]# sudo service metricbeat start
Starting metricbeat: 2018/04/24 03:23:51.152168 beat.go:264: INFO Home path: [/usr/share/metricbeat] Config path: [/etc/metricbeat] Data path: [/var/lib/metricbeat] Logs path: [/var/log/metricbeat]
2018/04/24 03:23:51.152222 beat.go:174: INFO Setup Beat: metricbeat; Version: 6.2.1
2018/04/24 03:23:51.152357 logp.go:219: INFO Metrics logging every 30s
2018/04/24 03:23:51.152403 output.go:167: INFO Loading template enabled. Reading template file: /etc/metricbeat/metricbeat.template.json
2018/04/24 03:23:51.156313 output.go:178: INFO Loading template enabled for Elasticsearch 2.x. Reading template file: /etc/metricbeat/metricbeat.template-es2x.json
2018/04/24 03:23:51.160122 client.go:107: INFO Elasticsearch url: http://172.30.1.45:9200
2018/04/24 03:23:51.160211 outputs.go:106: INFO Activated elasticsearch as output plugin.
2018/04/24 03:23:51.160318 publish.go:291: INFO Publisher name: localhost.localdomain
2018/04/24 03:23:51.160540 async.go:63: INFO Flush Interval set to: 1s
2018/04/24 03:23:51.160559 async.go:64: INFO Max Bulk Size set to: 50
2018/04/24 03:23:51.160695 metricbeat.go:25: INFO Register [ModuleFactory:[system], MetricSetFactory:[apache/status, haproxy/info, haproxy/stat, mongodb/status, mysql/status, nginx/stubstatus, postgresql/activity, postgresql/bgwriter, postgresql/database, redis/info, redis/keyspace, system/core, system/cpu, system/diskio, system/filesystem, system/fsstat, system/load, system/memory, system/network, system/process, zookeeper/mntr]]
Config OK
                                                           [确定]
  • 检查metricbeat是否正常运行:curl -XGET ‘http://172.30.1.45:9200/metricbeat-*/_search?pretty’(返回索引对应内容)

  • 显示输出

浏览器中访问http://172.30.1.45:5601/ 
在discover项选择metricbeat-*查看metric的数据; 
在dashboard项点击open选择要查看的数据,如: 查看Metricbeat-memory: 

你可能感兴趣的:(日志,ELK,metricbeat,ELK)