lxb 8 months ago
parent
commit
cf61103462
  1. 4
      client.py
  2. 2
      client_config.json
  3. 23
      server.py
  4. 21
      serverList_examlpe.json
  5. 6
      server_config.json

4
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)

2
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"],

23
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__':

21
serverList_examlpe.json

@ -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"
]
}
]

6
server_config.json

@ -0,0 +1,6 @@
{
"server_list":["76", "174", "233", "222"],
"note_dict":{
"174": "test note"
}
}
Loading…
Cancel
Save