Commit 6a3c55a0 authored by Santhosh Kumar's avatar Santhosh Kumar

cleanup code

parent db69f3ea
import matplotlib.pyplot as plt
# Given values
cpu_utilization = [0, 10, 30, 40, 50, 60, 80, 90, 100]
service_time = [1.36,
1.26,
1.30,
1.32,
1.35,
1.40,
1.35,
1.37,
1.35,
]
num_of_pods = [1, 2, 5, 5, 5, 5, 5, 5, 5]
# Plotting
plt.figure(figsize=(10, 6))
# CPU Utilization on x-axis
plt.plot(cpu_utilization, service_time, label='Service Time(s)', marker='o')
# Number of Pods
plt.plot(cpu_utilization, num_of_pods, label='Number of Pods', marker='o')
plt.title('Service Time and Number of Pods vs. CPU Utilization')
plt.xlabel('CPU Utilization Limit(%)')
plt.ylabel('Service Time(s)')
plt.legend()
plt.grid(True)
plt.text(100, 5, 'minReplicas: 1\nmaxReplicas: 5\nMax CPU utilization: 40%', bbox=dict(facecolor='lightblue', alpha=0.5))
for cpu, avg_cpu, pods in zip(cpu_utilization, service_time, num_of_pods):
plt.text(cpu, avg_cpu, f'{avg_cpu}', ha='right', va='bottom')
plt.text(cpu, pods, f'{pods}', ha='right', va='bottom')
plt.tight_layout()
plt.show()
...@@ -4,6 +4,7 @@ from prometheus_client import Counter, Gauge, start_http_server ...@@ -4,6 +4,7 @@ from prometheus_client import Counter, Gauge, start_http_server
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST, CollectorRegistry from prometheus_client import generate_latest, CONTENT_TYPE_LATEST, CollectorRegistry
import psutil import psutil
import time import time
import subprocess
import multiprocessing import multiprocessing
...@@ -122,10 +123,14 @@ def get_memory_usage(): ...@@ -122,10 +123,14 @@ def get_memory_usage():
result = subprocess.run(['top', '-b', '-n', '1'], capture_output=True, text=True) result = subprocess.run(['top', '-b', '-n', '1'], capture_output=True, text=True)
return result.stdout return result.stdout
@app.route('/memory') @app.route('/memory/<int:memory_size>', methods=['GET'])
def manage_memory(): def manage_memory(memory_size):
global stress_process global stress_process
size = request.args.get('size') try:
size = int(memory_size) * 1024*1024
except ValueError:
return jsonify({'error': 'Invalid memory size'}), 400
if size: if size:
if stress_process: if stress_process:
# Kill existing stress-ng process # Kill existing stress-ng process
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment