Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

system_app.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.settings import DATABASE_TYPE
  20. from api.utils.api_utils import get_json_result
  21. from api.versions import get_rag_version
  22. from rag.settings import SVR_QUEUE_NAME
  23. from rag.utils.es_conn import ELASTICSEARCH
  24. from rag.utils.storage_factory import STORAGE_IMPL, STORAGE_IMPL_TYPE
  25. from timeit import default_timer as timer
  26. from rag.utils.redis_conn import REDIS_CONN
  27. @manager.route('/version', methods=['GET'])
  28. @login_required
  29. def version():
  30. return get_json_result(data=get_rag_version())
  31. @manager.route('/status', methods=['GET'])
  32. @login_required
  33. def status():
  34. res = {}
  35. st = timer()
  36. try:
  37. res["es"] = ELASTICSEARCH.health()
  38. res["es"]["elapsed"] = "{:.1f}".format((timer() - st)*1000.)
  39. except Exception as e:
  40. res["es"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  41. st = timer()
  42. try:
  43. STORAGE_IMPL.health()
  44. res["storage"] = {"storage": STORAGE_IMPL_TYPE.lower(), "status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
  45. except Exception as e:
  46. res["storage"] = {"storage": STORAGE_IMPL_TYPE.lower(), "status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  47. st = timer()
  48. try:
  49. KnowledgebaseService.get_by_id("x")
  50. res["database"] = {"database": DATABASE_TYPE.lower(), "status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
  51. except Exception as e:
  52. res["database"] = {"database": DATABASE_TYPE.lower(), "status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  53. st = timer()
  54. try:
  55. if not REDIS_CONN.health():
  56. raise Exception("Lost connection!")
  57. res["redis"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
  58. except Exception as e:
  59. res["redis"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  60. try:
  61. v = REDIS_CONN.get("TASKEXE")
  62. if not v:
  63. raise Exception("No task executor running!")
  64. obj = json.loads(v)
  65. color = "green"
  66. for id in obj.keys():
  67. arr = obj[id]
  68. if len(arr) == 1:
  69. obj[id] = [0]
  70. else:
  71. obj[id] = [arr[i+1]-arr[i] for i in range(len(arr)-1)]
  72. elapsed = max(obj[id])
  73. if elapsed > 50: color = "yellow"
  74. if elapsed > 120: color = "red"
  75. res["task_executor"] = {"status": color, "elapsed": obj}
  76. except Exception as e:
  77. res["task_executor"] = {"status": "red", "error": str(e)}
  78. return get_json_result(data=res)