storage api python service templated and port added to jenkinsfile

This commit is contained in:
2025-10-26 20:19:08 -07:00
parent a483c5eae1
commit 0e694894ca
16 changed files with 338 additions and 70 deletions

View File

@ -1,34 +0,0 @@
from flask import Flask, jsonify
import psutil
app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
def bytes_to_human_readable(bytes):
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
if bytes < 1024.0:
return f"{bytes:.2f} {unit}"
bytes /= 1024.0
def get_disk_info():
disk_info = []
partitions = psutil.disk_partitions()
for partition in partitions:
usage = psutil.disk_usage(partition.mountpoint)
disk_info.append({
'device': partition.device.replace('\\\\', '\\').rstrip('\\'),
#'mountpoint': partition.mountpoint,
#'fstype': partition.fstype,
'total': bytes_to_human_readable(usage.total),
'used': bytes_to_human_readable(usage.used),
'free': bytes_to_human_readable(usage.free),
'percent': usage.percent
})
return disk_info
@app.route('/disk', methods=['GET'])
def disk():
return jsonify(get_disk_info())
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)