mirror of
https://git.oceanpay.cc/danial/kami_ctrip.git
synced 2025-12-19 00:06:01 +00:00
Merge remote-tracking branch 'origin/main' into develop
This commit is contained in:
@@ -15,7 +15,7 @@ RUN echo "" > /etc/apt/sources.list && \
|
||||
echo "deb http://mirrors.aliyun.com/debian buster-updates main" >> /etc/apt/sources.list
|
||||
|
||||
# 安装cv2依赖和其他依赖
|
||||
RUN apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0
|
||||
RUN apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0 curl
|
||||
|
||||
# 下载并安装 Node.js
|
||||
RUN wget https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.gz && \
|
||||
@@ -32,5 +32,9 @@ RUN pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
# 暴露容器端口
|
||||
EXPOSE 5001
|
||||
|
||||
# 添加健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
||||
CMD curl -f http://localhost:5001/health || exit 1
|
||||
|
||||
# 运行应用
|
||||
CMD ["gunicorn", "-c", "gun.conf", "app:app"]
|
||||
|
||||
33
app.py
33
app.py
@@ -1,4 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import psutil
|
||||
|
||||
from flask import Flask, g, request, jsonify
|
||||
|
||||
@@ -9,6 +12,9 @@ app = Flask(__name__)
|
||||
logger = get_logger()
|
||||
app.config["JSON_AS_ASCII"] = False
|
||||
|
||||
# 记录应用启动时间
|
||||
START_TIME = time.time()
|
||||
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
@@ -21,6 +27,33 @@ def before_request():
|
||||
g.proxies = {}
|
||||
|
||||
|
||||
@app.route("/health", methods=["GET"])
|
||||
def health_check():
|
||||
"""健康检查接口,用于容器监控服务状态"""
|
||||
# 获取当前进程信息
|
||||
process = psutil.Process(os.getpid())
|
||||
|
||||
# 计算运行时间
|
||||
uptime = time.time() - START_TIME
|
||||
|
||||
# 获取内存使用情况
|
||||
memory_info = process.memory_info()
|
||||
|
||||
health_data = {
|
||||
"status": "ok",
|
||||
"uptime": f"{uptime:.2f} seconds",
|
||||
"memory": {
|
||||
"rss": f"{memory_info.rss / (1024 * 1024):.2f} MB", # 物理内存
|
||||
"vms": f"{memory_info.vms / (1024 * 1024):.2f} MB", # 虚拟内存
|
||||
},
|
||||
"cpu_percent": f"{process.cpu_percent(interval=0.1):.2f}%",
|
||||
"threads": len(process.threads()),
|
||||
"version": "1.0.0",
|
||||
}
|
||||
|
||||
return jsonify(health_data)
|
||||
|
||||
|
||||
@app.route("/xiecheng/v3/card/bind", methods=["GET", "POST"])
|
||||
def bind_card_v3():
|
||||
if request.method == "GET":
|
||||
|
||||
@@ -11,4 +11,5 @@ selenium==3.141.0
|
||||
pillow==10.3.0
|
||||
pycryptodome==3.21.0
|
||||
pytz==2024.2
|
||||
loguru==0.7.2
|
||||
loguru==0.7.2
|
||||
psutil==5.9.5
|
||||
Reference in New Issue
Block a user