agent/cloud_node_statistics.py

33 lines
897 B
Python
Raw Permalink Normal View History

2016-05-07 18:29:28 +03:00
#!/usr/bin/env python
# coding: utf-8
2015-12-14 05:02:08 +03:00
2016-10-09 22:59:21 +03:00
from SWSCloudNode import Node, StatisticsReporter
from SWSCloudNode import LXC
from SWSCloudNode import Qemu
from SWSCloudNode import QemuStats
2015-12-14 05:02:08 +03:00
2016-10-09 22:59:21 +03:00
cls_lxc = LXC()
cls_qemu = Qemu()
2016-04-20 03:39:25 +03:00
cls_node = Node()
2015-12-14 05:02:08 +03:00
2016-10-12 03:19:11 +03:00
for container in cls_lxc.list_containers():
2015-12-14 05:02:08 +03:00
# print container
2016-04-20 03:39:25 +03:00
info = cls_lxc.info(container)
2015-12-14 05:02:08 +03:00
info['container_id'] = info['name']
2016-10-12 23:34:07 +03:00
print (cls_node.report_container_stats(info['container_id'], info))
2015-12-14 05:02:08 +03:00
# print info
2016-10-09 22:59:21 +03:00
"""
curl localhost:8089/node_stats/v1/compute/vms/04ea5600-89c6-11e6-b1e1-fb8145d56ed7 -X POST --header 'Content-Type: application/json'
"""
vms = cls_qemu.list().get('online')
for vm in vms:
dom = vms.get(vm).get('hostname')
data = dict(
2016-10-13 04:12:29 +03:00
network=QemuStats().network(dom),
2016-10-09 22:59:21 +03:00
cpu=QemuStats().cpu(dom),
memory=QemuStats().memory(dom))
2016-10-12 23:34:07 +03:00
print (StatisticsReporter().send_vm_statistics(dom, data))