知识库

如何使用 Prometheus 监控 Neo4j

从 Neo4j Enterprise 3.4 版本开始,您现在可以使用开源监控工具 Prometheus 来监控 Neo4j。以下文章详细介绍了一个基本的 Prometheus 实现,以演示 Prometheus v2.2.1 与 Neo4j 之间的连接。

安装 Prometheus 后,需要通过 Neo4j 的 neo4j.conf 文件配置以下参数

# Enable the Prometheus endpoint. Default is 'false'.
metrics.prometheus.enabled=true
# The IP and port the endpoint will bind to in the format <hostname or IP address>:<port number>.
# The default is localhost:2004.
metrics.prometheus.endpoint=localhost:2004

并且 prometheus.yml 文件应配置如下

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'Neo4j-prometheus'

    # metrics_path: /metrics
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['localhost:2004']

在上述配置片段中,Prometheus 与 Neo4j 安装在同一台服务器上。如果您选择将其安装在不同的服务器上,只需将上述对 localhost 的引用替换为 Neo4j 实例的 IP 地址即可。

http://<Prometheus 服务器 IP>:9090 启动 Prometheus 浏览器并点击菜单选项 StatusTargets 应显示

image

回到第三个菜单选项 Graphs,您可以定义一个图表来监控 Neo4j 指标。例如,在下面的详情中,图表显示的是已启动的事务数量 (neo4j_transaction_started)

image

© . All rights reserved.