# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2024/1/30 9:42
# @Function : Prometheus client
import os
import time
from prometheus_client import start_http_server,Gauge
#定义数据类型,metric,describe(描述),标签
#统计altermanager的告警配置数量
altermanager_cnf_num = Gauge('altermanager_cnf_num','Count the number of alarm',['instance'])
def get_altermanager_cnf_num():
#获取指标
altermanager_cnf_path = "/opt/prometheus/rules"
altermanager_cnf_nums = os.popen(f"ls -l {altermanager_cnf_path} | grep -v 'total' | wc -l").read().strip()
#获取实例名称
hostname = os.popen("hostname").read().strip()
altermanager_cnf_num.labels(instance=hostname).set(altermanager_cnf_nums)
if __name__ == '__main__':
#启动web服务
start_http_server(80)
while True:
#不断执行函数更新数据源
get_altermanager_cnf_num()
#更新间隔
time.sleep(3)
##运维开发如何提交作品? 代码只能写1000行,没有这么少的代码啊
管理系统这些很熟悉,OA、产值、工单、组织架构、合同、行政审
PigeonKVM是一个由Python+Django+Ope
ServerManager 是一款由Python编写的开源服
结合AI、IoT等最新技术,提供软硬一体化的AIoT产品解决
自动化运维平台提供了基于基于saltstack的主机维护、集
图片处理是对象存储的增值产品功能,通过对对象存储图片进行处理
需求方专属客服,免费梳理匹配
添加客服微信,免费为您安排与该工程师直接沟通
长按二维码添加客服微信
如当前档期不合,也可免费为您推荐相似案例作者