DavidLiu 4 месяцев назад
Родитель
Сommit
925051c1e1

+ 1 - 1
src/core/callcenter/esl/client.py

@@ -549,7 +549,7 @@ class OutboundClient:
                         self.build_call_info(call_id, device_id, new_device_id, destination=None, bucket_type=_bucket_call_type,  **kwargs)
                         self.server.agent.acd_service.transfer_to_agent(call_id, new_device_id)
 
-                    registry.counter('call_incoming_requests', '呼入流量统计', {'bucket_type': f"{_bucket_call_type}"})
+                    registry.CALL_INCOMING_REQUESTS.labels(f"{_bucket_call_type}").inc()
                     self.server.dataHandleServer.create_record(call_id, caller_number, _bucket_call_type, service_category=service_category, destination=destination)
 
                     # # 检查白名单

+ 3 - 2
src/core/callcenter/esl/handler/channel_answer_handler.py

@@ -35,7 +35,7 @@ class ChannelAnswerHandler(EslEventHandler):
 
         if CallType.BOT_CALL.code == call_info.call_type:
             call_info.answer_flag = AnswerFlag.ROBOT_ANSWER.code
-            registry.counter('call_bot_answer_requests', '呼入机器人接听量', {'bucket_type': f"{call_info.bucket_type}"})
+            registry.CALL_BOT_ANSWER_REQUESTS.labels(f"{call_info.bucket_type}").inc()
 
         next_command = call_info.next_commands[0] if len(call_info.next_commands) > 0 else None
         device_type = DeviceType.get_by_code(device_info.device_type)
@@ -128,7 +128,8 @@ class ChannelAnswerHandler(EslEventHandler):
         device_id = EslEventUtil.getDeviceId(event)
         call.answer_flag = AnswerFlag.AGENT_ANSWER.code
         if CallType.BOT_CALL.code == call.call_type:
-            registry.counter('call_bot_transfer_requests', '呼入机器人转人量', {'bucket_type': f"{call.bucket_type}"})
+            registry.CALL_BOT_TRANSFER_REQUESTS.labels(f"{call.bucket_type}").inc()
+
         self.record(event, device_id)
         call.next_commands.append(NextCommand(device_id, NextType.NEXT_TRANSFER_SUCCESS.code, call.device_list[1]))
         self.logger.info("转接电话中 callId:%s, from:%s, to:%s "% (call.call_id, from_device_id, device_id))

+ 7 - 29
src/core/callcenter/registry.py

@@ -6,36 +6,14 @@ import traceback
 from . import app
 from typing import Iterable
 from prometheus_client import Counter, Gauge, Histogram, Summary
-# from prometheus_client.core import CollectorRegistry
+from prometheus_client.core import CollectorRegistry
 from prometheus_flask_exporter import PrometheusMetrics
 
 metrics = PrometheusMetrics(app)
+# 呼入总量
+CALL_INCOMING_REQUESTS = Counter('call_incoming_requests', '呼入总流量', ['bucket'])
+CALL_BOT_ANSWER_REQUESTS = Counter('call_bot_answer_requests', '机器人接听量', ['bucket'])
+CALL_BOT_TRANSFER_REQUESTS = Counter('call_bot_transfer_requests', '机器转人量', ['bucket'])
 
-
-
-ESL_EVENT_LATENCY = Histogram('esl_event_latency', 'Esl Event latency in seconds', ['eventName'])
-
-
-def counter(name, description, labels=None, initial_value_when_only_static_labels=True, **kwargs):
-    try:
-        return metrics.counter(name, description, labels, initial_value_when_only_static_labels, **kwargs)
-    except:
-        traceback.print_exc()
-
-def gauge(name, description, labels=None, initial_value_when_only_static_labels=True, **kwargs):
-    try:
-        return metrics.gauge(name, description, labels, initial_value_when_only_static_labels, **kwargs)
-    except:
-        traceback.print_exc()
-
-def histogram(name, description, labels=None, initial_value_when_only_static_labels=True, **kwargs):
-    try:
-        return metrics.histogram(name, description, labels, initial_value_when_only_static_labels, **kwargs)
-    except:
-        traceback.print_exc()
-
-def summary(name, description, labels=None, initial_value_when_only_static_labels=True, **kwargs):
-    try:
-        return metrics.summary(name, description, labels, initial_value_when_only_static_labels, **kwargs)
-    except:
-        traceback.print_exc()
+# esl时间耗时
+ESL_EVENT_LATENCY = Histogram('esl_event_latency', 'Esl Event latency in seconds', ['eventName'])