Davidliu 3 months ago
parent
commit
92217a4bce
2 changed files with 6 additions and 1 deletions
  1. 1 0
      src/core/callcenter/registry.py
  2. 5 1
      src/core/voip/bot.py

+ 1 - 0
src/core/callcenter/registry.py

@@ -34,6 +34,7 @@ ESL_EVENT_CALLBACK_LATENCY = Histogram('esl_event_callback_latency', 'Esl Event
 
 
 BOT_CALL_DURATION = Histogram('bot_call_duration', '通话时长',['taskId'])
+BOT_REQUEST_ONCE_LATENCY = Histogram('bot_request_once_latency','请求机器人单次耗时',['taskId'])
 BOT_REQUEST_LATENCY = Histogram('bot_request_latency','请求机器人耗时',['taskId'])
 BOT_INTERACTION_ROUNDS = Histogram('bot_interaction_rounds',  '机器人交互轮次',['taskId'] )
 BOT_CREATE_ACCOUNT_LATENCY = Histogram('bot_create_account_latency',  '创建虚拟机器人耗时')

+ 5 - 1
src/core/voip/bot.py

@@ -449,9 +449,10 @@ class ToTextBotAgent:
                 # try:
                 session.headers.update({'Content-Type': 'application/json'})
                 while try_count > 0:
+                    once_start = time.time()
                     try:
                         try_count = try_count - 1
-                        response = session.post(url=url, json=json.loads(request_data), timeout=.5)
+                        response = session.post(url=url, json=json.loads(request_data), timeout=.8)
                         # response = requests.post(url=url,  json=json.loads(request_data), headers=headers, timeout=10)  # 使用占位URL
                         if response.status_code == 200:
                             response_data = response.json()
@@ -467,6 +468,9 @@ class ToTextBotAgent:
                     except requests.RequestException as e:
                         traceback.print_exc()
                         self.call_agent.logger.error(f"TaskId={request.taskId}, 请求发生异常: {e}, URL: {url}")
+                    finally:
+                        latency = (time.time() - once_start)
+                        registry.BOT_REQUEST_ONCE_LATENCY.labels(request.taskId).observe(latency)
                 if not response or response.status_code != 200:
                     massage = self.get_default_response()
                     self.call_agent.message_queue.put(massage)