Commit 8f97d50c by Nagy Gergő

Revert "Critical values loaded from environmental variables. Added frequency setup to config file."

This reverts commit 5b1fdf66.
parent 5b1fdf66
[Client]
Frequency = 5
Debug = True
[Server]
Address = 10.7.0.96
Port = 5672
[AMQP]
Queue = monitor
User = cloud
Pass = password
Vhost = monitor
[Metrics]
cpuUsage = 5
memoryUsage = 5
userCount = 30
swapUsage = 10
systemBootTime = 60
packageTraffic = 5
dataTraffic = 5
cpuUsage = True
memoryUsage = True
userCount = True
swapUsage = True
systemBootTime = True
packageTraffic = True
dataTraffic = True
#!/usr/bin/python
import platform, collections, time, socket, pika, struct, os
import platform, collections, time, socket, pika, struct
import logging
logging.basicConfig()
......@@ -8,18 +8,21 @@ class Client:
def __init__(self, config):
"""
Constructor of the client requires a configuration provided by cnfparse
modul. It is a dictionary: {server_address, server_port, frequency,
debugMode, amqp_user, amqp_pass, amqp_queue}.
"""
hostname = socket.gethostname().split('.')
hostname.reverse()
self.name = "circle." + ".".join(hostname)
self.server_address = str(os.getenv("GRAPHITE_SERVER_ADDRESS"))
self.server_port = int(os.getenv("GRAPHITE_SERVER_PORT"))
self.amqp_user = str(os.getenv("AMQP_USER"))
self.amqp_pass = str(os.getenv("AMQP_PASS"))
self.amqp_queue = str(os.getenv("AMQP_QUEUE"))
self.amqp_virtual_host = str(os.getenv("AMQP_VIRTUAL_HOST"))
self.beat = 1
self.server_address = str(config["server_address"])
self.server_port = int(config["server_port"])
self.delay = int(config["frequency"])
self.debugMode = config["debugMode"]
self.amqp_user = str(config["amqp_user"])
self.amqp_pass = str(config["amqp_pass"])
self.amqp_queue = str(config["amqp_queue"])
self.amqp_virtual_host = str(config["amqp_virtual_host"])
def __connect(self):
"""
......@@ -61,21 +64,13 @@ class Client:
"""
metrics = []
for collector in metricCollectors:
if (collector[1] % self.beat) is 0:
stat = collector[0]()
metrics.append((
stat = collector()
metrics.append((
self.name + "." + stat.name +
" %d" % (stat.value) +
" %d" % (time.time())
))
))
return metrics
def __getMaxBeat(self, metricCollectors = []):
max = 0
for item in metricCollectors:
if max < item[1]:
max = item[1]
return max
def startReporting(self, metricCollectors = [], debugMode = False):
"""
......@@ -92,16 +87,12 @@ class Client:
(self.server_address, self.server_port, self.delay, self.name)
)
try:
max_beat = self.__getMaxBeat(metricCollectors)
while True:
metrics = self.__collectFromNode(metricCollectors)
if self.debugMode == "True":
print(metrics)
self.__send(metrics)
time.sleep(1)
self.beat++
if self.beat > max_beat:
self.beat = 1
time.sleep(self.delay)
except KeyboardInterrupt:
print("Reporting has stopped by the user. Exiting...")
finally:
......
......@@ -6,7 +6,14 @@ def importConf(path_to_file):
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")
params["server_port"] = config.get("Server" , "Port")
params["amqp_queue"] = config.get("AMQP" , "Queue")
params["amqp_user"] = config.get("AMQP" , "User")
params["amqp_pass"] = config.get("AMQP" , "Pass")
params["amqp_virtual_host"] = config.get("AMQP" , "Vhost")
metrics["cpu.usage"] = config.get("Metrics", "cpuUsage")
metrics["memory.usage"] = config.get("Metrics", "memoryUsage")
metrics["user.count"] = config.get("Metrics", "userCount")
......
......@@ -33,11 +33,11 @@ class collectables:
@staticmethod
def provide(requests = []):
valid_keys = collectables.listKeys()
reqs = [request for request, value in requests.items() if int(value)>0]
reqs = [request for request, value in requests.items() if value=="True"]
collectors = []
for request in reqs:
for item in collectables.__collectables[request]:
collectors.append([item.harvest,value])
collectors.append(item.harvest)
seen = set()
seen_add = seen.add
return [ x for x in collectors if x not in seen and not seen_add(x)]
......
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