公开指标

Neo4j 支持以下公开数据以用于监控目的的方法

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

  • CSV 文件 - 从 CSV 文件中检索指标。默认情况下启用。

  • JMX MBean - 通过 JMX MBean 公开指标。默认情况下启用。

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

  • 普罗米修斯 — 发布指标以作为 普罗米修斯 端点进行轮询。默认情况下禁用。

Neo4j 操作管理器

可以通过 Neo4j 操作管理器 (NOM) 查看 Neo4j 指标数据。有关如何安装和设置 NOM 以与您的 Neo4j DBMS 一起使用,请参阅 Neo4j 操作管理器文档

CSV 文件

将指标导出到 CSV 文件。

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

# 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 MBean

从 Neo4j 4.2.2 开始,JMX 指标默认通过 JMX MBean 公开。

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

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

石墨

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

将以下设置添加到 neo4j.conf 中,以启用与石墨的集成。

# 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 浏览器连接到石墨,以监控您的 Neo4j 指标。

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

普罗米修斯

发布指标以作为 普罗米修斯 端点进行轮询。

将以下设置添加到 neo4j.conf 中,以启用普罗米修斯端点。

# 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 完全启动时,普罗米修斯端点将在配置的地址处可用。

您永远不应该将普罗米修斯端点直接暴露给互联网。如果安全性至关重要,则应设置 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 指标通过普罗米修斯公开时,它们的名称将被转换为符合普罗米修斯命名约定。

将应用以下一般规则。

  • 句点 (.) 将被下划线 (_) 替换,因为普罗米修斯不支持指标名称中的句点。

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

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

有关更多信息,请参阅 普罗米修斯文档