
經(jīng)常有朋友問 Neo4j 部署完成后,怎么來實(shí)時(shí)監(jiān)控服務(wù)運(yùn)行狀態(tài)呢?本文將簡單介紹 Prometheus 的部署及使用,為朋友們解惑。
Prometheus【普羅米修斯】,是一項(xiàng) SoundCloud 開源的監(jiān)控和報(bào)警解決方案,能夠?qū)崿F(xiàn)與當(dāng)下最流行的 Kubernetes 無縫連接,使得 Prometheus 逐漸成為主流監(jiān)控方案。

從 Neo4j Enterprise 3.4 版本,可以使用開源工具 Prometheus 來對(duì) Neo4j 運(yùn)行狀況進(jìn)行監(jiān)控。本文詳細(xì)介紹了 Prometheus 的基本實(shí)現(xiàn),以演示 Prometheus v2.17.1 和 Neo4j 之間的連接。
我的環(huán)境是:Mac Catalina 10.15.3,Neo4j Enterprise 3.5.14。
1、下載 prometheus-2.17.1.linux-amd64.tar.gz (57.4M):

2、修改neo4j.conf文件,配置以下參數(shù),并啟動(dòng) 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
啟動(dòng) Neo4j 后,可看到如下圖所示的輸出信息:

3、解壓 prometheus-2.17.1.linux-amd64.tar.gz
修改 prometheus 的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']
注意:上面的配置是假設(shè) Prometheus 與 Neo4j 部署在同一服務(wù)器上, 如果部署在不同的服務(wù)器,只需將 prometheus.yml 文件中對(duì) “l(fā)ocalhost” 的配置替換為 Neo4j 實(shí)例的 IP 地址。
4、啟動(dòng) prometheus:
prometheus --config.file=prometheus.yml

5、 http://<Prometheus Server IP>:9090 啟動(dòng) Prometheus 瀏覽器:
打開 localhost:9090 就可以看到 prometheus 的監(jiān)控頁面。

單擊菜單Status→ Targets, 如下圖所示:

點(diǎn)擊菜單Graph,可以選擇一個(gè)圖表來監(jiān)控 Neo4j 運(yùn)行狀態(tài)。例如,在下圖中,該圖表示已啟動(dòng)的事務(wù)數(shù)(neo4j_transaction_started):

更多監(jiān)控資料,請(qǐng)查看 Neo4j 官網(wǎng)文檔。
轉(zhuǎn)載請(qǐng)注明出處,謝謝。