使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

有效監(jiān)控 redis 數(shù)據(jù)庫對于保持最佳性能、識別潛在瓶頸和確保整體系統(tǒng)可靠性至關(guān)重要。 Redis Exporter Service 是一個強大的實用程序,旨在使用 prometheus 監(jiān)控 Redis 數(shù)據(jù)庫。 本教程將指導(dǎo)您完成 Redis Exporter Service 的完整設(shè)置和配置,確保您無縫建立監(jiān)控解決方案。通過學(xué)習(xí)本教程,您將實現(xiàn)完全可操作的監(jiān)控設(shè)置

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

方法一:手動配置

我們繼續(xù)本節(jié)的手動配置方法。

創(chuàng)建Prometheus系統(tǒng)用戶和組

創(chuàng)建一個名為的系統(tǒng)用戶和組“prometheus”來管理導(dǎo)出器

sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus

下載并安裝 Redis Exporter

下載從 gitHub 提取最新版本的 Redis Exporter 下載的文件,并將二進制文件移動到 /usr/local/bin/ 目錄。

curl -s https://api.github.com/repos/oliver006/redis_exporter/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
tar xvf redis_exporter-*.linux-amd64.tar.gz
sudo mv redis_exporter-*.linux-amd64/redis_exporter /usr/local/bin/

驗證 Redis 導(dǎo)出器安裝

redis_exporter --version

這是示例輸出:

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

為 Redis Exporter 配置 systemd 服務(wù)

創(chuàng)建 systemd 服務(wù)單元文件來管理 Redis Exporter

sudo vim /etc/systemd/system/redis_exporter.service

將以下內(nèi)容添加到file:

redis_exporter.service
[Unit]Description=Prometheus Redis ExporterDocumentation=https://github.com/oliver006/redis_exporterWants=network-online.targetAfter=network-online.target[Service]Type=simpleUser=prometheusGroup=prometheusExecReload=/bin/kill -HUP $MaiNPIDExecStart=/usr/local/bin/redis_exporter    --log-format=txt    --namespace=redis    --web.listen-address=:9121    --web.telemetry-path=/metricssyslogIdentifier=redis_exporterRestart=always[Install]WantedBy=multi-user.target

重新加載 systemd 并啟動 Redis Exporter服務(wù)

sudo systemctl daemon-reload
sudo systemctl enable redis_exporter
sudo systemctl start redis_exporter

配置 Prometheus Droplet(手動方法)

讓我們手動配置 Prometheous Droplet。

備份 prometheus.yml 文件

cp /etc/prometheus/prometheus.yml /etc/prometheus/prometheus.yml-$(date  '%d%b%Y-%H:%M')

添加 Redis Exporter 端點scraped

登錄到您的 Prometheus 服務(wù)器并添加要抓取的 Redis Exporter 端點。

將 IP 地址和端口替換為您的 Redis Exporter 端點(9121 是 Redis Exporter 的默認端口)服務(wù))。

vi /etc/prometheus/prometheus.yml
prometheus.yml
scrape_configs:   - job_name: server1_db     static_configs:       - targets: ['10.10.1.10:9121']         labels:           alias: db1    - job_name: server2_db     static_configs:       - targets: ['10.10.1.11:9121']         labels:

手動配置到此結(jié)束。現(xiàn)在,讓我們繼續(xù)基于腳本的配置。

方法 2:使用腳本進行配置

您還可以通過運行兩個腳本來實現(xiàn)此目的 – 一個用于目標(biāo) Droplet,另一個用于 Prometheus Droplet。

讓我們從配置目標(biāo) Droplet 開始。

通過 ssh 連接到目標(biāo)Droplet。

使用以下命令下載目標(biāo)配置腳本:

wget https://solutions-files.ams3.digitaloceanspaces.com/Redis-Monitoring/DO_Redis_Target_Config.sh

下載腳本后,確保它具有可執(zhí)行權(quán)限運行:

chmod  x DO_Redis_Target_Config.sh

通過運行以下命令執(zhí)行腳本:

./DO_Redis_Target_Config.sh

配置

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

注意:如果redis_exporter.service文件已經(jīng)存在,腳本將不會運行。

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

配置 Prometheus Droplet(腳本方法)

SSH 到 Prometheus Droplet 并使用以下命令下載腳本:

wget https://solutions-files.ams3.digitaloceanspaces.com/Redis-Monitoring/DO_Redis_Prometheus_Config.sh

下載腳本后,請確保它具有可執(zhí)行權(quán)限運行:

chmod  x DO_Redis_Prometheus_Config.sh

執(zhí)行腳本running:

./DO_Redis_Prometheus_Config.sh

輸入要添加到監(jiān)控的 Droplet 數(shù)量。

輸入主機名和IP地址。

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

配置完成。

添加后,通過訪問 URL prometheushostname:9090/targets 檢查目標(biāo)是否更新。

注意:如果您輸入的 IP 地址已添加到 監(jiān)控時,您將被要求再次輸入詳細信息。另外,如果 您沒有更多服務(wù)器可以添加,可以輸入 0 退出 script

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

配置 grafana

通過瀏覽器訪問 Grafana-IP:3000 登錄 Grafana 儀表板。

Go到配置 > 數(shù)據(jù)來源。

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

單擊“添加數(shù)據(jù)源”。

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

搜索并選擇 Prometheus。

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

輸入名稱 Prometheus 和 URL (Prometheus主機名:9090)并單擊“保存并測試”。如果看到“數(shù)據(jù)源正在運行”,則說明您已成功添加數(shù)據(jù)源。完成后,轉(zhuǎn)到創(chuàng)建 > 導(dǎo)入。

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

您可以手動配置儀表板或通過以下方式導(dǎo)入儀表板 上傳 json 文件。用于 Redis 監(jiān)控的 JSON 模板可以是 在以下鏈接中找到:

https://solutions-files.ams3.digitaloceanspaces.com/Redis-Monitoring/DO_Grafana-Redis_Monitoring.json

填寫字段并導(dǎo)入。

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

Grafana 儀表板是 準(zhǔn)備好。選擇主機并檢查是否 指標(biāo)是可見的。請隨意修改和編輯儀表板 根據(jù)需要。

使用 Redis Exporter 服務(wù)監(jiān)控 Redis Droplet

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點贊12 分享