javaWeb学习微服务架构和实践Prometheus

使用prometheus监控redis

2019-06-25  本文已影响18人  baiyongjie

github地址: https://github.com/oliver006/redis_exporter

Redis export 安装和使用

# 下载 redis_exporter
https://github.com/oliver006/redis_exporter/releases

cd /usr/local/src/
wget https://github.com/oliver006/redis_exporter/releases/download/v1.0.1/redis_exporter-v1.0.1.linux-amd64.tar.gz
tar xf redis_exporter-v1.0.1.linux-amd64.tar.gz

cd redis_exporter-v1.0.1.linux-amd64
./redis_exporter  -h

# 常用参数
-redis.addr
-redis.password
-web.listen-address

# 创建redis_exporter工作目录
mkdir /usr/local/redis_exporter
mv redis_exporter  /usr/local/redis_exporter/
cd /usr/local/redis_exporter/

# 编写启动脚本
vim start_redis_exporter.sh 
#!/bin/bash
HOSTIP=192.168.1.73
nohup ./redis_exporter -redis.addr $HOSTIP:7000 -redis.password PASSWORD -web.listen-address $HOSTIP:27000 &
nohup ./redis_exporter -redis.addr $HOSTIP:7001 -redis.password PASSWORD -web.listen-address $HOSTIP:27001 &

# 测试 URL 获取 metrics
curl -s  192.168.1.73:27000/metrics|grep -v "^#"| more 
exporter_scrape_duration_seconds{quantile="0.5"} NaN
exporter_scrape_duration_seconds{quantile="0.9"} NaN

[root@kvm000 redis_exporter]# curl -s  192.168.1.73:27001/metrics|grep -v "^#"| more  
exporter_scrape_duration_seconds{quantile="0.5"} NaN
exporter_scrape_duration_seconds{quantile="0.9"} NaN
exporter_scrape_duration_seconds{quantile="0.99"} NaN

配置prometheus

[root@localhost sd_config]# vim /opt/prometheus/prometheus.yml 
  - job_name: 'redis'
    file_sd_configs:
    - files: ['/opt/prometheus/sd_config/redis.yml']
      refresh_interval: 180s

[root@localhost sd_config]# vim /opt/prometheus/sd_config/redis.yaml 
- targets:
  - 192.168.1.73:27000
  - 192.168.1.73:27001
  labels:
    idc: bj_company
    service: redis

[root@localhost sd_config]# kill -hup `ps -ef |grep prometheus|grep -v grep|awk '{print $2}'`

image

配置grafana

导入模板: 763, 需要简单修改

image
上一篇下一篇

猜你喜欢

热点阅读