温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Prometheus监控 Redis , redis-cli_exporter

发布时间:2020-06-19 13:38:33 来源:网络 阅读:2742 作者:霍帅兵 栏目:编程语言

用Prometheus监控Redis 的时候,发现redis_exporter不能对redis里面的队列(list)长度进行监控,Google了一下,发现官网也没有redis-cli_exporter。
索性就自己用Python写了一个Rediscli_exporter.

#!/usr/bin/env python
#coding:utf-8
#Author: shuaibing.huo@gmail.com
import prometheus_client
import redis
from prometheus_client import Gauge
from flask import Response,Flask

app = Flask(__name__)
queue_len = Gauge("www_site_queue_len","the len of redis_queue")

@app.route("/metrics")
def redis_conn():
    pool = redis.ConnectionPool(host="xxxxxxxx.redis.rds.aliyuncs.com",port=6379,db=0,password="avavavav")
    conn = redis.Redis(connection_pool=pool)
    queue_len_data = conn.llen("www_site")
    queue_len.set(queue_len_data)
    return Response(prometheus_client.generate_latest(queue_len),mimetype="text/plain")

if __name__ == "__main__":
    app.run(host="0.0.0.0",port=9101)
                       **如果有帮到你的话,欢迎微信赞赏**

Prometheus监控 Redis , redis-cli_exporter

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI