Quellcode durchsuchen

metric tools debug

DavidLiu vor 4 Monaten
Ursprung
Commit
e498723446
2 geänderte Dateien mit 28 neuen und 3 gelöschten Zeilen
  1. 8 3
      src/core/callcenter/esl/client.py
  2. 20 0
      src/core/registry.py

+ 8 - 3
src/core/callcenter/esl/client.py

@@ -26,6 +26,7 @@ from src.core.callcenter.esl.constant.esl_constant import BRIDGE_VARIABLES, BRID
     ORIGINATE, PARK, SET, EAVESDROP, SMF_ALEG, EXECUTE, PLAYBACK, PAUSE, TRANSFER, UUID_TRANSFER, UUID_BROADCAST, \
     UUID_BREAK, UUID_HOLD, \
     UUID_RECORD, UUID_SETVAR, UUID_GETVAR, UUID_KILL
+import src.core.registry as Registry
 import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
 import src.core.callcenter.esl.handler as event_handler
 from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic, profile1, profile2, sipHeaderCallId
@@ -518,26 +519,30 @@ class OutboundClient:
                     kwargs['variable_sip_h_P-LIBRA-CallId'] = call_id
                     kwargs['variable_sip_h_P-LIBRA-DeviceId'] = new_device_id
 
+                    _call_type = 2
+                    destination = None
                     bucket = self.server.get_bucket(call_id)
                     whitelist = self.server.get_whitelist()
                     if bucket and bucket.name == 'AI':
                         #转到ai机器人
+                        _call_type = 1
                         destination = self.server.agent.register(**kwargs)
                         self.server.logger.info("device_id=%s, destination=%s, new_device_id=%s" % (device_id, destination, new_device_id))
                         self.build_call_info(call_id, device_id, new_device_id, str(destination), **kwargs)
                         self.server.cache.add_device_user_part(device_id, destination)
                         con.execute("bridge", "{sip_h_P-LIBRA-CallId=%s,sip_h_P-LIBRA-DeviceId=%s,origination_uuid=%s}user/%s" % (call_id, new_device_id, new_device_id, destination), device_id)
-                        self.server.dataHandleServer.create_record(call_id, caller_number, 1, service_category=1, destination=destination)
                     elif caller_number in whitelist:
                         # 检查白名单
+                        _call_type = 0
                         self.build_call_info(call_id, device_id, new_device_id, destination=None, **kwargs)
                         self.server.agent.acd_service.transfer_to_agent(call_id, new_device_id)
-                        self.server.dataHandleServer.create_record(call_id, caller_number, 0, service_category=None, destination=None)
                     else:
                         # 传统服务
                         self.build_call_info(call_id, device_id, new_device_id, destination=None, **kwargs)
                         self.server.agent.acd_service.transfer_to_agent(call_id, new_device_id)
-                        self.server.dataHandleServer.create_record(call_id, caller_number, 2, service_category=None, destination=None)
+
+                    Registry.counter('call_incoming_requests', '呼入流量统计', ['call_type', str(_call_type)])
+                    self.server.dataHandleServer.create_record(call_id, caller_number, _call_type, service_category=None, destination=destination)
 
                     # # 检查白名单
                     # if caller_number in whitelist:

+ 20 - 0
src/core/registry.py

@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+# encoding:utf-8
+
+import prometheus_client
+from typing import Iterable
+from prometheus_client import Counter, Gauge, Histogram, Summary
+from prometheus_client.core import CollectorRegistry
+
+
+def counter(name: str, documentation: str, labelnames: Iterable[str] = ()):
+    return Counter(name, documentation, labelnames)
+
+def gauge(name: str, documentation: str, labelnames: Iterable[str] = ()):
+    return Gauge(name, documentation, labelnames)
+
+def histogram(name: str, documentation: str, labelnames: Iterable[str] = ()):
+    return Histogram(name, documentation, labelnames)
+
+def summary(name: str, documentation: str, labelnames: Iterable[str] = ()):
+    return Summary(name, documentation, labelnames)