Skip to main content

channel-exporter

Release Python Version License Downloads

用于 Python 应用的 Prometheus 指标监控库,支持 Flask、Requests 和消息队列消费者的监控指标自动收集。

功能特性

  • ✅ 内置三大监控维度
    • Web 服务内部指标(Flask)
    • 合作商 HTTP 调用指标(Requests)
    • 消息队列消费指标(Consumer)
  • ✅ Prometheus 原生集成
  • ✅ 灵活的指标桶配置
  • ✅ 自动化的指标收集
  • ✅ 合作商接口预配置

安装使用

pip install channel_exporter

环境要求

  • Python 2.7+
  • 可选依赖(安装即监控):
    • Flask (Web 服务监控)
    • requests (HTTP 调用监控)
    • ctec_consumer (消费者监控)

快速开始(Web 服务指标)

# coding:utf-8
import channel_exporter
from flask import Flask

app = Flask(__name__)


@app.get("/")
def hello():
    return "Hello World!"


if __name__ == "__main__":
    # 初始化监控配置
    channel_exporter.__init__("<your_syscode>")

    # 启动后访问 /metrics 获取指标
    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: 完整syscode
  • f_code: 空值
  • topic: 消息主题
  • code: 处理结果(0成功/1失败)

Metadata

Release files for channel-exporter 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for channel-exporter 1.2.2
File Size Uploaded Provenance
channel_exporter-1.2.2.tar.gz 10.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for channel-exporter 1.2.2
File Interpreter ABI Platform
channel_exporter-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / channel_exporter-1.2.2.tar.gz

Download URL channel_exporter-1.2.2.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
496b0eb7a0b3bb20049d5c6c658e5cd82f69c410ea17f1b49a74f41df81844a7
BLAKE2b-256 checksum
How to use checksums
c02348729edfe8179123969c01cbeb2ad672b49d0ea3c45194f89a1ff68f950b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / channel_exporter-1.2.2-py3-none-any.whl

Download URL channel_exporter-1.2.2-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
353dbc626a51089f745c701ec34941f381859def2dd16740004c02594d0e52fb
BLAKE2b-256 checksum
How to use checksums
b9fb2f7837b00966cb8ec51d33fc17d78a3d83884c562973f7d609fb0f3e5a0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for channel-exporter 1.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page