diff --git a/client.py b/client.py index 2e75cde..7fdc233 100644 --- a/client.py +++ b/client.py @@ -205,7 +205,7 @@ def main(): # 持续发送 send_interval = client_cfg['interval'] - api_url = client_cfg['server_url'] + '/api/update_data' + api_url = client_cfg['server_url'] + f'/{client_cfg['api_name']}/update_data' while True: data = collect_data() try: diff --git a/client_config.json b/client_config.json index eff9a25..a595694 100644 --- a/client_config.json +++ b/client_config.json @@ -9,5 +9,6 @@ "/media/D", "/media/E", "/media/F" - ] + ], + "api_name": "api" } \ No newline at end of file diff --git a/server.py b/server.py index 536b3d5..513fce4 100644 --- a/server.py +++ b/server.py @@ -10,20 +10,28 @@ CORS(app) server_cfg = None data_dict = dict() +parser = argparse.ArgumentParser() +parser.add_argument('--cfg', default='server_config.json', type=str, help='the path of config json.') +args = parser.parse_args() +# 加载配置文件 +cfg_path = args.cfg +with open(cfg_path, 'r') as f: + server_cfg = json.load(f) + #endregion #region 接口 # 测试用 -@app.route('/api') +@app.route(f'/{server_cfg['api_name']}') def hello(): return 'hi. —— CheckGPUsWeb' -@app.route('/api/get_data', methods=['GET']) +@app.route(f'/{server_cfg['api_name']}/get_data', methods=['GET']) def get_data(): return jsonify(data_dict) -@app.route('/api/update_data', methods=['POST']) +@app.route(f'/{server_cfg['api_name']}/update_data', methods=['POST']) def receive_data(): data = request.json # 如果存在对应标题则更新记录 @@ -46,15 +54,6 @@ def init(): data_dict['server_dict'][server_name] = None def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--cfg', default='server_config.json', type=str, help='the path of config json.') - args = parser.parse_args() - # 加载配置文件 - cfg_path = args.cfg - global server_cfg - with open(cfg_path, 'r') as f: - server_cfg = json.load(f) - init() # flask app.run(debug=False, host=server_cfg['host'], port=server_cfg['port']) diff --git a/server_config.json b/server_config.json index 928f390..b7285a3 100644 --- a/server_config.json +++ b/server_config.json @@ -4,5 +4,6 @@ "server_list":["76", "174", "233", "222"], "note_dict":{ "174": "test note" - } + }, + "api_name": "api" } \ No newline at end of file diff --git a/web/js/script.js b/web/js/script.js index fd57979..b93b6bb 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -1,6 +1,6 @@ // 请求服务器获取数据 function fetchData() { - fetch('http://10.1.16.174:15002/api/get_data') + fetch('http://10.1.16.174:15002/api/get_data') // http://mm.zjgsu.edu.cn/serverInfo-api/get_data // 获取服务器和显卡数据 .then(response => response.json()) // 解析 JSON 响应 .then(data => { @@ -130,7 +130,7 @@ function displayServerData(data){ serverData.cpu['temperature_list'].forEach(function(v){ temperature_list_str += v + " ℃ "; }); - cpuInfo.innerHTML = "CPU型号 : " + serverData.cpu['name'] + "
" + + cpuInfo.innerHTML = "" + serverData.cpu['name'] + "
" + "温度 : " + temperature_list_str + "
" + "占用率 : " + serverData.cpu['core_avg_occupy'] + "%";