用Prometheus监控Redis 的时候,发现redis_exporter不能对redis里面的队列(list)长度进行监控,Google了一下,发现官网也没有redis-cli_exporter。
索性就自己用Python写了一个Rediscli_exporter.
#!/usr/bin/env python
#coding:utf-8
#Author: [email protected]
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)
原文地址:http://blog.51cto.com/13766835/2342040
时间: 2024-11-09 09:32:01