update(k8s): add granularity

This commit is contained in:
Aleksandr Tcitlionok
2024-12-06 03:51:48 +00:00
parent 22ea154c19
commit 955d7d3e55

View File

@@ -68,15 +68,24 @@ def fetch_k8s_data_with_usage():
def calculate_time_on_duty(creation_timestamp):
"""
Calculate the time on duty in hours or days from the creation timestamp.
Calculate the time on duty in hours, days, or minutes from the creation timestamp.
"""
now = datetime.now(timezone.utc)
delta = now - creation_timestamp
# If less than a day, return hours; otherwise, return days
# 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:
return f"{delta.seconds // 3600} hours"
return f"{delta.days} days"
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"
def convert_memory_to_gb(memory):
"""