用于 Python 应用的 Prometheus 指标监控库,支持 Flask、Requests 和消息队列消费 者的监控指标自动收集。
Project description
channel-exporter
用于 Python 应用的 Prometheus 指标监控库,支持 Flask、Requests 和消息队列消费者的监控指标自动收集。
功能特性
- ✅ 内置三大监控维度
- Web 服务内部指标(Flask)
- 合作伙伴 HTTP 调用指标(Requests)
- 消息队列消费指标(Consumer)
- ✅ Prometheus 原生集成
- ✅ 灵活的指标桶配置
- ✅ 自动化的指标收集
- ✅ 合作伙伴接口预配置
安装使用
pip install channel_exporter
环境要求
- Python 2.7+
- 可选依赖(安装即监控):
- Flask (Web 服务监控)
- requests (HTTP 调用监控)
- ctec_consumer (消费者监控)
快速开始(Web 服务指标)
import channel_exporter
from flask import Flask
# 初始化监控配置
channel_exporter.__init__("<your_syscode>")
app = Flask(__name__)
@app.get("/")
def hello():
return "Hello World!"
# 启动后访问 /metrics 获取指标
if __name__ == "__main__":
app.run()
配置说明
初始化参数
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
syscode |
str | 是 | 无 | 10位服务编码,格式:大写字母+9位数字 |
inner_metrics_buckets |
tuple | 否 | 默认桶 | Web 服务耗时分布桶 |
partner_http_metrics_buckets |
tuple | 否 | 默认桶 | HTTP 调用耗时分布桶 |
consumer_metrics_buckets |
tuple | 否 | 默认桶 | 消费者耗时分布桶 |
default_metrics_port |
int | 否 | 9166 | 指标默认暴露端口 |
指标说明
Web 服务指标
指标名称:[syscode]_inner_metrics
标签说明:
appid: 应用ID(syscode前4位)application: 系统编码f_code: 请求方系统编码(取自 headers["User-Agent"])path: 请求路径http_status: HTTP 状态码code: 业务响应码method_code: 接口编号
HTTP 调用指标
指标名称:partner_http_metrics
标签说明:
appid: 应用ID(syscode前4位)application: 系统编码partner: 合作商(域名)编号action_code: 动作(路径)编号http_status: HTTP 状态码code: 业务响应码(由被调用方定义,-1表示未找到业务响应码)
消费者指标
指标名称:[syscode]_consumer_metrics
标签说明:
appid: 应用ID(syscode前4位)application: 完整syscodef_code: 空值topic: 消息主题code: 处理结果(0成功/1失败)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file channel_exporter-1.0.1.tar.gz.
File metadata
- Download URL: channel_exporter-1.0.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9b6f7ea8d833ab684758ac7ea2b0864a3becd75f82bfbfe94dd5ec40b51d497
|
|
| MD5 |
56dd89078abedcc3cf6e8e688f96aa2e
|
|
| BLAKE2b-256 |
de98ab6f5df331187ad0f26d3df810b40d476c291ef8f8ebf8e7a89464ec5f98
|
File details
Details for the file channel_exporter-1.0.1-py3-none-any.whl.
File metadata
- Download URL: channel_exporter-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a22e6641de78b595bf33854a60564267e5d276b3337c33d474147bb62342b84
|
|
| MD5 |
140d193f62a4e47b854bba02a78c4d5a
|
|
| BLAKE2b-256 |
c4cd8b4ad00a5a3f9aa66a9ec1be96931dfa61b6843a56de6a7ccccd87a4b536
|