-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdocker_collectmetrics.py
44 lines (33 loc) · 1.06 KB
/
docker_collectmetrics.py
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
import os, sys
import docker
class ContainerUtil:
def __init__(self, **kwargs):
self.client = kwargs["client"]
self.component = kwargs["component"]
self.instname = kwargs["instance_name"]
@property
def container(self):
return self._get_container()
def _get_container(self):
try:
container = [c for c in self.client.containers.list(
filters={
'label': 'org.geonode.component={0}'.format(self.component),
'status': 'running'
}
) if '{0}'.format(self.instname) in c.name][0]
except:
raise
return container
def main():
c = docker.from_env()
command = "{}".format("/usr/local/bin/invoke collectmetrics")
django = ContainerUtil(
client=c,
component="django",
instance_name=os.getenv('GEONODE_INSTANCE_NAME', 'starterkit')
).container
out = django.exec_run(cmd=command, tty=True)
print(out)
if __name__ == '__main__':
main()