溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Prometheus監(jiān)控 Redis , redis-cli_exporter

發(fā)布時間:2020-06-19 13:38:33 來源:網(wǎng)絡 閱讀:2765 作者:霍帥兵 欄目:編程語言

用Prometheus監(jiān)控Redis 的時候,發(fā)現(xiàn)redis_exporter不能對redis里面的隊列(list)長度進行監(jiān)控,Google了一下,發(fā)現(xiàn)官網(wǎng)也沒有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監(jiān)控 Redis , redis-cli_exporter

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI