mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
✨ 添加 request_histogram 和 render_histogram
This commit is contained in:
parent
4c29cf10e4
commit
96573ec86e
@ -1,6 +1,8 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from starlette.responses import Response
|
from starlette.responses import Response
|
||||||
from prometheus_client import CONTENT_TYPE_LATEST, Counter, generate_latest
|
from prometheus_client import CONTENT_TYPE_LATEST, Gauge, Counter, Histogram, generate_latest
|
||||||
|
|
||||||
# Request counter
|
# Request counter
|
||||||
request_counter = Counter(
|
request_counter = Counter(
|
||||||
@ -14,6 +16,24 @@ cookie_choose_counter = Counter(
|
|||||||
"bison_cookie_choose_counter", "The number of cookie choose", ["site_name", "target", "cookie_id"]
|
"bison_cookie_choose_counter", "The number of cookie choose", ["site_name", "target", "cookie_id"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
request_histogram = Histogram(
|
||||||
|
"bison_request_histogram",
|
||||||
|
"The time of platform used to request the source",
|
||||||
|
["site_name", "platform_name"],
|
||||||
|
buckets=[0.1, 0.5, 1, 2, 5, 10, 30, 60],
|
||||||
|
)
|
||||||
|
|
||||||
|
render_histogram = Histogram(
|
||||||
|
"bison_render_histogram",
|
||||||
|
"The time of theme used to render",
|
||||||
|
["site_name", "platform_name"],
|
||||||
|
buckets=[0.1, 0.5, 1, 2, 5, 10, 30, 60],
|
||||||
|
)
|
||||||
|
|
||||||
|
start_time = Gauge("bison_start_time", "The start time of the program")
|
||||||
|
start_time.set(time.time())
|
||||||
|
|
||||||
|
|
||||||
metrics_router = APIRouter(prefix="/api/metrics", tags=["metrics"])
|
metrics_router = APIRouter(prefix="/api/metrics", tags=["metrics"])
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from nonebot_plugin_apscheduler import scheduler
|
|||||||
from nonebot_plugin_saa.utils.exceptions import NoBotFound
|
from nonebot_plugin_saa.utils.exceptions import NoBotFound
|
||||||
|
|
||||||
from nonebot_bison.utils import ClientManager
|
from nonebot_bison.utils import ClientManager
|
||||||
from nonebot_bison.metrics import sent_counter, request_counter
|
from nonebot_bison.metrics import sent_counter, request_counter, render_histogram, request_histogram
|
||||||
|
|
||||||
from ..config import config
|
from ..config import config
|
||||||
from ..send import send_msgs
|
from ..send import send_msgs
|
||||||
@ -98,6 +98,9 @@ class Scheduler:
|
|||||||
success_flag = False
|
success_flag = False
|
||||||
platform_obj = platform_manager[schedulable.platform_name](context)
|
platform_obj = platform_manager[schedulable.platform_name](context)
|
||||||
try:
|
try:
|
||||||
|
with request_histogram.labels(
|
||||||
|
platform_name=schedulable.platform_name, site_name=platform_obj.site.name
|
||||||
|
).time():
|
||||||
if schedulable.use_batch:
|
if schedulable.use_batch:
|
||||||
batch_targets = self.batch_api_target_cache[schedulable.platform_name][schedulable.target]
|
batch_targets = self.batch_api_target_cache[schedulable.platform_name][schedulable.target]
|
||||||
sub_units = []
|
sub_units = []
|
||||||
@ -131,6 +134,7 @@ class Scheduler:
|
|||||||
sent_counter.labels(
|
sent_counter.labels(
|
||||||
platform_name=schedulable.platform_name, site_name=platform_obj.site.name, target=schedulable.target
|
platform_name=schedulable.platform_name, site_name=platform_obj.site.name, target=schedulable.target
|
||||||
).inc()
|
).inc()
|
||||||
|
with render_histogram.labels(platform_name=schedulable.platform_name, site_name=platform_obj.site.name).time():
|
||||||
for user, send_list in to_send:
|
for user, send_list in to_send:
|
||||||
for send_post in send_list:
|
for send_post in send_list:
|
||||||
logger.info(f"send to {user}: {send_post}")
|
logger.info(f"send to {user}: {send_post}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user