Skip to content

Commit

Permalink
Add termination timestamp and interval timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
shloka-bhalgat-unskript committed Apr 12, 2024
1 parent 652a23b commit 36e8bf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def k8s_get_oomkilled_pods_printer(output):
if output is None:
return
pprint.pprint(output)

def format_datetime(dt):
# Format datetime to a string 'YYYY-MM-DD HH:MM:SS UTC'
return dt.strftime('%Y-%m-%d %H:%M:%S UTC')


def k8s_get_oomkilled_pods(handle, namespace: str = "", time_interval_to_check=24) -> Tuple:
Expand Down Expand Up @@ -98,7 +102,7 @@ def k8s_get_oomkilled_pods(handle, namespace: str = "", time_interval_to_check=2
# If termination time is greater than interval_time_to_check meaning
# the POD has gotten OOMKilled in the last 24 hours, so lets flag it!
if termination_time and termination_time >= interval_time_to_check:
result.append({"pod": pod_name, "namespace": namespace, "container": container_name})
result.append({"pod": pod_name, "namespace": namespace, "container": container_name, "termination_time":termination_time,"interval_time_to_check": interval_time_to_check})

return (False, result) if result else (True, None)

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def k8s_get_pods_with_high_restart_printer(output):

print(output)

def format_datetime(dt):
# Format datetime to a string 'YYYY-MM-DD HH:MM:SS UTC'
return dt.strftime('%Y-%m-%d %H:%M:%S UTC')

def k8s_get_pods_with_high_restart(handle, namespace: str = '', threshold: int = 25) -> Tuple:
"""k8s_get_pods_with_high_restart This function finds out PODS that have
high restart count and returns them as a list of dictionaries
Expand Down Expand Up @@ -81,6 +85,8 @@ def k8s_get_pods_with_high_restart(handle, namespace: str = '', threshold: int =
# We compare if the termination time is within the last 24 hours, if yes
# then we need to add it to the retval and return the list back
if termination_time and termination_time >= interval_time_to_check:
retval.append({'name': pod.metadata.name, 'namespace': pod.metadata.namespace})
formatted_termination_time = format_datetime(termination_time)
formatted_interval_time_to_check = format_datetime(interval_time_to_check)
retval.append({"pod": pod.metadata.name, "namespace": pod.metadata.namespace, "termination_time":formatted_termination_time,"interval_time_to_check": formatted_interval_time_to_check})

return (False, retval) if retval else (True, None)

0 comments on commit 36e8bf6

Please sign in to comment.