update(k8s): add granularity
This commit is contained in:
@@ -68,15 +68,24 @@ def fetch_k8s_data_with_usage():
|
|||||||
|
|
||||||
def calculate_time_on_duty(creation_timestamp):
|
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)
|
now = datetime.now(timezone.utc)
|
||||||
delta = now - creation_timestamp
|
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:
|
if delta.days < 1:
|
||||||
return f"{delta.seconds // 3600} hours"
|
hours = delta.seconds // 3600
|
||||||
return f"{delta.days} days"
|
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):
|
def convert_memory_to_gb(memory):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user