Commit dd5f6fc0 by Gregory Nagy

flake8 and synchronized memory reporter function (celery collector)

parent 0a10962e
......@@ -208,6 +208,7 @@ class Client:
"." + "network.packages_sent" +
" %d" % interfaces_list[
iname].packets_sent
+ "." + iname
+ " %d" % (time.time())
))
metrics.append(("vm." +
......@@ -215,6 +216,7 @@ class Client:
"." + "network.packages_recv" +
" %d" % interfaces_list[
iname].packets_recv
+ "." + iname
+ " %d" % (time.time())
))
metrics.append(("vm." +
......@@ -222,6 +224,7 @@ class Client:
".bytes_sent" +
" %d" % interfaces_list[
iname].bytes_sent
+ "." + iname
+ " %d" % (time.time())
))
metrics.append(("vm." +
......@@ -229,6 +232,7 @@ class Client:
".bytes_recv" +
" %d" % interfaces_list[
iname].bytes_recv
+ "." + iname
+ " %d" % (time.time())
))
return metrics
......
......@@ -2,30 +2,30 @@ import ConfigParser as configparser
def importConf(path_to_file):
config = configparser.RawConfigParser(allow_no_value=False)
try:
config.read(path_to_file)
params = {}
metrics = {}
params["debugMode"] = config.get("Client", "Debug")
metrics["cpu.usage"] = int(config.get("Metrics", "cpuUsage"))
metrics["memory.usage"] = int(config.get("Metrics", "memoryUsage"))
metrics["user.count"] = int(config.get("Metrics", "userCount"))
metrics["swap.usage"] = int(config.get("Metrics", "swapUsage"))
metrics["system.boot_time"] = int(config.get("Metrics",
"systemBootTime"))
metrics["network"] = int(config.get("Metrics", "dataTraffic"))
params["kvmCpuUsage"] = int(config.get("KVM", "cpuUsage"))
params["kvmMemoryUsage"] = int(config.get("KVM", "memoryUsage"))
params["kvmNetworkUsage"] = int(config.get("KVM", "networkUsage"))
except configparser.NoSectionError:
print("Config file contains error! Reason: Missing section.")
raise
except configparser.ParsingError:
print("Config file contains error! Reason: Cannot parse.")
raise
except configparser.MissingSectionHeaderError:
print("Config file contains error! Reason: Missing section-header.")
raise
config = configparser.RawConfigParser(allow_no_value=False)
try:
config.read(path_to_file)
params = {}
metrics = {}
params["debugMode"] = config.get("Client", "Debug")
metrics["cpu.usage"] = int(config.get("Metrics", "cpuUsage"))
metrics["memory.usage"] = int(config.get("Metrics", "memoryUsage"))
metrics["user.count"] = int(config.get("Metrics", "userCount"))
metrics["swap.usage"] = int(config.get("Metrics", "swapUsage"))
metrics["system.boot_time"] = int(config.get("Metrics",
"systemBootTime"))
metrics["network"] = int(config.get("Metrics", "dataTraffic"))
params["kvmCpuUsage"] = int(config.get("KVM", "cpuUsage"))
params["kvmMemoryUsage"] = int(config.get("KVM", "memoryUsage"))
params["kvmNetworkUsage"] = int(config.get("KVM", "networkUsage"))
except configparser.NoSectionError:
print("Config file contains error! Reason: Missing section.")
raise
except configparser.ParsingError:
print("Config file contains error! Reason: Cannot parse.")
raise
except configparser.MissingSectionHeaderError:
print("Config file contains error! Reason: Missing section-header.")
raise
return params, metrics
return params, metrics
......@@ -2,45 +2,45 @@ from metrics import *
class collectables:
__collectables = {
std.cpu.usage.name: [std.cpu.usage],
std.memory.usage.name: [std.memory.usage],
std.swap.usage.name: [std.swap.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],
std.network.bytes_received.name: [std.network.bytes_received],
std.system.boot_time.name: [std.system.boot_time],
"network": [std.network.bytes_sent, std.network.bytes_received,
std.network.packages_sent, std.network.packages_received],
}
__collectables = {
std.cpu.usage.name: [std.cpu.usage],
std.memory.usage.name: [std.memory.usage],
std.swap.usage.name: [std.swap.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],
std.network.bytes_received.name: [std.network.bytes_received],
std.system.boot_time.name: [std.system.boot_time],
"network": [std.network.bytes_sent, std.network.bytes_received,
std.network.packages_sent, std.network.packages_received],
}
@staticmethod
def listKeys():
return list(collectables.__collectables.keys())
@staticmethod
def listKeys():
return list(collectables.__collectables.keys())
@staticmethod
def listMetricsToKey(key):
return collectables.__collectables[key]
@staticmethod
def listMetricsToKey(key):
return collectables.__collectables[key]
@staticmethod
def listMetricsNameToKey(key):
return [x.name for x in collectables.__collectables[key]]
@staticmethod
def listMetricsNameToKey(key):
return [x.name for x in collectables.__collectables[key]]
@staticmethod
def provide(requests=[]):
#valid_keys = collectables.listKeys()
reqs = []
for requests, value in requests.items():
if value > 0:
reqs.append([requests, value])
collectors = []
for request in reqs:
for item in collectables.__collectables[request[0]]:
collectors.append([item.harvest, request[1]])
return collectors
@staticmethod
def provide(requests=[]):
#valid_keys = collectables.listKeys()
reqs = []
for requests, value in requests.items():
if value > 0:
reqs.append([requests, value])
collectors = []
for request in reqs:
for item in collectables.__collectables[request[0]]:
collectors.append([item.harvest, request[1]])
return collectors
@staticmethod
def provideAll():
return collectables.provide(collectables.listKeys())
@staticmethod
def provideAll():
return collectables.provide(collectables.listKeys())
......@@ -9,7 +9,9 @@ Metrics = collections.namedtuple("Metrics", ["name", "value"])
class Collection(object):
class Group(object):
class Metric(object):
name = "unknown"
collector_function = 0
......@@ -19,14 +21,14 @@ class Collection(object):
@classmethod
def harvest(cls):
query = cls.collector_function.im_func(
**cls.collector_function_arguments)
**cls.collector_function_arguments)
if ((isinstance(query, list)) or (isinstance(query, dict))):
return Metrics(cls.name,
query[cls.collector_function_result_attr])
elif (isinstance(query, tuple)):
return Metrics(cls.name,
query.__getattribute__(
cls.collector_function_result_attr))
cls.collector_function_result_attr))
else:
return Metrics(cls.name, query)
......@@ -34,18 +36,21 @@ class Collection(object):
class std(Collection):
class cpu(Collection.Group):
class usage(Collection.Group.Metric):
name = "cpu.usage"
collector_function = ps.cpu_percent
collector_function_arguments = {
'interval': 0.0,
'interval': 0.0,
}
class memory(Collection.Group):
class usage(Collection.Group.Metric):
name = "memory.usage"
collector_function = ps.virtmem_usage
collector_function = ps.virtual_memory
collector_function_result_attr = "percent"
class swap(Collection.Group):
......@@ -86,4 +91,4 @@ class std(Collection):
class system(Collection.Group):
class boot_time(Collection.Group.Metric):
name = "system.boot_time"
collector_function = ps.get_boot_time
\ No newline at end of file
collector_function = ps.get_boot_time
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