-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-collector.py
More file actions
62 lines (52 loc) · 1.76 KB
/
docker-collector.py
File metadata and controls
62 lines (52 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from pymongo import MongoClient
import pymongo
from pprint import pprint as pp
import time
key_names = (
('name','containerName'),
('created','containerCreated'),
('ports','containerPorts'),
('state','containerState'),
('externalId','containerId'),
('imageUuid','containerImage'))
def adjust_key_names(d):
if not isinstance(d,dict):
raise TypeError
for native_name,req_name in key_names:
d[req_name] = d.pop(native_name)
mongocli = MongoClient(host = 'mopbz171199.fr.dst.ibm.com')
DB = mongocli.get_database('docker-beta_cloud_dst_ibm_com:8080')
last_collection_date = DB.last_ts.find().next()
ts = last_collection_date['value']
def get_collection_dates():
collection_dates = DB.collection_dates.find({},{'checkdate':1})
return collection_dates
def get_environments():
environments = DB.environments.find({'ts':ts},{'name':1,'description':1})
return environments
def get_stacks():
stacks = DB.stacks.find({'ts':ts},{'name':1,'description':1})
return stacks
def get_services():
services = DB.services.find({'ts':ts},{'name':1,'state':1})
return services
def get_containers():
#containers = DB.containers.find()
containers = DB.containers.find({'ts':ts})
return containers
def get_dockerhosts():
dockerhosts = DB.dockerhosts.find_one()['values']
return dockerhosts
if __name__ == '__main__':
for container in get_containers():
adjust_key_names(container)
#pp(container)
name = container['containerName']
state = container['containerState']
host = container['containerHost']
if state == 'running':
#print name,state,host
a,b = host.split('/')
x = eval(b)
print name,a,x[0]
print "*" * 20