python监控程序编写_使用Python编写Prometheus监控的方法

本文介绍了如何使用Python和Flask配合Prometheus进行监控。通过安装Prometheus,创建Counter、Gauge类型的Metrics,以及使用labels区分不同特征,实现了Python服务器端的Prometheus监控。同时,还展示了如何使用asyncio编写监控程序。
摘要由CSDN通过智能技术生成

要使用python编写Prometheus监控,需要你先开启Prometheus集群。可以参考//www.ddpool.cn/article/148895.htm 安装。在python中实现服务器端。在Prometheus中配置请求网址,Prometheus会定期向该网址发起申请获取你想要返回的数据。

使用Python和Flask编写Prometheus监控

Installation

pip install flask

pip install prometheus_client

Metrics

Prometheus提供4种类型Metrics:Counter, Gauge, Summary和Histogram

Counter

Counter可以增长,并且在程序重启的时候会被重设为0,常被用于任务个数,总处理时间,错误个数等只增不减的指标。

import prometheus_client

from prometheus_client import Counter

from prometheus_client.core import CollectorRegistry

from flask import Response, Flask

app = Flask(__name__)

requests_total = Counter("request_count", "Total request cout of the host")

@app.route("/metrics")

def requests_count():

requests_total

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值