2015-04-05 18:02:36 +00:00
|
|
|
from orchestra.contrib.orchestration import replace
|
2015-04-05 10:46:24 +00:00
|
|
|
from orchestra.contrib.resources import ServiceMonitor
|
2014-07-09 16:17:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OpenVZTraffic(ServiceMonitor):
|
2015-04-23 19:46:23 +00:00
|
|
|
"""
|
|
|
|
WARNING: Not fully implemeted
|
|
|
|
"""
|
2014-07-09 16:17:43 +00:00
|
|
|
model = 'vps.VPS'
|
|
|
|
resource = ServiceMonitor.TRAFFIC
|
2014-07-14 14:56:48 +00:00
|
|
|
|
2014-07-16 15:20:16 +00:00
|
|
|
def process(self, line):
|
2014-07-14 14:56:48 +00:00
|
|
|
""" diff with last stored value """
|
|
|
|
object_id, value = line.split()
|
|
|
|
last = self.get_last_data(object_id)
|
|
|
|
if not last or last.value > value:
|
|
|
|
return object_id, value
|
|
|
|
return object_id, value-last.value
|
|
|
|
|
|
|
|
def monitor(self, container):
|
|
|
|
""" Get OpenVZ container traffic on a Proxmox +2.0 cluster """
|
|
|
|
context = self.get_context(container)
|
|
|
|
self.append(
|
|
|
|
"CONF=$(grep -r 'HOSTNAME=\"%(hostname)s\"' /etc/pve/nodes/*/openvz/*.conf)" % context)
|
|
|
|
self.append('NODE=$(echo "${CONF}" | cut -d"/" -f5)')
|
|
|
|
self.append('CTID=$(echo "${CONF}" | cut -d"/" -f7 | cur -d"\." -f1)')
|
|
|
|
self.append(
|
|
|
|
"ssh root@${NODE} vzctl exec ${CTID} cat /proc/net/dev \\\n"
|
|
|
|
" | grep venet0 \\\n"
|
|
|
|
" | awk -F: '{print $2}' \\\n"
|
|
|
|
" | awk '{print $1+$9}'")
|
|
|
|
|
|
|
|
def get_context(self, container):
|
2015-04-05 18:02:36 +00:00
|
|
|
context = {
|
2014-07-14 14:56:48 +00:00
|
|
|
'hostname': container.hostname,
|
|
|
|
}
|
2015-04-05 18:02:36 +00:00
|
|
|
return replace(context, "'", '"')
|