Commit 2c5ae1f7 by Gregory Nagy

Client.conf file KVM section added.

client.py pip8 formated
cnfparse.py pip8 formated
collectables.py fixed bug and pip formated
parent 743a2c72
...@@ -9,3 +9,7 @@ swapUsage = 30 ...@@ -9,3 +9,7 @@ swapUsage = 30
systemBootTime = 120 systemBootTime = 120
packageTraffic = 10 packageTraffic = 10
dataTraffic = 10 dataTraffic = 10
[KVM]
cpuUsage =5
memoryUsage = 5
#!/usr/bin/python #!/usr/bin/python
# import platform
# import collections
import time import time
import socket import socket
import pika import pika
...@@ -14,7 +12,6 @@ logging.basicConfig() ...@@ -14,7 +12,6 @@ logging.basicConfig()
class Client: class Client:
def __init__(self, config): def __init__(self, config):
""" """
Constructor of the client requires a configuration provided by cnfparse Constructor of the client requires a configuration provided by cnfparse
...@@ -89,14 +86,14 @@ class Client: ...@@ -89,14 +86,14 @@ class Client:
memory = [cmd_param_index for cmd_param_index, cmd_param in memory = [cmd_param_index for cmd_param_index, cmd_param in
enumerate(entry.as_dict()["cmdline"]) enumerate(entry.as_dict()["cmdline"])
if cmd_param == "-m"] if cmd_param == "-m"]
running_vms.append([entry.as_dict()["cmdline"][search[0]+1], running_vms.append([entry.as_dict()["cmdline"][search[0] + 1],
entry.pid, entry.pid,
int(entry.as_dict()["cmdline"][memory[0]+1])]) int(entry.as_dict()["cmdline"][memory[0] + 1])])
for vm in running_vms: for vm in running_vms:
vm_proc = psutil.Process(vm[1]) vm_proc = psutil.Process(vm[1])
metrics.append((self.name + "." + "kvm." + metrics.append((self.name + "." + "kvm." +
vm[0] + "." + "memory.usage." + vm[0] + "." + "memory.usage." +
" %d" % (vm_proc.get_memory_percent()/100*vm[2]) " %d" % (vm_proc.get_memory_percent() / 100 * vm[2])
+ " %d" % (time.time()) + " %d" % (time.time())
)) ))
metrics.append((self.name + "." + "kvm." + metrics.append((self.name + "." + "kvm." +
......
...@@ -15,8 +15,8 @@ def importConf(path_to_file): ...@@ -15,8 +15,8 @@ def importConf(path_to_file):
metrics["system.boot_time"] = int(config.get("Metrics", metrics["system.boot_time"] = int(config.get("Metrics",
"systemBootTime")) "systemBootTime"))
metrics["network"] = int(config.get("Metrics", "dataTraffic")) metrics["network"] = int(config.get("Metrics", "dataTraffic"))
metrics["kvmCpuUsage"] = int(config.get("KVM", "cpuUsage")) params["kvmCpuUsage"] = int(config.get("KVM", "cpuUsage"))
metrics["kvmMemoryUsage"] = int(config.get("KVM", "memoryUsage")) params["kvmMemoryUsage"] = int(config.get("KVM", "memoryUsage"))
except configparser.NoSectionError: except configparser.NoSectionError:
print("Config file contains error! Reason: Missing section.") print("Config file contains error! Reason: Missing section.")
raise raise
......
...@@ -2,7 +2,6 @@ from metrics import * ...@@ -2,7 +2,6 @@ from metrics import *
class collectables: class collectables:
__collectables = { __collectables = {
std.cpu.usage.name: [std.cpu.usage], std.cpu.usage.name: [std.cpu.usage],
std.memory.usage.name: [std.memory.usage], std.memory.usage.name: [std.memory.usage],
...@@ -34,7 +33,7 @@ class collectables: ...@@ -34,7 +33,7 @@ class collectables:
#valid_keys = collectables.listKeys() #valid_keys = collectables.listKeys()
reqs = [] reqs = []
for requests, value in requests.items(): for requests, value in requests.items():
if value>0: if value > 0:
reqs.append([requests, value]) reqs.append([requests, value])
collectors = [] collectors = []
for request in reqs: for request in reqs:
......
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