知识库

如何使用 Prometheus 监控 Neo4j

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

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

# 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 地址。

在 Prometheus 服务器的 http://<IP of Prometheus Server>:9090 上启动 Prometheus 浏览器,然后单击菜单选项“状态”→“目标”,应该会显示

image

返回到第 3 个菜单选项“图表”,您可以定义一个图表来监控 Neo4j 指标。例如,在下面的详细信息中,图表表示已启动的事务数 (neo4j_transaction_started)

image