|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from flask import Blueprint, request, jsonify
|
|
|
|
|
import app.cpu_usage as cpu_usage
|
|
|
|
|
import app.io_usage as io_usage
|
|
|
|
@ -11,6 +13,9 @@ import app.sys_control as sys_control
|
|
|
|
|
|
|
|
|
|
route_bp = Blueprint('route', __name__)
|
|
|
|
|
|
|
|
|
|
cpu_alarm_threshold = os.getenv('CPU_ALARM_THRESHOLD', 70)
|
|
|
|
|
io_alarm_threshold = os.getenv('IO_ALARM_THRESHOLD', 70)
|
|
|
|
|
memory_alarm_threshold = os.getenv('MEMORY_ALARM_THRESHOLD', 70)
|
|
|
|
|
# 资源使用情况
|
|
|
|
|
@route_bp.route('/api/sys/resource', methods=['GET'])
|
|
|
|
|
def get_resource():
|
|
|
|
@ -19,7 +24,7 @@ def get_resource():
|
|
|
|
|
memory_percent = memory_usage.get_memory_percent()
|
|
|
|
|
online = login_info.get_online_size()
|
|
|
|
|
status = 0
|
|
|
|
|
if cpu_percent >= 70 or memory_percent >= 70 or io_percent >= 50:
|
|
|
|
|
if cpu_percent >= cpu_alarm_threshold or memory_percent >= memory_alarm_threshold or io_percent >= io_alarm_threshold:
|
|
|
|
|
status = 1
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
@ -28,6 +33,9 @@ def get_resource():
|
|
|
|
|
'cpu_percent': cpu_percent,
|
|
|
|
|
'io_percent': io_percent,
|
|
|
|
|
'memory_percent': memory_percent,
|
|
|
|
|
'cpu_alarm_threshold': cpu_alarm_threshold,
|
|
|
|
|
'io_alarm_threshold': io_alarm_threshold,
|
|
|
|
|
'memory_alarm_threshold': memory_alarm_threshold,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
# 获取过去12小时网络传输速度
|
|
|
|
|