prometheus / prometheus/client_python
Multiproc doesn't capture all metrics
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 4.4k
- フォーク
- 876
- 平均マージ
- 8日 4時間
- マージ済み PR(30日)
- 1
説明
Hey folks,
I have a similar setup to what is described here. The only difference is that I have nginx in front talking to gunicorn over sockets, but I don't think that matters as far as I can tell.
I wasn't able to use this code:
# Using multiprocess collector for registry
def make_metrics_app():
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
return make_asgi_app(registry=registry)
metrics_app = make_metrics_app()
app.mount("/metrics", metrics_app)
It results in a page that gets a 307, so I implemented this:
@router.get("/metrics", response_class=PlainTextResponse, include_in_schema=False)
async def get_metrics() -> str:
"""
Get prometheus metrics
"""
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
res = Response(content=data)
res.headers["Content-Type"] = CONTENT_TYPE_LATEST
res.headers["Content-Length"] = str(len(data))
return res
Apart from that my setup is pretty typical, I have some counters and a histogram:
AUTOMATIONS_TOTAL: Final = Gauge(
name=prefix_("automations_total"),
documentation="Number of automations run",
labelnames=["platform", "action", "kind", "status"],
multiprocess_mode="sum",
)
REQUEST_TIME_SECONDS: Final = Histogram(
name=prefix_("request_time_seconds"),
documentation="Time spent processing request",
labelnames=["method", "url_rule", "status_code"],
)
REQUESTS_IN_PROGRESS_TOTAL: Final = Gauge(
name=prefix_("requests_in_progress_total"),
documentation="Number of concurrent requests",
# See Metrics Tuning (Gauge)
# https://github.com/prometheus/client_python#multiprocess-mode-gunicorn
multiprocess_mode="sum",
)
My in progress counter always remains at zero, but I'm hoping that's because requests finish faster than I can see them. The histogram, however, never shows up - I see no record of it in my PROMETHEUS_MULTIPROC_DIR and it's never rendered in the output. Any ideas for what I could troubleshoot?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue に示されている FastAPI のマルチプロセス collector のパスとカスタム /metrics ハンドラーを再現します。counter、gauge、histogram の挙動を比較しながら、CollectorRegistry、MultiProcessCollector、および PROMETHEUS_MULTIPROC_DIR の出力を調査します。完了の条件は、histogram が存在しない理由を特定し、期待されるメトリクスがレンダリングされることを確認することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- fastapi, nginx, prometheus, python
- 領域
- observability
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100