Commit 19408133 by Nagy Gergő

Refactored config file parser and client

parent c5cc5350
......@@ -14,11 +14,11 @@ def main():
""")
if (len(sys.argv)==2 and sys.argv[1]=="run"):
configuration = cnfparse.importConf("config/client.conf")
configuration, metrics = cnfparse.importConf("config/client.conf")
cli = client.Client(configuration)
cli.startReporting(metricCollectors =
collectables.collectables.provideAll())
cli.startReporting(metricCollectors =
collectables.collectables.provide(metrics))
if __name__ == "__main__":
main()
......@@ -5,6 +5,7 @@ def importConf(path_to_file):
try:
config.read(path_to_file)
params = {}
metrics = {}
params["frequency"] = config.get("Client" , "Frequency")
params["debugMode"] = config.get("Client" , "Debug")
params["server_address"] = config.get("Server" , "Address")
......@@ -12,13 +13,13 @@ def importConf(path_to_file):
params["amqp_queue"] = config.get("AMQP" , "Queue")
params["amqp_user"] = config.get("AMQP" , "User")
params["amqp_pass"] = config.get("AMQP" , "Pass")
params["cpu.usage"] = config.get("Metrics", "cpuUsage")
params["memory.usage"] = config.get("Metrics", "memoryUsage")
params["user.count"] = config.get("Metrics", "userCount")
params["swap.usage"] = config.get("Metrics", "swapUsage")
params["system.boot_time"]= config.get("Metrics", "systemBootTime")
params["package.traffic"] = config.get("Metrics", "packageTraffic")
params["data.traffic"] = config.get("Metrics", "dataTraffic")
metrics["cpu.usage"] = config.get("Metrics", "cpuUsage")
metrics["memory.usage"] = config.get("Metrics", "memoryUsage")
metrics["user.count"] = config.get("Metrics", "userCount")
metrics["swap.usage"] = config.get("Metrics", "swapUsage")
metrics["system.boot_time"]= config.get("Metrics", "systemBootTime")
metrics["package.traffic"] = config.get("Metrics", "packageTraffic")
metrics["data.traffic"] = config.get("Metrics", "dataTraffic")
except configparser.NoSectionError:
print("Config file contains error! Reason: Missing section.")
raise
......@@ -29,6 +30,6 @@ def importConf(path_to_file):
print("Config file contains error! Reason: Missing section-header.")
raise
return params
return params, metrics
from metrics import *
class collectables:
class collectables:
__collectables = {
std.cpu.usage.name: [std.cpu.usage],
std.memory.usage.name: [std.memory.usage],
std.user.count.name: [std.user.count],
std.network.packages_sent.name: [std.network.packages_sent],
std.network.packages_received.name: [std.network.packages_received],
std.network.bytes_sent.name: [std.network.bytes_sent],
......@@ -27,10 +28,12 @@ class collectables:
def listMetricsNameToKey(key):
return [x.name for x in collectables.__collectables[key]]
@staticmethod
@staticmethod
def provide(requests = []):
valid_keys = collectables.listKeys()
reqs = [request for request, value in requests.items() if value=="True"]
collectors = []
for request in requests:
for request in reqs:
for item in collectables.__collectables[request]:
collectors.append(item.harvest)
seen = set()
......
......@@ -51,10 +51,10 @@ class std (Collection):
class user (Collection.Group):
class count (Collection.Group.Metric):
name = "user.count"
@staticmethod
def harvest():
return Metrics("user.count", len(ps.get_users()))
return Metrics(std.user.count.name, len(ps.get_users()))
class network (Collection.Group):
......
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