目录
脚本
说明
配置
写在前面
本文适合有python基础、使用过promethues + grafana的人
今天接到个任务,要监控后端的服务状态。
Prometheus有个不好的地方在于,在国内比较小众,模板不如zabbix那么丰富,网上的资料也很少。作为一个不想当咸鱼的运维,这种小(简)型(单)的exporter当然是要自己写啦。
Prometheus是使用pull的方式获取数据,于是自己用flask写了个接口监控后端服务的状态,并展示到grafana上。
安装依赖
yum -y install epel-release &&yum install python-pip -y&& pip install --upgrade pip &&pip install flask &&pip install prometheus_client
监控脚本
#!/bin/python
##coding=utf-8
import requests
import prometheus_client
from prometheus_client.core import CollectorRegistry
from prometheus_client import Gauge
from flask import Response,Flask
###定义函数,返回接口响应码
def StatusCode(url):
try:
url = url
response = requests.post(url)