监控 Fleet 管理的 APM Server
Elastic Stack
本指南假定您已经将 APM 数据摄取到 Elastic Stack 中。
在 8.0 及更高版本中,您可以使用 Metricbeat 收集有关 APM Server 的数据并将其发送到监控集群。要收集和发送监控数据
在监控 APM 之前,您必须具有 Elasticsearch 生产集群的监控数据。要了解如何操作,请参阅使用 Metricbeat 收集 Elasticsearch 监控数据。或者,在 Kibana 中打开 Stack Monitoring 应用程序,并按照产品内指南进行操作。
通过将以下设置添加到您的
elastic-agent.yml
配置文件来启用 Elastic Agent 的监控agent.monitoring: http: enabled: true host: localhost port: 6791
- 启用监控
- 用于公开日志/指标的主机
- 用于公开日志/指标的端口
注册 Elastic Agent
编辑
elastic-agent.yml
后,您必须重新注册 Elastic Agent 才能使更改生效。要在 Fleet 中注册 Elastic Agent
elastic-agent enroll --url <string> --enrollment-token <string> [--ca-sha256 <string>] [--certificate-authorities <string>] [--daemon-timeout <duration>] [--delay-enroll] [--elastic-agent-cert <string>] [--elastic-agent-cert-key <string>] [--elastic-agent-cert-key-passphrase <string>] [--force] [--header <strings>] [--help] [--insecure ] [--proxy-disabled] [--proxy-header <strings>] [--proxy-url <string>] [--staging <string>] [--tag <string>] [global-flags]
有关 enroll 命令的更多信息,请参阅Elastic Agent 命令参考。
在与 Elastic Agent 相同的服务器上安装 Metricbeat。要了解如何操作,请参阅Metricbeat 入门。如果您已经安装了 Metricbeat,请跳过此步骤。
启用 Metricbeat 中的
beat-xpack
模块。例如,要启用
modules.d
目录中的默认配置,请运行以下命令,使用适用于您操作系统的正确命令语法metricbeat modules enable beat-xpack
在 Metricbeat 中配置
beat-xpack
模块。完成后,您的
modules.d/beat-xpack.yml
文件应如下所示- module: beat xpack.enabled: true period: 10s hosts: ["http://localhost:6791"] basepath: "/processes/apm-server-default" username: remote_monitoring_user password: your_password
请勿更改
module
名称或xpack.enabled
布尔值;这些是堆栈监控所必需的。 我们建议您暂时接受默认的period
。将
hosts
设置为与您的elastic-agent.yml
文件中配置的 host:port 相匹配。 在此示例中,它是http://localhost:6791
。要监控在多个 Elastic Agent 中运行的多个 APM Server 实例,请指定一个主机列表,例如
hosts: ["http://localhost:5066","http://localhost:5067","http://localhost:5068"]
如果您将 Elastic Agent 配置为使用加密通信,则必须通过 HTTPS 访问它。 例如,使用像
https://localhost:5066
这样的hosts
设置。APM Server 指标在
/processes/apm-server-default
中公开。 将此位置添加为basepath
。根据您的环境的需要设置
username
和password
设置。 如果启用了 Elastic 安全功能,则必须提供用户名和密码,以便 Metricbeat 可以成功收集指标
可选:禁用 Metricbeat 中的系统模块。
默认情况下,系统模块已启用。 但是,它收集的信息不会显示在 Kibana 的 Stack Monitoring 页面上。 除非您想将该信息用于其他目的,否则请运行以下命令
metricbeat modules disable system
确定将监控数据发送到哪里。
提示在生产环境中,您应该将您的部署日志和指标发送到专用的监控部署(称为监控集群)。监控会将日志和指标索引到 Elasticsearch 中,并且这些索引会像任何其他索引一样消耗存储、内存和 CPU 周期。通过使用单独的监控部署,您可以避免影响您的其他生产部署,并且即使生产部署不可用,也可以查看日志和指标。
例如,在 Metricbeat 配置文件 (
metricbeat.yml
) 中指定 Elasticsearch 输出信息output.elasticsearch: # Array of hosts to connect to. hosts: ["http://es-mon-1:9200", "http://es-mon2:9200"] # Optional protocol and basic auth credentials. #protocol: "https" #api_key: "id:api_key" #username: "elastic" #password: "changeme"
- 在此示例中,数据存储在具有节点
es-mon-1
和es-mon-2
的监控集群上。 - 指定
api_key
或username
/password
之一。
如果您将监控集群配置为使用加密通信,则必须通过 HTTPS 访问它。 例如,使用像
https://es-mon-1:9200
这样的hosts
设置。重要提示Elasticsearch 监控功能使用 ingest pipelines,因此存储监控数据的集群必须至少有一个 ingest 节点。
如果在监控集群上启用了 Elasticsearch 安全功能,则必须提供有效的用户 ID 和密码,以便 Metricbeat 可以成功发送指标
- 在监控集群上创建一个具有
remote_monitoring_agent
内置角色的用户。或者,如果您的环境中可用,请使用remote_monitoring_user
内置用户。 - 将
username
和password
设置添加到 Metricbeat 配置文件中的 Elasticsearch 输出信息。
有关这些配置选项的更多信息,请参阅配置 Elasticsearch 输出。
- 在此示例中,数据存储在具有节点
启动 Metricbeat 以开始收集 APM 监控数据。