Commit 743a2c72 by Gregory Nagy

Added collection from running kvm processes

parent 34d2ee59
......@@ -5,7 +5,7 @@
import time
import socket
import pika
# import struct
import psutil
import logging
import os
......@@ -77,7 +77,36 @@ class Client:
+ " %d" % (time.time())
))
return metrics
def __collectFromVMs(self):
metrics = []
running_vms = []
for entry in psutil.get_process_list():
if entry.name in "kvm":
search = [cmd_param_index for cmd_param_index, cmd_param in
enumerate(entry.as_dict()["cmdline"])
if cmd_param == "-name"]
memory = [cmd_param_index for cmd_param_index, cmd_param in
enumerate(entry.as_dict()["cmdline"])
if cmd_param == "-m"]
running_vms.append([entry.as_dict()["cmdline"][search[0]+1],
entry.pid,
int(entry.as_dict()["cmdline"][memory[0]+1])])
for vm in running_vms:
vm_proc = psutil.Process(vm[1])
metrics.append((self.name + "." + "kvm." +
vm[0] + "." + "memory.usage." +
" %d" % (vm_proc.get_memory_percent()/100*vm[2])
+ " %d" % (time.time())
))
metrics.append((self.name + "." + "kvm." +
vm[0] + "." + "cpu.usage" +
" %d" % (vm_proc.get_cpu_times().system +
vm_proc.get_cpu_times().user)
+ " %d" % (time.time())
))
return metrics
def getMaxFrequency(self, metricCollectors=[]):
max = metricCollectors[0][1]
for item in metricCollectors:
......@@ -103,6 +132,7 @@ class Client:
maxFrequency = self.getMaxFrequency(metricCollectors)
while True:
metrics = self.__collectFromNode(metricCollectors)
metrics.append(self.__collectFromVMs())
if self.debugMode == "True":
print(metrics)
self.__send(metrics)
......
......@@ -15,6 +15,8 @@ def importConf(path_to_file):
metrics["system.boot_time"] = int(config.get("Metrics",
"systemBootTime"))
metrics["network"] = int(config.get("Metrics", "dataTraffic"))
metrics["kvmCpuUsage"] = int(config.get("KVM", "cpuUsage"))
metrics["kvmMemoryUsage"] = int(config.get("KVM", "memoryUsage"))
except configparser.NoSectionError:
print("Config file contains error! Reason: Missing section.")
raise
......
......@@ -91,4 +91,4 @@ class std (Collection):
class boot_time (Collection.Group.Metric):
name = "system.boot_time"
collector_function = ps.get_boot_time
collector_function = ps.get_boot_time
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment