余尚辉 2 months ago
parent
commit
37e9a649fc
2 changed files with 7 additions and 3 deletions
  1. 2 3
      ai-slibra-assistant/api/AiBot.py
  2. 5 0
      ai-slibra-assistant/util/registry.py

+ 2 - 3
ai-slibra-assistant/api/AiBot.py

@@ -25,10 +25,8 @@ from entity import Error
 import traceback
 from util import insert_log, timetic
 
-from prometheus_fastapi_instrumentator import Instrumentator
 import time
 
-from util.registry import AI_BOT_REQUEST_LATENCY
 
 logger=get_logger("log")
 
@@ -37,6 +35,7 @@ app = FastAPI()
 
 # 服务监控,qps,latent, cpu利用率
 
+from util.registry import AI_BOT_REQUEST_LATENCY
 
 
 @app.post("/botservice")
@@ -92,6 +91,6 @@ def botservice(reqbot:reqRobot):
         latency = (time.time() - start_time)
         AI_BOT_REQUEST_LATENCY.labels(bid=bid).observe(latency)
 
-Instrumentator().instrument(app).expose(app)
+
 if __name__ == '__main__':
     uvicorn.run("AiBot:app", host='0.0.0.0', port=40072,workers=4)

+ 5 - 0
ai-slibra-assistant/util/registry.py

@@ -1,2 +1,7 @@
+from api.AiBot from app
+from prometheus_fastapi_instrumentator import Instrumentator
 from prometheus_client import Counter,Histogram
+
+Instrumentator().instrument(app).expose(app)
+
 AI_BOT_REQUEST_LATENCY = Histogram('ai_bot_request_latency',  '文本机器人接口耗时',['bid'])