From ddc1c6e9cf92d7d446f08905996a6e693fed85ed Mon Sep 17 00:00:00 2001 From: lxb <1580622474@qq.com> Date: Wed, 4 Dec 2024 21:51:30 +0800 Subject: [PATCH] update --- client.py | 4 ++-- client_config.json | 2 +- server.py | 23 ++++++++++++++++------- serverList_examlpe.json | 21 --------------------- server_config.json | 6 ++++++ 5 files changed, 25 insertions(+), 31 deletions(-) delete mode 100644 serverList_examlpe.json create mode 100644 server_config.json diff --git a/client.py b/client.py index 0f7b11d..e912cc7 100644 --- a/client.py +++ b/client.py @@ -149,7 +149,7 @@ def collect_data(): result_dict['update_time_stamp'] = int(time.time()) result_dict['error_dict'] = error_dict result_dict['note'] = client_cfg['note'] - result_dict['api_key'] = client_cfg['api_key'] + result_dict['title'] = client_cfg['title'] return result_dict @@ -166,7 +166,7 @@ def main(): while True: data = collect_data() try: - response = requests.post(api_url, json=data) + requests.post(api_url, json=data) except Exception as e: print(e) time.sleep(send_interval) diff --git a/client_config.json b/client_config.json index 52f86e8..eff9a25 100644 --- a/client_config.json +++ b/client_config.json @@ -1,6 +1,6 @@ { "server_url": "http://127.0.0.1:15002", - "api_key": "default_key_000", + "title": "174", "interval": 3.0, "note": "", "enable": ["gpu", "cpu", "memory", "storage", "network"], diff --git a/server.py b/server.py index 50fa5bd..147b5e7 100644 --- a/server.py +++ b/server.py @@ -10,10 +10,7 @@ import time app = Flask(__name__) CORS(app) port = 15002 -server_list_path = 'serverList.json' -data_list_lock = threading.Lock() -check_interval = 2 -# 共享list +server_cfg = None data_dict = dict() #endregion @@ -27,18 +24,30 @@ def hello(): @app.route('/api/get_data', methods=['GET']) def get_data(): - return jsonify({}) + return jsonify(data_dict) @app.route('/api/update_data', methods=['POST']) def receive_data(): data = request.json - print(data) + if (data['title'] in server_cfg['server_list']): + data_dict['server_dict'][data['title']] = data return jsonify({"status": "success"}) #endregion -# 测试 +def init(): + data_dict['server_dict'] = dict() + for server_name in server_cfg['server_list']: + data_dict['server_dict'][server_name] = None + def main(): + # 加载配置文件 + cfg_path = "server_config.json" + global server_cfg + with open(cfg_path, 'r') as f: + server_cfg = json.load(f) + + # flask app.run(debug=False, host='127.0.0.1', port=port) if __name__ == '__main__': diff --git a/serverList_examlpe.json b/serverList_examlpe.json deleted file mode 100644 index 29e2425..0000000 --- a/serverList_examlpe.json +++ /dev/null @@ -1,21 +0,0 @@ -[ - { - "title": "SERVER_233", - "ip": "123.123.123.233", - "port": 12345, - "username": "lxb", - "password": "abcdefg" - }, - { - "title": "SERVER_76", - "ip": "123.123.123.76", - "port": 22, - "username": "lxb", - "key_filename": "/home/.ssh/id_rsa", - "network_interface_name": "eno2", - "storage_list": [ - "/media/D", - "/media/F" - ] - } -] \ No newline at end of file diff --git a/server_config.json b/server_config.json new file mode 100644 index 0000000..68a7258 --- /dev/null +++ b/server_config.json @@ -0,0 +1,6 @@ +{ + "server_list":["76", "174", "233", "222"], + "note_dict":{ + "174": "test note" + } +} \ No newline at end of file