經常有朋友問 Neo4j 部署完成后,怎么來實時監控服務運行狀態呢?本文將簡單介紹 Prometheus 的部署及使用,為朋友們解惑。
Prometheus【普羅米修斯】,是一項 SoundCloud 開源的監控和報警解決方案,能夠實現與當下最流行的 Kubernetes 無縫連接,使得 Prometheus 逐漸成為主流監控方案。
從 Neo4j Enterprise 3.4 版本,可以使用開源工具 Prometheus 來對 Neo4j 運行狀況進行監控。本文詳細介紹了 Prometheus 的基本實現,以演示 Prometheus v2.17.1 和 Neo4j 之間的連接。
我的環境是:Mac Catalina 10.15.3,Neo4j Enterprise 3.5.14。
1、下載 prometheus-2.17.1.linux-amd64.tar.gz (57.4M):
2、修改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
啟動 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']
注意:上面的配置是假設 Prometheus 與 Neo4j 部署在同一服務器上, 如果部署在不同的服務器,只需將 prometheus.yml 文件中對 “localhost” 的配置替換為 Neo4j 實例的 IP 地址。
4、啟動 prometheus:
prometheus --config.file=prometheus.yml
5、 http://<Prometheus Server IP>:9090 啟動 Prometheus 瀏覽器:
打開 localhost:9090 就可以看到 prometheus 的監控頁面。
單擊菜單Status→ Targets, 如下圖所示:
點擊菜單Graph,可以選擇一個圖表來監控 Neo4j 運行狀態。例如,在下圖中,該圖表示已啟動的事務數(neo4j_transaction_started):
轉載請注明出處,謝謝。