添加 request_histogram 和 render_histogram

This commit is contained in:
2024-12-12 19:43:44 +08:00
parent 4c29cf10e4
commit 96573ec86e
2 changed files with 49 additions and 25 deletions
+28 -24
View File
@@ -6,7 +6,7 @@ from nonebot_plugin_apscheduler import scheduler
from nonebot_plugin_saa.utils.exceptions import NoBotFound
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 ..send import send_msgs
@@ -98,19 +98,22 @@ class Scheduler:
success_flag = False
platform_obj = platform_manager[schedulable.platform_name](context)
try:
if schedulable.use_batch:
batch_targets = self.batch_api_target_cache[schedulable.platform_name][schedulable.target]
sub_units = []
for batch_target in batch_targets:
userinfo = await config.get_platform_target_subscribers(schedulable.platform_name, batch_target)
sub_units.append(SubUnit(batch_target, userinfo))
to_send = await platform_obj.do_batch_fetch_new_post(sub_units)
else:
send_userinfo_list = await config.get_platform_target_subscribers(
schedulable.platform_name, schedulable.target
)
to_send = await platform_obj.do_fetch_new_post(SubUnit(schedulable.target, send_userinfo_list))
success_flag = True
with request_histogram.labels(
platform_name=schedulable.platform_name, site_name=platform_obj.site.name
).time():
if schedulable.use_batch:
batch_targets = self.batch_api_target_cache[schedulable.platform_name][schedulable.target]
sub_units = []
for batch_target in batch_targets:
userinfo = await config.get_platform_target_subscribers(schedulable.platform_name, batch_target)
sub_units.append(SubUnit(batch_target, userinfo))
to_send = await platform_obj.do_batch_fetch_new_post(sub_units)
else:
send_userinfo_list = await config.get_platform_target_subscribers(
schedulable.platform_name, schedulable.target
)
to_send = await platform_obj.do_fetch_new_post(SubUnit(schedulable.target, send_userinfo_list))
success_flag = True
except SkipRequestException as err:
logger.debug(f"skip request: {err}")
except Exception as err:
@@ -131,16 +134,17 @@ class Scheduler:
sent_counter.labels(
platform_name=schedulable.platform_name, site_name=platform_obj.site.name, target=schedulable.target
).inc()
for user, send_list in to_send:
for send_post in send_list:
logger.info(f"send to {user}: {send_post}")
try:
await send_msgs(
user,
await send_post.generate_messages(),
)
except NoBotFound:
logger.warning("no bot connected")
with render_histogram.labels(platform_name=schedulable.platform_name, site_name=platform_obj.site.name).time():
for user, send_list in to_send:
for send_post in send_list:
logger.info(f"send to {user}: {send_post}")
try:
await send_msgs(
user,
await send_post.generate_messages(),
)
except NoBotFound:
logger.warning("no bot connected")
def insert_new_schedulable(self, platform_name: str, target: Target):
self.pre_weight_val += 1000