Created
September 8, 2017 12:30
-
-
Save celebdor/68ba2191b99ae109d284a95fc99f433d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import datetime | |
import sys | |
from kubernetes import client, config | |
config.load_kube_config() | |
v1 = client.CoreV1Api() | |
try: | |
namespace = sys.argv[1] | |
except IndexError: | |
namespace = 'default' | |
ret = v1.list_namespaced_pod(namespace=namespace) | |
print '"Pod name","Pod creation","Pod running"' | |
creation_data = [] | |
creation_count = 0 | |
running_data = [] | |
for i in ret.items: | |
creation_data.append(i.metadata.creation_timestamp) | |
running_data.append(i.status.container_statuses[0].state.running.started_at) | |
creation_data.sort() | |
running_data.sort() | |
if len(sys.argv) == 3 and sys.argv[2] == 'time_relative': | |
epoch = creation_data[0] | |
else: | |
from dateutil.parser import parse | |
epoch = parse("1970-01-01 00:00:00+00:00") | |
created = 0 | |
composed_data = {} | |
print '"epoch","cumulative created"' | |
for creation_time in creation_data: | |
created += 1 | |
seconds = (creation_time - epoch).total_seconds() | |
composed_data[created] = [seconds] | |
print '"%s","%s"' % (seconds, created) | |
running = 0 | |
print '"epoch","cumulative running"' | |
for running_start_time in running_data: | |
running += 1 | |
seconds = (running_start_time - epoch).total_seconds() | |
composed_data[running].append(seconds) | |
print '"%s","%s"' % (seconds, running) | |
print '"cumulative pods","API creation time","API Pod running time"' | |
for pods, seconds in composed_data.items(): | |
print '"%s","%s","%s"' % (pods, seconds[0], seconds[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment