From 51cf0639813201a97b1afabb3cd398e049194dc1 Mon Sep 17 00:00:00 2001 From: jshixiong <2645476194@qq.com> Date: Fri, 9 May 2025 11:48:27 +0800 Subject: [PATCH] fix --- README.md | 8 ++++++++ app/login_info.py | 8 ++++++-- app/network.py | 2 +- app/request_info.py | 3 +-- app/sys_clean.py | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3814437..93ccf25 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # py_sys_monitor +```.env +RUBY_RECENT_LOGIN_URL=http://test-data.educoder.net/api/home/online_users.json +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 +``` diff --git a/app/login_info.py b/app/login_info.py index 8be3dd1..6173759 100644 --- a/app/login_info.py +++ b/app/login_info.py @@ -1,7 +1,11 @@ import json +import os + import requests import logging +ruby_recent_login_url = os.getenv("RUBY_RECENT_LOGIN_URL", "http://test-data.educoder.net/api/home/online_users.json") +ruby_oline_size_url = os.getenv("RUBY_ONLINE_SIZE_URL", "http://test-data.educoder.net/api/home/online_num") def get_recent_login_info(page_index=1, page_size=10): if page_index <= 0: @@ -12,7 +16,7 @@ def get_recent_login_info(page_index=1, page_size=10): data = {"status":-1,"message":"响应失败"} try: - url = f"http://test-data.educoder.net/api/home/online_users.json?limit={page_size}&page={page_index}" + url = f"{ruby_recent_login_url}?limit={page_size}&page={page_index}" response = requests.get(url) data = response.json() response.raise_for_status() # 如果响应状态码不是 200,会引发 HTTPError @@ -31,7 +35,7 @@ def get_online_size(): 返回结果为服务器的响应 JSON 数据。 """ try: - url = 'http://test-data.educoder.net/api/home/online_num' + url = ruby_oline_size_url response = requests.get(url) response.raise_for_status() # 如果响应状态码不是 200,会引发 HTTPError data = response.json() diff --git a/app/network.py b/app/network.py index 67877bc..75cc993 100644 --- a/app/network.py +++ b/app/network.py @@ -5,7 +5,7 @@ import os from datetime import datetime, timedelta from collections import deque -log_file_path = '/data/ww/py_sys_monitor/info/net_speed' +log_file_path = os.getenv("NET_SPEED_PATH", '/data/ww/py_sys_monitor/info/net_speed') def ensure_log_file_exists(): if not os.path.exists(log_file_path): diff --git a/app/request_info.py b/app/request_info.py index d90da76..68e1dd5 100644 --- a/app/request_info.py +++ b/app/request_info.py @@ -1,8 +1,7 @@ import os import json -from flask import request -log_file_path = '/data/ww/py_sys_monitor/info/access_log' +log_file_path = os.getenv("ACCESS_LOG_PATH", '/data/ww/py_sys_monitor/info/access_log') def get_request_info(page_index=1, page_size=10): if page_index <= 0: diff --git a/app/sys_clean.py b/app/sys_clean.py index 3c1e053..6b259e9 100644 --- a/app/sys_clean.py +++ b/app/sys_clean.py @@ -6,7 +6,7 @@ import string from flask import jsonify import logging -log_directory = '/data/ww/py_sys_monitor/logs/junk' +log_directory = os.getenv("JUNK_PATH", '/data/ww/py_sys_monitor/logs/junk') def get_junk_file(): if not os.path.exists(log_directory):