You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

system_app.py 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. from flask_login import login_required
  17. from api.db.services.knowledgebase_service import KnowledgebaseService
  18. from api.utils.api_utils import get_json_result
  19. from api.versions import get_rag_version
  20. from rag.settings import SVR_QUEUE_NAME
  21. from rag.utils.es_conn import ELASTICSEARCH
  22. from rag.utils.minio_conn import MINIO
  23. from timeit import default_timer as timer
  24. from rag.utils.redis_conn import REDIS_CONN
  25. @manager.route('/version', methods=['GET'])
  26. @login_required
  27. def version():
  28. return get_json_result(data=get_rag_version())
  29. @manager.route('/status', methods=['GET'])
  30. @login_required
  31. def status():
  32. res = {}
  33. st = timer()
  34. try:
  35. res["es"] = ELASTICSEARCH.health()
  36. res["es"]["elapsed"] = "{:.1f}".format((timer() - st)*1000.)
  37. except Exception as e:
  38. res["es"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  39. st = timer()
  40. try:
  41. MINIO.health()
  42. res["minio"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
  43. except Exception as e:
  44. res["minio"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  45. st = timer()
  46. try:
  47. KnowledgebaseService.get_by_id("x")
  48. res["mysql"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)}
  49. except Exception as e:
  50. res["mysql"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  51. st = timer()
  52. try:
  53. qinfo = REDIS_CONN.health(SVR_QUEUE_NAME)
  54. res["redis"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.), "pending": qinfo["pending"]}
  55. except Exception as e:
  56. res["redis"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)}
  57. return get_json_result(data=res)