Files
cosmoserver/files/archive/archive.py

184 lines
5.2 KiB
Python

# dynamic data
# this will go to the redis server
@app.route('/dynamic_data', methods=['GET'])
def dynamic_data():
return jsonify(get_dynamic_data())
# static data
@app.route('/static_data', methods=['GET'])
def static_data():
return jsonify(get_static_data())
# redis data
@app.route('/redis_data', methods=['GET'])
def redis_data():
return jsonify(get_client_redis_data(human_readable = False))
# redis strings
@app.route('/redis_strings', methods=['GET'])
def redis_strings():
return jsonify(get_client_redis_data(human_readable = True))
# socket timer data
@app.route('/timer_data', methods=['GET'])
def timer_data():
time_now = time.time()
time_lapsed = time_now - float(cosmostat_client.recent_check)
result = {
"Time Lapsed": time_lapsed,
"Current Time Value": time_now,
"Last Update Value": float(cosmostat_client.recent_check),
"System Updating": cosmostat_client.check_system_timer()
}
return jsonify(result)
def get_static_data(human_readable = False):
result = []
return cosmostat_client.get_static_metrics(human_readable)
def generate_state_definition():
result = {
"uuid": cosmostat_client.uuid,
"state_definition": get_php_summary()
}
return result
# api to validate Cosmostat Class
@app.route('/client_summary', methods=['GET'])
def client_summary():
result = []
if run_cosmostat_server():
result = get_client_summary()
else:
result = {"message": "server not running on this endpoint"}
return jsonify(result)
# api to get all hostnames
@app.route('/client_hostnames', methods=['GET'])
def client_hostnames():
result = []
if run_cosmostat_server():
result = cosmostat_server.get_client_hostnames(send_age = True)
else:
result = {"message": "server not running on this endpoint"}
return jsonify(result)
# api to get server redis data
@app.route('/get_server_redis', methods=['GET'])
def get_server_redis():
result = []
if run_cosmostat_server():
result = get_server_redis_data()
else:
result = {"message": "server not running on this endpoint"}
return jsonify(result)
# api to get server redis data
@app.route('/client_ip_summary', methods=['GET'])
def client_ip_summary():
result = []
if run_cosmostat_server():
result = get_client_ip_summary()
else:
result = {"message": "server not running on this endpoint"}
return jsonify(result)
# generate cosmostat server summary
def get_client_summary():
result = []
for client in cosmostat_server.systems:
data_age = time.time() - client.data_timestamp
this_client = {
"uuid": client.uuid,
"short_id": client.name,
"data_age": data_age,
"hostname": client.hostname
}
result.append(this_client)
if result == []:
result = {"message": "no clients reporting"}
return result
########################################################
# various data functions
########################################################
# complex data type return
def get_property_summary(self, type = None):
these_properties = []
if type == None:
for name, value in self._properties.items():
these_properties.append({"Property": name, "Value": value})
else:
for name, value in self._properties.items():
if type in name:
these_properties.append({"Property": name, "Value": value})
result = {
"Source": self.name,
"Component Type": self.type,
"Properties": these_properties
}
return result
# simple data value return
def get_property_value(self, type = None):
result = []
print(f"Component type: {type}")
for name, value in self._properties.items():
print(f"Component Property: {name}")
if type in name:
result.append(value)
if len(result) == 1:
return result[0]
else:
return result
# full data return
def get_description(self):
these_properties = []
for name, value in self._properties.items():
these_properties.append({"Property": name, "Value": value})
these_metrics = []
for name, value in self._metrics.items():
these_metrics.append({"Metric": name, "Data": value})
result = {
"Source": self.name,
"Type": self.type,
"Properties": these_properties,
"Metrics": these_metrics
}
return result
# complex data type return
def get_metrics(self, type = None):
these_metrics = []
if type == None:
for name, value in self._metrics:
these_metrics.append({"Metric": name, "Data": value})
else:
for name, value in self._metrics:
if name == type:
these_metrics.append({"Metric": name, "Data": value})
result = {
"Source": self.name,
"Component Type": self.type,
"Metrics": these_metrics
}
return result