elastic stack 的指标监控可以通过 metricbeat 配合几十种的 module 对各种服务器环境及服务实例自身的状态信息进行采集和上报。
配置启动- 安装修改相关配置
- 输出到 ES
output.elasticsearch:
hosts: ["myEShost:9200"]
username: "metricbeat_internal"
password: "YOUR_PASSWORD"
(可选)初始化 Kibana(如果 Kibana 和 ES 在同一集群可跳过) setup.kibana:
host: "mykibanahost:5601"
username: "my_kibana_user"
password: "{pwd}"
./metricbeat modules enble ${module1} ${module2}
在集群中初始化采集模块相关配置./metricbeat setup -e启动 metricbeat
- 给配置文件赋予权限
sudo chown root metricbeat.yml sudo chown root modules.d/system.yml启动
sudo ./metricbeat -e &
| 目录 | 描述 | 配置 key | 默认路径 | deb / rpm | docker | zip, tar.gz, or tgz | brew |
|---|---|---|---|---|---|---|---|
| home | 安装目录 | path.home | - | /usr/share/metricbeat | /usr/share/metricbeat | {extract.path} | /usr/local/var/homebrew/linked/metricbeat-full |
| bin | 应用的执行目录 | - | {path.home}/bin | /usr/share/metricbeat/bin | /usr/share/metricbeat | {extract.path} | /usr/local/var/homebrew/linked/metricbeat-full/bin |
| config | 配置文件目录 | path.config | {path.home} | /etc/metricbeat | /usr/share/metricbeat | {extract.path} | /usr/local/etc/metricbeat |
| data | 数据目录 | path.data | {path.home}/data | /var/lib/metricbeat | /usr/share/metricbeat/data | {extract.path}/data | /usr/local/var/lib/metricbeat |
| logs | 日志目录 | path.logs | {path.home}/logs | /var/log/metricbeat | /usr/share/metricbeat/logs | {extract.path}/logs | /usr/local/ver/log/metricbeat |
帮助(help)
./metricbeat -h
./metricbeat help export
导出(export),可以导出配置和看板等
./metricbeat export config --es.version 7.10.2
./metricbeat export dashboard --id="xx" > dashboard.json
keystore,管理密钥相关配置,doc
./metricbeat keystore create
模块(modules),相关配置在 modules.d 文件夹里,通过命令开启/关闭模块,doc
./metricbeat modules list
./metricbeat modules enable mysql
初始化(setup),在目标集群里初始化对应的模板、pipeline、看板等,doc
./metricbeat setup -e
./metricbeat setup --dashboards -e
示例文件 (doc)
全局配置
- metricbeat.max_start_delay 最大延迟开始时间
- metricbeat 在启动(重启)时会随机一个 [0, max_start_delay) 时间,以免大量实例同时启动产生的惊群效应如果设为 0 则禁止延迟启动默认为 10s
- metricbeat 会在每一个上报的事件数据包里添加时序标记(timeseries.instance)默认值为 true (添加)
常规配置
- name 传入字符串,指定当前采集实例的名字,会被放在 event 里一起上报(agent.name)
- 不设的话默认值是当前服务器的 hostname
- 默认放在 fields 字段对应的对象里可以通过开启 fields_under_root 把这些数据放在顶层
配置文件
- 默认位于 modules.d/*.yml通过配置进行指定
metricbeat.config.modules:
path: ${path.config}/modules.d/*.yml
热加载
- reload.enabled 开启热加载reload.period 轮询时间间隔,尽量不要设置小于 1s,因为数据加载可能就需要 1s 了
metricbeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: true
reload.period: 10s
output 输出
- 主要需要关注的:
- Elasticsearch Service(doc)Elasticsearch(doc)Logstash(doc)Kafka(doc)File(doc)Console(doc)
SSL(doc)
- 配置开启
output.elasticsearch.hosts: ["https://192.168.1.42:9200"] output.elasticsearch.ssl.certificate_authorities: ["/etc/pki/root/ca.pem"] output.elasticsearch.ssl.certificate: "/etc/pki/client/cert.pem" output.elasticsearch.ssl.key: "/etc/pki/client/cert.key"配置说明
- enabled 是否开启certificate_authorities 认证证书,支持路径数组,也可以直接把证书在里面certificate 认证信息,支持路径,也可以直接贴在里面key 密钥,支持路径,也可以直接贴在里面verification_mode认证模式,默认 full,同时支持 certificate 和 none
ilm (doc)
- 配置
setup.ilm.enabled: auto
setup.ilm.rollover_alias: "metricbeat"
setup.ilm.pattern: "{now/d}-000001"
配置说明
- setup.ilm.enabled 配置开启setup.ilm.rollover_alias 滚动别名setup.ilm.pattern 滚动命名策略setup.ilm.policy_name 策略名称,默认 metricbeat
index template (doc)
- 配置
setup.template.name: "metricbeat" setup.template.pattern: "metricbeat-*"配置说明
- setup.template.enabled 配置开启setup.template.name 名称setup.template.pattern 索引匹配策略setup.template.settings 指定 settings
kibana (doc)
- 配置
setup.kibana.host: "192.0.2.255:5601" setup.kibana.protocol: "http" setup.kibana.path: /kibana setup.kibana.ssl.enabled: true setup.kibana.ssl.certificate_authorities: ["/etc/pki/root/ca.pem"] setup.kibana.ssl.certificate: "/etc/pki/client/cert.pem" setup.kibana.ssl.key: "/etc/pki/client/cert.key配置说明
- setup.kibana.host 地址setup.kibana.username 账号setup.kibana.password 密码setup.kibana.protocol 协议setup.kibana.space.id 对指定 space 生效setup.kibana.ssl.enabled 开启 ssl
processor(doc)
autodiscover(doc)
logging(doc)
- 自定义 index template (doc)自定义索引名称(doc)自定义看板(doc)给 event 添加 geoip 信息(doc)用 ingest 节点处理日期信息(doc)
- ActiveMQ(doc),5.13.0 和 5.15.9 版本经过测试。
- 配置
metricbeat.modules: - module: activemq metricsets: ['broker', 'queue', 'topic'] period: 10s hosts: ['localhost:8161'] path: '/api/jolokia/?ignoreErrors=true&canonicalNaming=false' username: admin # default username password: admin # default password配置说明
- metricsets 传入数组,指定需要监控的组件broker(doc)queue(doc)topic(doc)
- 配置
metricbeat.modules: - module: apache metricsets: ["status"] period: 10s enabled: true # Apache hosts hosts: ["http://127.0.0.1"] # Path to server status. Default server-status #server_status_path: "server-status" # Username of hosts. Empty by default #username: username # Password of hosts. Empty by default #password: password
- 配置
monitoring:
enabled: true
cluster_uuid: PRODUCTION_ES_CLUSTER_UUID
elasticsearch:
hosts: ["https://example.com:9200", "https://example2.com:9200"]
api_key: id:api_key
username: beats_system
password: somepassword
ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
ssl.certificate: "/etc/pki/client/cert.pem"
ssl.key: "/etc/pki/client/cert.key"
配置说明
- enabled 开启监控cluster_uuid 添加集群信息之后这部分数据会被 beats 填在上报的数据包里elasticsearch 集群信息
- api_key 指定 api_key 或者 username + password 用来登陆ssl 指定证书和认证 key 等信息
- 配置
metricbeat.modules: - module: redis metricsets: ["info", "keyspace"] enabled: true period: 10s # Redis hosts hosts: ["127.0.0.1:6379"] password: foo
- 配置说明
- metricsets 传入数组配置监控维度period 延迟开启hosts 目标节点(集群)地址password 登陆密钥
- 配置
metricbeat.modules:
- module: system
metricsets:
- cpu # CPU usage
- load # CPU load averages
- memory # Memory usage
- network # Network IO
- process # Per process metrics
- process_summary # Process summary
- uptime # System Uptime
- socket_summary # Socket summary
#- core # Per CPU core usage
#- diskio # Disk IO
#- filesystem # File system usage for each mountpoint
#- fsstat # File system summary metrics
#- raid # Raid
#- socket # Sockets and connection info (linux only)
#- service # systemd service information
enabled: true
period: 10s
processes: ['.*']
# Configure the metric types that are included by these metricsets.
cpu.metrics: ["percentages","normalized_percentages"] # The other available option is ticks.
core.metrics: ["percentages"] # The other available option is ticks.
- 配置说明
- 系统监控可以开启上面那些模块,通过在 metricsets 中配置数组实现对不同模块可以指定不同维度,通过在 x.metrics 中配置数组实现,可选的有 percentages、normalized_percentages、ticks
- 监控上报(同 beats 模块)
接口创建有点烦可以参考(doc),还是在 kibana 上点比较舒服
初始化账号系统权限最少需要包括这些:
| 种类 | 权限组 | 用途 |
|---|---|---|
| Cluster | monitor | 接受集群信息 |
| Cluster | manage_ilm | 管理 ilm |
| Index | metricbeat-* 的 manage | 通过 ilm 做别名 |
| Index | metricbeat-* 的 write | 索引的增删改 |
如果用的不是默认的索引名字(metricbeat-*)要指定为自定义的名字
管理员账号权限要包含这些:
| Role | 用途 |
|---|---|
| kibana_admin | 管理 kibana 里的各种页面 |
| ingest_admin | 管理索引模板和pipeline |
| beats_admin | beats 相关的配置权限 |
自身监控可以用 beats_system 的账号,否则需要特别创建包括以下权限:
| 种类 | 权限组 | 用途 |
|---|---|---|
| Cluster | monitor | 接受集群信息 |
| Index | .monitoring-beats-* 的 create_index | 创建监控索引 |
| Index | .monitoring-beats-* 的 create_doc | 往监控索引写数据 |
如果用 metricbeat 的话可以用 remote_monitoring_user 账号,否则需要特别创建包括以下权限:
| Role | 用途 |
|---|---|
| kibana_admin | 管理 kibana 里的各种页面 |
| monitoring_user | 管理 kibana 里的监控功能 |
| remote_monitoring_collector | 从Filebeat上采集信息 |
| remote_monitoring_agent | 把监控数据发给监控集群 |
或者给需要看监控数据的账户赋予 monitoring_user 的权限
其他安全配置看文档(doc)
与 ES 交互的安全性见Elasticsearch模块
与 Logstash 交互的安全性- 配置
output.logstash: hosts: ["logs.mycompany.com:5044"] ssl.certificate_authorities: ["/etc/ca.crt"] ssl.certificate: "/etc/client.crt" ssl.key: "/etc/client.key"配置说明
- hosts 目标节点地址ssl 认证相关配置



