update(app): add helm chart and cleanup repo
Some checks failed
CI Pipeline / Build and Push Docker Image (push) Failing after 2m48s
Some checks failed
CI Pipeline / Build and Push Docker Image (push) Failing after 2m48s
This commit is contained in:
@@ -9,14 +9,12 @@ def fetch_k8s_data_with_usage():
|
||||
v1 = client.CoreV1Api()
|
||||
metrics_client = client.CustomObjectsApi()
|
||||
|
||||
# Fetch nodes
|
||||
nodes = []
|
||||
for node in v1.list_node().items:
|
||||
# Extract storage (ephemeral-storage) and instance type
|
||||
ephemeral_storage = node.status.capacity.get("ephemeral-storage", "0")
|
||||
instance_type = node.metadata.labels.get("beta.kubernetes.io/instance-type", "N/A")
|
||||
|
||||
# Calculate time on duty
|
||||
creation_timestamp = node.metadata.creation_timestamp
|
||||
if creation_timestamp:
|
||||
time_on_duty = calculate_time_on_duty(creation_timestamp)
|
||||
@@ -26,17 +24,15 @@ def fetch_k8s_data_with_usage():
|
||||
nodes.append({
|
||||
"node_name": node.metadata.name,
|
||||
"cpu": node.status.capacity.get("cpu"),
|
||||
"memory": round(convert_memory_to_mib(node.status.capacity.get("memory")), 2), # Convert to MiB
|
||||
"memory": round(convert_memory_to_mib(node.status.capacity.get("memory")), 2),
|
||||
"storage": f"{round(convert_memory_to_gb(ephemeral_storage), 2)} GB",
|
||||
"instance_type": instance_type,
|
||||
"pods_allocatable": node.status.allocatable.get("pods"),
|
||||
"time_on_duty": time_on_duty, # Add time on duty
|
||||
"time_on_duty": time_on_duty,
|
||||
})
|
||||
|
||||
# Fetch namespaces
|
||||
namespaces = [ns.metadata.name for ns in v1.list_namespace().items]
|
||||
|
||||
# Fetch pod metrics and calculate namespace resource usage
|
||||
namespace_usage = {}
|
||||
pod_metrics = metrics_client.list_cluster_custom_object(
|
||||
group="metrics.k8s.io", version="v1beta1", plural="pods"
|
||||
@@ -50,15 +46,13 @@ def fetch_k8s_data_with_usage():
|
||||
cpu_usage = container["usage"]["cpu"]
|
||||
memory_usage = container["usage"]["memory"]
|
||||
|
||||
# Convert CPU to cores and memory to MiB
|
||||
namespace_usage[pod_namespace]["cpu"] += convert_cpu_to_cores(cpu_usage)
|
||||
namespace_usage[pod_namespace]["memory"] += convert_memory_to_mib(memory_usage)
|
||||
|
||||
# Round and format usage for readability
|
||||
namespace_usage = {
|
||||
ns: {
|
||||
"cpu": round(usage["cpu"], 4), # Round to 4 decimal places
|
||||
"memory": round(usage["memory"], 2), # Memory in MiB
|
||||
"cpu": round(usage["cpu"], 4),
|
||||
"memory": round(usage["memory"], 2),
|
||||
}
|
||||
for ns, usage in namespace_usage.items()
|
||||
}
|
||||
@@ -73,17 +67,14 @@ def calculate_time_on_duty(creation_timestamp):
|
||||
now = datetime.now(timezone.utc)
|
||||
delta = now - creation_timestamp
|
||||
|
||||
# If less than an hour, return minutes
|
||||
if delta.days < 1 and delta.seconds < 3600:
|
||||
minutes = delta.seconds // 60
|
||||
return f"{minutes} minutes" if minutes > 1 else "less than a minute"
|
||||
|
||||
# If less than a day, return hours
|
||||
if delta.days < 1:
|
||||
hours = delta.seconds // 3600
|
||||
return f"{hours} hours" if hours > 1 else "1 hour"
|
||||
|
||||
# Otherwise, return days
|
||||
return f"{delta.days} days" if delta.days > 1 else "1 day"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user