Prometheus 监控 Redis 集群的正确姿势
Prometheus 监控Redis的正确姿势(redis集群)
Prometheus
监控 Redis cluster
,其实套路都是一样的,使用 exporter
。
exporter
负责采集指标,通过 http
暴露给 Prometheus
拉取。granafa
则通过这些指标绘图展示数据。Prometheus
收集的数据还会根据你设置的告警规则判断是否要发送给 Alertmanager
, Alertmanager
则要判断是否要发出告警。
Alertmanager
告警分为三个阶段
- Inactive 触发告警的规则会被发送到这来。
- Pending 你设置的等待时间,即规则里面的 for
- Firing 发送告警到邮件、钉钉之类的
扯远了,开始监控 Redis cluster
redis_exporter 监控 Redis cluster
监控什么应用,使用的相应的 exporter
,可以在官网查到。EXPORTERS AND INTEGRATIONS
Redis
使用 redis_exporter
,链接:redis_exporter
支持 Redis 2.x - 5.x
安装及参数
wget https://github.com/oliver006/redis_exporter/releases/download/v1.3.5/redis_exporter-v1.3.5.linux-amd64.tar.gz
tar zxvf redis_exporter-v1.3.5.linux-amd64.tar.gz
cd redis_exporter-v1.3.5.linux-amd64/
./redis_exporter <flags>
redis_exporter
支持的参数很多,对我们有用的就几个。
./redis_exporter --help
Usage of ./redis_exporter:
-redis.addr string
Address of the Redis instance to scrape (default "redis://localhost:6379")
-redis.password string
Password of the Redis instance to scrape
-web.listen-address string
Address to listen on for web interface and telemetry. (default ":9121")
单实例 redis 监控
nohup ./redis_exporter -redis.addr 172.18.11.138:6379 -redis.password xxxxx &
Prometheus
添加单实例
- job_name: redis_since
static_configs:
- targets: ['172.18.11.138:9121']
Redis 集群监控方案
这个挺费劲的,网上查了很多资料,大都是监控单实例的,就这个是集群的,偏偏他的集群是没密码的。
prometheus监控redis集群
我试过的方案:
以下两种都会提示认证失败
level=error msg="Redis INFO err: NOAUTH Authentication required."
方法一
nohup ./redis_exporter -redis.addr 172.18.11.139:7000 172.18.11.139:7001 172.18.11.140:7002 172.18.11.140:7003 172.18.11.141:7004 172.18.11.141:7005 -redis.password xxxxx &
方法二
nohup ./redis_exporter -redis.addr redis://h:Lcsmy.312==/@172.18.11.139:7000 redis://h:Lcsmy.312==/@172.18.11.139:7001 redis://h:Lcsmy.312==/@172.18.11.140:7002 redis://h:Lcsmy.312==/@172.18.11.140:7003 redis://h:Lcsmy.312==/@172.18.11.141:7004 redis://h:Lcsmy.312==/@172.18.11.141:7005 -redis.password xxxxx &
本来想采取最low 的方法,一个实例启一个 redis_exporter
。这样子的话,集群那里很多语句都用不了,比如 cluster_slot_fail
。放弃该方法
nohup ./redis_exporter -redis.addr 172.18.11.139:7000 -redis.password xxxxxx -web.listen-address 172.18.11.139:9121 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.139:7001 -redis.password xxxxxx -web.listen-address 172.18.11.139:9122 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.140:7002 -redis.password xxxxxx -web.listen-address 172.18.11.139:9123 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.140:7003 -redis.password xxxxxx -web.listen-address 172.18.11.139:9124 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.141:7004 -redis.password xxxxxx -web.listen-address 172.18.11.139:9125 > /dev/null 2>&1 &
nohup ./redis_exporter -redis.addr 172.18.11.141:7005 -redis.password xxxxxx -web.listen-address 172.18.11.139:9126 > /dev/null 2>&1 &
最后只好去 github
提 issue
。用我的中国式英语和作者交流,终于明白了。。。其实官方文档已经写了。
scrape_configs:
## config for the multiple Redis targets that the exporter will scrape
- job_name: 'redis_exporter_targets'
static_configs:
- targets:
- redis://first-redis-host:6379
- redis://second-redis-host:6379
- redis://second-redis-host:6380
- redis://second-redis-host:6381
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: <<REDIS-EXPORTER-HOSTNAME>>:9121
## config for scraping the exporter itself
- job_name: 'redis_exporter'
static_configs:
- targets:
- <<REDIS-EXPORTER-HOSTNAME>>:9121
Redis 集群实际操作
启动 redis_exporter
nohup ./redis_exporter -redis.password xxxxx &
重点
在 prometheus
里面如何配置:
- job_name: 'redis_exporter_targets'
static_configs:
- targets:
- redis://172.18.11.139:7000
- redis://172.18.11.139:7001
- redis://172.18.11.140:7002
- redis://172.18.11.140:7003
- redis://172.18.11.141:7004
- redis://172.18.11.141:7005
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 172.18.11.139:9121
## config for scraping the exporter itself
- job_name: 'redis_exporter'
static_configs:
- targets:
- 172.18.11.139:9121
这样子就能采集到集群的数据了。但是日志里提示
time="2019-12-17T09:10:49+08:00" level=error msg="Couldn't connect to redis instance"
午休的时候突然想明白了,只要能连接到一个集群的一个节点,自然就能查询其他节点的指标了。于是启动命令改为:
nohup ./redis_exporter -redis.addr 172.18.11.141:7005 -redis.password xxxxx &
Prometheus
配置不变
送上几张图片:
告警规则
groups:
- name: Redis
rules:
- alert: RedisDown
expr: redis_up == 0
for: 5m
labels:
severity: error
annotations:
summary: "Redis down (instance {{ $labels.instance }})"
description: "Redis 挂了啊,mmp\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"
- alert: MissingBackup
expr: time() - redis_rdb_last_save_timestamp_seconds > 60 * 60 * 24
for: 5m
labels:
severity: error
annotations:
summary: "Missing backup (instance {{ $labels.instance }})"
description: "Redis has not been backuped for 24 hours\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"
- alert: OutOfMemory
expr: redis_memory_used_bytes / redis_total_system_memory_bytes * 100 > 90
for: 5m
labels:
severity: warning
annotations:
summary: "Out of memory (instance {{ $labels.instance }})"
description: "Redis is running out of memory (> 90%)\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"
- alert: ReplicationBroken
expr: delta(redis_connected_slaves[1m]) < 0
for: 5m
labels:
severity: error
annotations:
summary: "Replication broken (instance {{ $labels.instance }})"
description: "Redis instance lost a slave\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"
- alert: TooManyConnections
expr: redis_connected_clients > 1000
for: 5m
labels:
severity: warning
annotations:
summary: "Too many connections (instance {{ $labels.instance }})"
description: "Redis instance has too many connections\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"
- alert: NotEnoughConnections
expr: redis_connected_clients < 5
for: 5m
labels:
severity: warning
annotations:
summary: "Not enough connections (instance {{ $labels.instance }})"
description: "Redis instance should have more connections (> 5)\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"
- alert: RejectedConnections
expr: increase(redis_rejected_connections_total[1m]) > 0
for: 5m
labels:
severity: error
annotations:
summary: "Rejected connections (instance {{ $labels.instance }})"
description: "Some connections to Redis has been rejected\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"
Prometheus 监控 Redis 集群的正确姿势的更多相关文章
- Kubernetes集群部署史上最详细(二)Prometheus监控Kubernetes集群
使用Prometheus监控Kubernetes集群 监控方面Grafana采用YUM安装通过服务形式运行,部署在Master上,而Prometheus则通过POD运行,Grafana通过使用Prom ...
- 基于prometheus监控k8s集群
本文建立在你已经会安装prometheus服务的基础之上,如果你还不会安装,请参考:prometheus多维度监控容器 如果你还没有安装库k8s集群,情参考: 从零开始搭建基于calico的kuben ...
- Prometheus 监控K8S集群资源监控
Prometheus 监控K8S集群中Pod 目前cAdvisor集成到了kubelet组件内,可以在kubernetes集群中每个启动了kubelet的节点使用cAdvisor提供的metrics接 ...
- 监控Redis集群,有两种方法
前提条件 redis集群:已搭建三主三从(三台主机) prometheus.grafana已安装 三台主机ip: 192.168.0.39,192.168.0.164,192.168.0.68 第一种 ...
- 监控Redis集群--废弃,使用新教程
prometheus监控redis需要用到redis_exporter. redis_exporter 项目地址:https://github.com/oliver006/redis_exporter ...
- Kubernetes之利用prometheus监控K8S集群
prometheus它是一个主动拉取的数据库,在K8S中应该展示图形的grafana数据实例化要保存下来,使用分布式文件系统加动态PV,但是在本测试环境中使用本地磁盘,安装采集数据的agent使用Da ...
- Prometheus监控elasticsearch集群(以elasticsearch-6.4.2版本为例)
部署elasticsearch集群,配置文件可"浓缩"为以下: cluster.name: es_cluster node.name: node1 path.data: /app/ ...
- 部署prometheus监控kubernetes集群并存储到ceph
简介 Prometheus 最初是 SoundCloud 构建的开源系统监控和报警工具,是一个独立的开源项目,于2016年加入了 CNCF 基金会,作为继 Kubernetes 之后的第二个托管项目. ...
- 如何用prometheus监控k8s集群中业务pod的metrics
一般,我们从网上看到的帖子和资料, 都是用prometheus监控k8s的各项资源, 如api server, namespace, pod, node等. 那如果是自己的业务pod上的自定义metr ...
随机推荐
- webdriervAPI(CSS定位元素)
from selenium import webdriver driver = webdriver.Chorme() driver.get("http://www.baidu.co ...
- 【文章存档】Local Git 如何部署分支
又来存档文章了,链接 https://docs.azure.cn/zh-cn/articles/azure-operations-guide/app-service-web/aog-app-servi ...
- text matching(文本匹配) 相关资料总结
最近工作上需要做句子语义去重相关的工作,本质上这是属于NLP中text matching(文本匹配)相关的内容.因此我花了一些时间整理了一些关于这个方向的资料,整理如下(也许会持续更新): BiMPM ...
- Want To Become A Web Design Expert? Read This Piece
Want To Become A Web Design Expert? Read This Piece It can be very expensive to hire a web design fi ...
- java 面试题汇总
一.Java 基础 1.JDK 和 JRE 有什么区别? JDK是java开发工具包,提供java的开发环境和运行环境.包括编译器.开发工具和更多的类库等.JDK包含了JRE. JRE是java运行环 ...
- 《MIT 6.828 Homework 1: boot xv6》解题报告
本作业的网站链接:MIT 6.828 Homework 1: boot xv6 问题 Exercise: What is on the stack? While stopped at the abov ...
- Vue ---- Vuex 的第一次接触
在 Vue.js 的项目中,如果项目结构简单, 父子组件之间的数据传递可以使用 props 或者 $emit 等方式 http://www.cnblogs.com/wisewrong/p/62660 ...
- ubuntu18下Docker运行springboot项目
1.springboot项目打成jar包 mvn install 2.编写Dockerfile # 基础镜像使用java FROM java:8 # 作者 #MAINTAINER sk # VOLUM ...
- 【计算机网络】-传输层-Internet传输协议-UDP
[计算机网络]-传输层-UDP 简介 Internet协议集支持一个无连接的传输协议,该协议称为用户数据报协议(UDP,UserDatagram Protocol) .UDP为应用程序提供了一-种无需 ...
- JavaScript之二分法
二分法: 二分查找,又称为折半查找. 注意:二分法查找的数组必须是有序的. /* 获取元素88在数组中第一次出现的索引位置 如果数组元素中存在88,则直接返回88在数组中的索引位置即可. 如果 ...