def start(): di.get("Logger").info("Starting Client..") client = Client() reporter = Reporter() exm = Exms() threads = [] x = threading.Thread(target=client.loop, args=()) threads.append(x) x2 = threading.Thread(target=reporter.loop, args=()) threads.append(x2) for thread in exm.loop(): t = threading.Thread(target=thread.start, args=()) t.start() threads.append(t) # print(exm.loop()) di.get("Logger").info("Main : before running thread") x.start() x2.start() # x3.start() import time print(threads) while True: time.sleep(1)
def main(): # Log Sentinel and PSutil version di.get("Logger").info('Start Sentinel {}'.format(__version__)) di.get("Logger").info('{} {} and PSutil {} detected'.format( platform.python_implementation(), platform.python_version(), psutil_version)) #config = core.get_config() #args = core.get_args() # Catch the CTRL-C signal signal.signal(signal.SIGINT, __signal_handler) start() #(config=config, args=args)
def __init__(self, *args, **kwargs): self._logger = di.get("Logger") self.check_time = int(config.checks.freq) self.report_time = int(config.reporting.freq) self.sched_checks = sched.scheduler(timefunc=time.time, delayfunc=time.sleep) self.sched_reports = sched.scheduler(timefunc=time.time, delayfunc=time.sleep) self.monitors = Monitors()
def report_now(self, *args, **kwargs): """ Abstract class that needs to be implemented in all Monitors :param args: Optional list of Monitors to update :param kwargs: Optional list of KeyWord args :return: List of stats from all updated monitors """ self.reports = [] logger.info("Do something before real update") # IF no args then update all update behaviours in list if not args: for (classname, instance) in three2two.iteritems(self.monitor): # Return data from monitor (classname) stat = instance.report(*args, **kwargs) logger.info( "Do something with THIS update metrics for monitor {}". format(classname)) # This is now a list of dicts, probably not OK, need dict self.reports.append(stat) # We have args and only update those behaviours else: for inst in args: cname = inst.__class__.__name__ if cname in self.monitor: stat = inst.report(**kwargs) logger.info( "Do something with THIS update metrics for monitor {}" ).format(cname) # This is now a list of dicts, probably not OK, need dict self.reports.append(stat) logger.info("Do something with all update metrics") for adict in self.reports: di.get("Reporter").send_data(adict) return self.reports
Features: - A simple to use API for scheduling jobs. - Very lightweight and no external dependencies. - Excellent test coverage. - Works with Python 2.7 and 3.3 """ import collections import datetime import functools import random import time from src import di logger = di.get("Logger") class CancelJob(object): """ Can be returned from a job to unschedule itself. """ pass class Scheduler(object): """ Objects instantiated by the :class:`Scheduler <Scheduler>` are factories to create jobs, keep record of scheduled jobs and handle their execution. """
def __init__(self, *args, **kwargs): self.logger = di.get("Logger") self.queue = di.get("Queue") print("OracleExm Inited")
def __call__(self, *args, **kwargs): self.logger = di.get("Logger") self.queue = di.get("Queue")
# -*- coding: utf-8 -*- # Filename: report_rest by: andrek # Timesamp:2020-04-04 :: 11:07 using PyCharm import json from src.utils.paho.mqtt.publish import single import pulsar from src.core.interfaces.reportinterface import ReportInterface from src import config, di logger = di.get('Logger') # MQTT Settings MQTT_Broker = "127.0.0.1" MQTT_Port = 1883 Keep_Alive_Interval = 45 MQTT_Topic = "dummy" DEBUG = True class MqttReporter(ReportInterface): class Mqtt: @classmethod def publish_To_Topic(cls, topic, message, log=None): try: # pub = cls.mqttc.publish(topic, message, auth)
def __init__(self): # Might use call here di.get("Logger").debug("Loading available reports") self.header = 'report_' self.load_reports() self.queue = di.get("Queue")
def process_queue(self): while True: time.sleep(0.5) for msg in self.queue_messages(di.get("Queue")): self.send_data(msg)
# -*- coding: utf-8 -*- # Filename: metric_cpu by: andrek # Timesamp:2018-11-04 :: 12:04 using PyCharm import collections import os from src.utils.chronometer import getTimeSinceLastUpdate from src.core.interfaces.updateinterface import UpdateInterface from src import config from src.utils.three2two import iteritems from src import di logger = di.get("Logger") cpumeter = di.get("CpuMeter") import psutil class CpuUpdate(UpdateInterface): """TenForward CPU plugin. 'stats' is a dictionary that contains the system-wide CPU utilization as a percentage. """ ''' Default Alert levels custom made levels can be set from GUI Possible LEVELS are FATAL, CRITICAL, ERROR, WARNING, INFO ''' ALERT_LEVELS = {'total': {'CRITICAL': 90, 'WARNING': 75}}
def __signal_handler(signal, frame): di.get("Logger").info("Caught CTRL-C will gracefully try to exit") sys.exit(0)
def __init__(self, *args, **kwargs): self._logger = di.get("Logger") self.reporter = di.get("Reporter")
def __init__(self, *args, **kwargs): self._logger = di.get("Logger") self.exms = Exm()