- 自动挂载
/metrics
路径,提供 Prometheus 监控数据 - 为其他插件提供统一的数据上报接口
- Bot 在线状态
- Bot 掉线次数
- Bot 发送和接受消息次数
- Matcher 执行次数
- 使用 nb-cli
nb plugin install nonebot-plugin-prometheus
- 使用 uv
uv add nonebot-plugin-prometheus
- 使用 poetry
poetry add nonebot-plugin-prometheus
- 使用 pip
pip install nonebot-plugin-prometheus
先在插件代码最前面声明依赖
from nonebot import require
require("nonebot_plugin_prometheus")
然后可以从插件导入相关指标对象使用,详情请参考 Prometheus Python Client 官方文档
from nonebot_plugin_prometheus import Gauge, Counter, Histogram, Summary
# Request counter
request_counter = Counter(
"request_counter", "The number of requests"
)
request_counter.inc()
Tips
为了统计 matcher 运行时间,本插件会自动在
Matcher.state
中插入_prometheus_start_time
字段。
# 是否开启 Prometheus 插件
prometheus_enable = True
# Prometheus 挂载地址
prometheus_metrics_path = "/metrics"
Note
使用插件需要支持 ASGI 的驱动器,例如
fastapi
- 提供快速上手 docker compose 文件
- 支持通过对话查询指标数据