fix:报警阈值配置

master
jshixiong 4 months ago
parent b2f5192784
commit aba736daff

@ -7,4 +7,8 @@ RUBY_ONLINE_SIZE_URL=http://test-data.educoder.net/api/home/online_num
NET_SPEED_PATH=/data/ww/py_sys_monitor/info/net_speed
ACCESS_LOG_PATH=/data/ww/py_sys_monitor/info/access_log
JUNK_PATH=/data/ww/py_sys_monitor/logs/junk
CPU_ALARM_THRESHOLD=70
MEMORY_ALARM_THRESHOLD=70
IO_ALARM_THRESHOLD=70
```

@ -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小时网络传输速度

Loading…
Cancel
Save