Prometheus py监控Redis

py编写exporter

python编写Prometheus exporter获取redis数据

第三方`redis_exporter 无法获取实例的maxmemory

<code> 
 
 
 
 
 
 
​
​

from

 prometheus_client

import

 start_http_server

from

prometheus_client

import

Gauge

import

redis ​ FilePath =open (

"/root/pyredis/redisList.txt"

,

"r"

) ​

""" ​ 链接地址 端口 告警百分比 实例使用说明 联系人信息 118.190.217.164 6379 80 我的REDIS实例002 contact_user:JackFeng,A2Data||185123456,138123456 127.0.0.1 6379 80 我的REDIS实例002 contact_user:DataScience,Fen||185123456,138123456 """

​ ​ ​ g =Gauge(

'redis_maxMemory'

,

'maxMemory of redis instance'

, [

'addr'

,

'alias'

]) ​ ​

if

__name__ ==

"__main__"

:    

"""   启动服务 到 metrics   """

   start_http_server(

8666

)    

"""   生成请求   """

   

while

True

:        

for

line

in

FilePath:            RdHost,RdPort,RdWarn,RdName,RdContact = line.split()                                    print(RdHost,RdPort)            r=redis.Redis(host=RdHost, port=RdPort, db=

0

, password=

'123456'

)            maxMemory=r.config_get(

"maxMemory"

)                        g.labels(addr=

"%s:%s"

% (RdHost,RdPort),alias=

u"%s"

% RdName.decode(

'utf-8'

)).set(float(maxMemory[

'maxMemory'

])) ​ ​/<code>

Prometheus配置

<code>

-

job_name:

'PyRedis'

   

static_configs:

 

-

targets:

['118.190.217.164:8666']

/<code>

1、启动

Prometheus py监控Redis

2、查看Prometheus

可以发现 任务已经在 targets了

Prometheus py监控Redis

搜索你的这个id 就可以 ,通过Grafana模板看到相关信息

Prometheus py监控Redis

3、配置Grafana

Prometheus py监控Redis

如下图配置

Prometheus py监控Redis


4、导入自定义dashboard

Prometheus py监控Redis

Prometheus py监控Redis

监控的redis模板

请加小编获取 小编整理一些常用的。 dashboard

更多精彩,之后探索踩坑会做记录。


分享到:


相關文章: