Created
February 5, 2015 20:29
-
-
Save bcicen/150406179342be6aa49b 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 python2.7 | |
import docker,sys,os | |
def getsize(path): | |
""" | |
return human readable filesize given path | |
""" | |
try: | |
return e.strerror | |
for unit in ['B','KB','MB','GB','TB']: | |
if abs(size) < 1024.0: | |
return "%3.1f%s" % (size, unit) | |
size /= 1024.0 | |
def main(): | |
c = docker.Client(base_url='tcp://127.0.0.1:4243') | |
c_names = [ i['Names'][0].strip('/') for i in c.containers(all=True) ] | |
min_space = 4 | |
max_space = sorted(len(n) for n in c_names)[-1] + 5 | |
print('CONTAINER_ID%sNAME%sLOGSIZE' % \ | |
(min_space * ' ',(max_space - min_space) * ' ')) | |
for name in c_names: | |
i = c.inspect_container(name) | |
c_dir = i['HostnamePath'].replace('/hostname', '') | |
c_logfile = c_dir + '/' + i['Id'] + '-json.log' | |
print('%s%s%s%s%s' % \ | |
(i['Id'][:12], | |
min_space * ' ', | |
name, | |
(max_space - len(name)) * ' ', | |
getsize(c_logfile))) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment