Commit c9e70b85 by root

3.2 python

parent dc85b3c1
...@@ -14,8 +14,8 @@ Pass = guest ...@@ -14,8 +14,8 @@ Pass = guest
[Metrics] [Metrics]
cpuUsage = True cpuUsage = True
memoryUsage = True memoryUsage = True
userCount = True userCount = False
swapUsage = True swapUsage = False
systemBootTime = False systemBootTime = False
packageTraffic = False packageTraffic = False
dataTraffic = False dataTraffic = False
No preview for this file type
...@@ -12,8 +12,8 @@ class Client: ...@@ -12,8 +12,8 @@ class Client:
modul. It is a dictionary: {server_address, server_port, frequency, modul. It is a dictionary: {server_address, server_port, frequency,
debugMode, amqp_user, amqp_pass, amqp_queue}. debugMode, amqp_user, amqp_pass, amqp_queue}.
""" """
hostname = socket.gethostname().split('.') hostname = socket.gethostname().split('.')
hostname.reverse() hostname.reverse()
self.name = "circle." + ".".join(hostname) self.name = "circle." + ".".join(hostname)
self.server_address = str(config["server_address"]) self.server_address = str(config["server_address"])
self.server_port = int(config["server_port"]) self.server_port = int(config["server_port"])
...@@ -30,7 +30,7 @@ class Client: ...@@ -30,7 +30,7 @@ class Client:
""" """
try: try:
credentials = pika.PlainCredentials(self.amqp_user, self.amqp_pass) credentials = pika.PlainCredentials(self.amqp_user, self.amqp_pass)
self.connection = pika.BlockingConnection(pika.ConnectionParameters( self.connection = pika.BlockingConnection(pika.ConnectionParameters(
host=self.server_address, host=self.server_address,
port=self.server_port, port=self.server_port,
credentials=credentials credentials=credentials
...@@ -39,7 +39,7 @@ class Client: ...@@ -39,7 +39,7 @@ class Client:
self.channel = self.connection.channel() self.channel = self.connection.channel()
return True return True
except: except:
raise raise
def __disconnect(self): def __disconnect(self):
""" """
...@@ -95,5 +95,3 @@ class Client: ...@@ -95,5 +95,3 @@ class Client:
print("Reporting has stopped by the user. Exiting...") print("Reporting has stopped by the user. Exiting...")
finally: finally:
self.__disconnect() self.__disconnect()
No preview for this file type
import ConfigParser as configparser import configparser
def importConf(path_to_file): def importConf(path_to_file):
config = configparser.RawConfigParser(allow_no_value = False) config = configparser.RawConfigParser(allow_no_value = False)
......
No preview for this file type
No preview for this file type
...@@ -16,16 +16,17 @@ class Collection (object): ...@@ -16,16 +16,17 @@ class Collection (object):
@classmethod @classmethod
def harvest(cls): def harvest(cls):
print(cls.collector_function_arguments)
query = cls.collector_function(**cls.collector_function_arguments) query = cls.collector_function(**cls.collector_function_arguments)
if ((isinstance(query, list)) or (isinstance(query, dict))): if ((isinstance(query, list)) or (isinstance(query, dict))):
return Metrics(cls.name, return Metrics(name,
query[cls.collector_function_result_attr]) query[cls.collector_function_result_attr])
elif (isinstance(query,tuple)): elif (isinstance(query,tuple)):
return Metrics(cls.name, return Metrics(name,
query.__getattribute__(cls.collector_function_result_attr)) query.__getattribute__(cls.collector_function_result_attr))
else: else:
return Metrics(cls.name, return Metrics(cls.name,
query) query)
#################################################################################### ####################################################################################
...@@ -36,7 +37,7 @@ class std (Collection): ...@@ -36,7 +37,7 @@ class std (Collection):
class usage (Collection.Group.Metric): class usage (Collection.Group.Metric):
collector_function = ps.cpu_percent collector_function = ps.cpu_percent
collector_function_arguments = { collector_function_arguments = {
'interval': 0, 'interval': 0.0,
} }
name = "cpu.usage" name = "cpu.usage"
...@@ -52,9 +53,9 @@ class std (Collection): ...@@ -52,9 +53,9 @@ class std (Collection):
class count (Collection.Group.Metric): class count (Collection.Group.Metric):
name = "user.count" name = "user.count"
@staticmethod @classmethod
def harvest(): def harvest(cls):
return Metrics(std.user.count.name, len(ps.get_users())) return Metrics(cls.name, len(ps.get_users()))
class network (Collection.Group): class network (Collection.Group):
......
No preview for this file type
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