暴露指标

Neo4j 支持通过以下方式公开监控数据:

  • Neo4j Ops Manager — 一种基于 UI 的工具,使 DBA(或任何管理员)能够监控、管理和操作企业环境中的所有 Neo4j DBMS。

  • CSV 文件 — 从 CSV 文件中检索指标。默认启用。

  • JMX MBeans — 通过 JMX MBeans 公开指标。默认启用。

  • Graphite — 将指标发送到 Graphite 或任何基于 Graphite 协议的监控工具。默认禁用。

  • Prometheus — 将指标发布为 Prometheus 端点以供轮询。默认禁用。

Neo4j Ops Manager

Neo4j 指标数据可以通过 Neo4j Ops Manager (NOM) 查看。有关如何安装和设置 NOM 以便与您的 Neo4j DBMS 配合使用的更多信息,请参阅 Neo4j Ops Manager 文档

CSV 文件

将指标导出到 CSV 文件。

要启用将指标导出到本地 .CSV 文件,请将以下设置添加到 neo4j.conf

# Enable the CSV exporter. Default is true.
server.metrics.csv.enabled=true
# Directory path for output files.
# Default is the /metrics directory under NEO4J_HOME.
server.directories.metrics=/local/file/system/path
# How often to store data. Default is 30 seconds.
server.metrics.csv.interval=30s
# The maximum number of CSV files that will be saved. Default is 7.
server.metrics.csv.rotation.keep_number=7
# The file size at which the CSV files will auto-rotate. Default is 10.00MiB.
server.metrics.csv.rotation.size=10.00MiB
# Compresses the metric archive files. Default is NONE. Possible values are NONE, ZIP, and GZ.
server.metrics.csv.rotation.compression=ZIP

server.metrics.csv.rotation.compression 用于选择文件轮转后使用的压缩方案。由于 CSV 文件具有很高的压缩率,建议启用文件压缩以节省磁盘空间。

JMX MBeans

从 Neo4j 4.2.2 版本开始,JMX 指标默认通过 JMX MBeans 公开。

# Enable the JMX MBeans integration. Default is true.
server.metrics.jmx.enabled=true

有关访问和调整指标的更多信息,请参阅 Java 参考指南 → JMX 指标

Graphite

将指标发送到 Graphite 或任何基于 Graphite 协议的监控工具。

将以下设置添加到 neo4j.conf 以启用与 Graphite 的集成

# Enable the Graphite integration. Default is false.
server.metrics.graphite.enabled=true
# The hostname or IP address of the Graphite server.
# A socket address in the format <hostname>, <hostname>:<port>, or :<port>.
# If missing, the port or hostname is acquired from server.default_listen_address.
# The default port number for Graphite is 2003.
server.metrics.graphite.server=localhost:2003
# How often to send data. Default is 30 seconds.
server.metrics.graphite.interval=30s
# Prefix for Neo4j metrics on Graphite server.
server.metrics.prefix=neo4j

启动 Neo4j 并通过 Web 浏览器连接到 Graphite 以监控您的 Neo4j 指标。

如果您将 Graphite 服务器配置为使用主机名或 DNS 条目,则应注意 JVM 会将主机名解析为 IP 地址,并出于安全原因默认无限期缓存结果。这由 JVM 安全属性中的 networkaddress.cache.ttl 值控制。更多信息请参阅 https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html

Prometheus

发布指标作为 Prometheus 端点以供轮询。

将以下设置添加到 neo4j.conf 以启用 Prometheus 端点。

# Enable the Prometheus endpoint. Default is false.
server.metrics.prometheus.enabled=true
# The hostname and port to use as Prometheus endpoint.
# A socket address is in the format <hostname>, <hostname>:<port>, or :<port>.
# If missing, the port or hostname is acquired from server.default_listen_address.
# The default is localhost:2004.
server.metrics.prometheus.endpoint=localhost:2004

当 Neo4j 完全启动后,Prometheus 端点将在配置的地址处可用。

您绝不应将 Prometheus 端点直接暴露在互联网上。如果安全性至关重要,您应该设置 server.metrics.prometheus.endpoint=localhost:2004,并在同一台机器上配置一个反向 HTTP 代理来处理身份验证、SSL、缓存等。

如果您可以在内部网络中发送未加密的指标(例如 server.metrics.prometheus.endpoint=10.0.0.123:2004),则同一网段内的所有服务器都将能够访问它。

如果您指定了更宽松的设置,例如 server.metrics.prometheus.endpoint=0.0.0.0:2004,则应该配置防火墙规则以防止任何未经授权的访问。传输中的数据仍未加密,因此绝不应通过任何不安全的网络进行传输。

当 Neo4j 指标通过 Prometheus 公开时,它们的名称会进行转换以符合 Prometheus 的命名规范。

适用以下通用规则:

  • 点号 (.) 被替换为下划线 (_),因为 Prometheus 不支持在指标名称中使用点号。

  • 根据指标类型,会添加后缀。

原始 Neo4j 指标名称可以在 Prometheus 输出中找到,请参阅以 # HELP 开头的行。

更多信息,请参阅 Prometheus 文档