Skip to main content

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

Project description

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失败)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

channel_exporter-1.1.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

channel_exporter-1.1.2-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file channel_exporter-1.1.2.tar.gz.

File metadata

  • Download URL: channel_exporter-1.1.2.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for channel_exporter-1.1.2.tar.gz
Algorithm Hash digest
SHA256 f4d772293e0e83682888e7c621fd1de851e8a9a0697eeff6f63d695bc6b3e840
MD5 559231d78fb046bb5696bd1389838c63
BLAKE2b-256 7cb28e747772074d1f29a0b1e3f4b76f5c4bdd350986dbe756ff4666b2eb2491

See more details on using hashes here.

File details

Details for the file channel_exporter-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for channel_exporter-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 674418b8f7c1d9ca41be12b714bc42a0d5b3a68f5a49fd2e4edb89f131b56c99
MD5 0dd2ad4352fe3da6350e3a9b5dfebbad
BLAKE2b-256 428cc0c26863bc6f83cfb223d6168b1b8d8c32d6574c46e51da35adb0527978d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page