Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 151ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
m

metrics

Recently created Least recently created Recently updated Least recently updated

timmy / Flask + Prometheus 快速監控

Last active 5 hours ago flask metrics monitoring prometheus python webapp

使用 Flask 和 Prometheus 客戶端,快速設置基本的應用監控,輕鬆追蹤請求數量和延遲。

0 0 0 1
1 from flask import Flask, Response
2 from prometheus_client import Counter, Summary, generate_latest, CONTENT_TYPE_LATEST
3 import time
4
5 app = Flask(__name__)
6
7 # 自訂 metrics
8 REQUEST_COUNT = Counter('app_requests_total', 'Total number of requests')
9 REQUEST_LATENCY = Summary('app_request_latency_seconds', 'Request latency')