DavidLiu 4 months ago
parent
commit
29bc6b810e
2 changed files with 6 additions and 6 deletions
  1. 4 0
      src/core/callcenter/registry.py
  2. 2 6
      src/core/callcenter/views.py

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

@@ -10,6 +10,10 @@ from prometheus_flask_exporter import PrometheusMetrics
 
 
 metrics = PrometheusMetrics(app)
 metrics = PrometheusMetrics(app)
 
 
+def new_histogram(name: str,
+                 documentation: str,
+                 labelnames: Iterable[str] = (), **kwargs):
+    return Histogram(name, documentation, labelnames, **kwargs)
 
 
 def counter(name, description, labels=None, initial_value_when_only_static_labels=True, **kwargs):
 def counter(name, description, labels=None, initial_value_when_only_static_labels=True, **kwargs):
     return metrics.counter(name, description, labels, initial_value_when_only_static_labels, **kwargs)
     return metrics.counter(name, description, labels, initial_value_when_only_static_labels, **kwargs)

+ 2 - 6
src/core/callcenter/views.py

@@ -12,7 +12,7 @@ from src.core.callcenter.call import CallService
 from src.core.callcenter.api import AgentCallRequest, AgentActionRequest, HangupCallRequest
 from src.core.callcenter.api import AgentCallRequest, AgentActionRequest, HangupCallRequest
 from src.core.voip.bot import BotAgent
 from src.core.voip.bot import BotAgent
 from .acd import AcdService
 from .acd import AcdService
-from src.core.callcenter.registry import Histogram
+from src.core.callcenter import registry
 
 
 agent = BotAgent(app)
 agent = BotAgent(app)
 inbound_client = InboundClient(agent,app)
 inbound_client = InboundClient(agent,app)
@@ -23,12 +23,8 @@ agent_oper_service = AgentOperService(app)
 acd_service = AcdService(inbound_client, app)
 acd_service = AcdService(inbound_client, app)
 agent.acd_service = acd_service
 agent.acd_service = acd_service
 CONTENT_TYPE_LATEST = str('text/plain; version=0.0.4; charset=utf-8')
 CONTENT_TYPE_LATEST = str('text/plain; version=0.0.4; charset=utf-8')
+REQUEST_LATENCY = registry.new_histogram('liuwei_request_latency_seconds', 'Request latency in seconds', ['method', 'endpoint'])
 
 
-REQUEST_LATENCY = Histogram(
-    'request_latency_seconds',
-    'Request latency in seconds',
-    ['method', 'endpoint']
-)
 @app.before_request
 @app.before_request
 def start_timer():
 def start_timer():
     """在请求开始时记录时间"""
     """在请求开始时记录时间"""