add string returns for metrics and properties

This commit is contained in:
2026-03-16 09:17:44 -07:00
parent adb1387693
commit 61421305ed
16 changed files with 524 additions and 390 deletions

View File

@ -76,7 +76,8 @@ def update_redis_channel(redis_channel, data):
def update_redis_server():
# Update Stats Redis Channel
update_redis_channel("host_metrics", get_redis_data())
if cosmostat_system.check_system_timer():
update_redis_channel("host_metrics", get_redis_data(human_readable = False))
# Update history_stats Redis Channel
# update_redis_channel("history_stats", get_component_list())
@ -98,7 +99,12 @@ def static_data():
# redis data
@app.route('/redis_data', methods=['GET'])
def redis_data():
return jsonify(get_redis_data())
return jsonify(get_redis_data(human_readable = False))
# redis strings
@app.route('/redis_strings', methods=['GET'])
def redis_strings():
return jsonify(get_redis_data(human_readable = True))
# full summary
@app.route('/full_summary', methods=['GET'])
@ -110,15 +116,43 @@ def full_summary():
def info():
return jsonify(get_info())
# socket timer
@app.route('/start_timer', methods=['GET'])
def start_timer():
current_timestamp = int(time.time())
cosmostat_system.recent_check = current_timestamp
if app_settings["noisy_test"]:
print(f"Timestamp updated to {cosmostat_system.recent_check}")
return jsonify(
{
"message": "websocket timer reset",
"new_timestamp": cosmostat_system.recent_check
}
)
# socket timer data
@app.route('/timer_data', methods=['GET'])
def timer_data():
time_now = time.time()
time_lapsed = time_now - float(cosmostat_system.recent_check)
result = {
"Time Lapsed": time_lapsed,
"Current Time Value": time_now,
"Last Update Value": float(cosmostat_system.recent_check),
"System Updating": cosmostat_system.check_system_timer()
}
return jsonify(result)
# test route
@app.route('/test', methods=['GET'])
def test():
this_cpu = cosmostat_system.get_components(component_type="CPU")
return jsonify(
{
"component_count:": len(cosmostat_system.components),
"user": jenkins_user_settings(),
"hostname": jenkins_hostname_settings(),
"cpu_model": cosmostat_system.get_components(component_type="CPU").description
"cpu_model": this_cpu[0].description
}
)
@ -128,22 +162,18 @@ def test():
# needs to return array of {name: name, type: type, metrics: metrics}
# for redis table generation, includes system and component metrics
def get_dynamic_data():
return cosmostat_system.get_live_metrics()
def get_dynamic_data(human_readable = False):
return cosmostat_system.get_live_metrics(human_readable)
def get_static_data():
def get_static_data(human_readable = False):
result = []
for metric in cosmostat_system.get_system_properties():
result.append(metric)
for metric in cosmostat_system.get_component_properties():
result.append(metric)
return result
return cosmostat_system.get_static_metrics(human_readable)
def get_redis_data():
def get_redis_data(human_readable = False):
result = []
for metric in get_dynamic_data():
for metric in get_dynamic_data(human_readable):
result.append(metric)
for metric in get_static_data():
for metric in get_static_data(human_readable):
result.append(metric)
return result
@ -171,11 +201,11 @@ def get_info():
component_strings = []
for component in cosmostat_system.get_components():
component_strings.append({"name": component.name, "description": component.description})
system_strings = []
result = {
"hostname": jenkins_hostname_settings(),
"component_strings": component_strings
"component_strings": component_strings,
"system_strings": cosmostat_system.get_sysvars_summary_keys()
}
#for component_string in component_strings:
# for name, description in component_string.items():
@ -199,7 +229,8 @@ def new_cosmos_system():
# Background Loop Function
def background_loop():
# Update all data on the System object
cosmostat_system.update_system_state()
if cosmostat_system.check_system_timer():
cosmostat_system.update_system_state()
if app_settings["push_redis"]:
update_redis_server()
@ -241,7 +272,7 @@ if __name__ == '__main__':
print("Skipping flask background task")
# Flask API
app.run(debug=True, host=service_gateway_ip(), port=5000)
app.run(debug=False, host=service_gateway_ip(), port=5000)