Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

system_app.py 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License
  15. #
  16. import json
  17. from flask_login import login_required
  18. from api.db.services.knowledgebase_service import KnowledgebaseService
  19. from api.utils.api_utils import get_json_result
  20. from api.versions import get_rag_version
  21. from rag.settings import SVR_QUEUE_NAME
  22. from rag.utils.es_conn import ELASTICSEARCH
  23. from rag.utils.minio_conn import MINIO
  24. from timeit import default_timer as timer
  25. from rag.utils.redis_conn import REDIS_CONN
  26. @manager.route('/version', methods=['GET'])
  27. @login_required
  28. def version():
  29. return get_json_result(data=get_rag_version())
  30. @manager.route('/status', methods=['GET'])
  31. @login_required
  32. def status():
  33. res = {}
  34. st = timer()
  35. try:
  36. res["es"] = ELASTICSEARCH.health()
  37. res["es"]["elapsed"] = "{:.1f}".format((timer() - st)*1000.)
  38. except Exception as e:
  39. res["es"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  40. st = timer()
  41. try:
  42. MINIO.health()
  43. res["minio"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
  44. except Exception as e:
  45. res["minio"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  46. st = timer()
  47. try:
  48. KnowledgebaseService.get_by_id("x")
  49. res["mysql"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
  50. except Exception as e:
  51. res["mysql"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  52. st = timer()
  53. try:
  54. if not REDIS_CONN.health():
  55. raise Exception("Lost connection!")
  56. res["redis"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
  57. except Exception as e:
  58. res["redis"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  59. try:
  60. obj = json.loads(REDIS_CONN.get("TASKEXE"))
  61. color = "green"
  62. for id in obj.keys():
  63. arr = obj[id]
  64. if len(arr) == 1:
  65. obj[id] = [0]
  66. else:
  67. obj[id] = [arr[i+1]-arr[i] for i in range(len(arr)-1)]
  68. elapsed = max(obj[id])
  69. if elapsed > 50: color = "yellow"
  70. if elapsed > 120: color = "red"
  71. res["task_executor"] = {"status": color, "elapsed": obj}
  72. except Exception as e:
  73. res["task_executor"] = {"status": "red", "error": str(e)}
  74. return get_json_result(data=res)