【redis】用prometheus+grafana+redis_exporter監(jiān)控redis

一、背景

用prometheus+grafana+redis_exporter監(jiān)控redis,對redis 1主1從3哨兵 實(shí)例做一些業(yè)務(wù)分析。

prometheus、grafana安裝機(jī)器: 192.168.1.101
redis_exporter 安裝機(jī)器: 192.168.1.102

二、安裝redis_exporter

在redis主從哨兵的maser節(jié)點(diǎn)(192.168.1.102):

wget https://github.com/oliver006/redis_exporter/releases/download/v0.21.2/redis_exporter-v0.21.2.linux-amd64.tar.gz

tar  -zxf  redis_exporter-v0.21.2.linux-amd64.tar.gz

mkdir  /usr/local/redis_exporter

mv  redis_exporter    /usr/local/redis_exporter/


vim  /usr/lib/systemd/system/redis_exporter.service
####################################################
[Unit]
Description=Redis Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/redis_exporter/redis_exporter \
    -web.listen-address ":9121" \
    -redis.addr "redis://192.168.1.102:6381" \
    -redis.password "Redis@123"

[Install]
WantedBy=multi-user.target

####################################################

systemctl  daemon-reload

systemctl  start  redis_exporter
systemctl  enable  redis_exporter
systemctl  status  redis_exporter

ss  -tan  | grep 9121
LISTEN     0      1024      [::]:9121                  [::]:*
ESTAB      0      0       [::ffff:192.168.1.102]:9121                [::ffff:192.168.1.102]:42594



image.png

三、安裝prometheus、grafana

在一臺(tái)空閑新機(jī)器上:

安裝prometheus

wget https://github.com/prometheus/prometheus/releases/download/v2.33.3/prometheus-2.33.3.linux-amd64.tar.gz
mkdir  /var/lib/prometheus
tar -zxf  prometheus-2.33.3.linux-amd64.tar.gz
mv  prometheus-2.33.3.linux-amd64  /usr/local/prometheus

vim   /usr/lib/systemd/system/prometheus.service
##################################################
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/usr/local/prometheus
ExecStart=/usr/local/prometheus/prometheus \
--web.listen-address=0.0.0.0:9090 \
--storage.tsdb.path="/var/lib/prometheus" \
--config.file=prometheus.yml
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target


##################################################

vim /usr/local/prometheus/prometheus.yml
############################################################################
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  - job_name: "redis-server"
    static_configs:
      - targets: ["192.168.1.102:9121"]

###############################################################################


systemctl  start    prometheus
systemctl  enable   prometheus
systemctl  status  prometheus


# ss -tan | grep  -w  9090
LISTEN     0      65535     [::]:9090                  [::]:*

image.png

用瀏覽器訪問:http://192.168.1.101:9090/

image.png
image.png

安裝grafana

yum -y install  https://dl.grafana.com/oss/release/grafana-6.0.2-1.x86_64.rpm

systemctl  start  grafana-server
systemctl  enable  grafana-server
systemctl  status grafana-server
image.png

四、prometheus 和 grafana 集成

用瀏覽區(qū)打開 grafana web:http://192.168.1.101:3000
默認(rèn)用戶名和密碼:admin

添加數(shù)據(jù)源 Prometheus,點(diǎn)擊配置,點(diǎn)擊 Data Sources


image.png
image.png
image.png
image.png
image.png
image.png
image.png

五、導(dǎo)入prometheus-redis_rev1.json模板

https://grafana.com/api/dashboards/763/revisions/1/download

image.png

如果啟動(dòng)多個(gè)redis實(shí)例,那么這個(gè)列表就會(huì)展示出所有的redis實(shí)例
上面也說到用redis_exporter 0.24版本,有redis.file 參數(shù),可以將所有的redis實(shí)例寫到一個(gè)文件中。

image.png
image.png

六、參考

Prometheus監(jiān)控redis
https://www.cnblogs.com/layzer/articles/prometheus_redis.html

Grafana Prometheus系統(tǒng)監(jiān)控Redis服務(wù)
https://blog.csdn.net/wyl9527/article/details/97151685

Prometheus監(jiān)控Redis
https://blog.csdn.net/wc1695040842/article/details/107014209

Prometheus部署+簡單監(jiān)控
https://www.cnblogs.com/layzer/articles/prometheus_install_monitor.html

Prometheus 監(jiān)控Redis的正確姿勢(redis集群)
https://www.cnblogs.com/fsckzy/p/12053604.html

Prometheus 和 Grafana 集成
https://blog.csdn.net/weixin_45417821/article/details/123729143

prometheus.service啟動(dòng)、停止、重啟、自啟動(dòng)
https://blog.csdn.net/qq_32014795/article/details/121852659

How to Setup a Redis Exporter for Prometheus
https://blog.ruanbekker.com/blog/2020/05/05/how-to-setup-a-redis-exporter-for-prometheus

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容