Ejemplo n.º 1
0
    def __init__(self, home):
        """
        Load configuration object
        """
        AutoConf.autoconf(home)
        self.configuration = AutoConf.get_warden_conf()

        # Setup logger
        # this is the stdout log level
        loglevel = getattr(logging, self.configuration.get('warden', {}).get('loglevel', 'INFO'))
        log.setLevel(loglevel)

        self.startuptime = None
        self.shutdowntime = None
        self.smtp_forwarder_enabled = str(self.configuration.get('smtp_forwarder', {}).get('enabled', '')).lower() in ('true', 't', '1', 'yes', 'y')

        log.info('Initialising Warden..')
        try:
            # initialise Carbon, daemon services are setup here, but the event reactor is not yet run
            self.carbon = CarbonManager()

            # initialise Gentry, this will also perform database manipulation for Sentry
            self.gentry = GentryManager()

            # initialise Diamond, not much is required here
            self.diamond = DiamondManager()


            if self.smtp_forwarder_enabled:
                self.smtpforward = SMTPForwarderManager(dict(self.configuration.get('smtp_forwarder', {})))

        except Exception:
            log.exception("An error occured during initialisation.")
            sys.exit(1)
Ejemplo n.º 2
0
    def __init__(self,
                 warden_configuration_file,
                 new_graphite_root=None,            # does the graphite root variable need to be changed
                 carbon_config_path=None,           # where are the carbon config files
                 diamond_config_path=None,          # where is the diamond config file
                 gentry_settings_path=None,         # the name of the gentry settings module
                 start_stmp_forwarder=True,
                 smtp_forwarder_config_path=None,
    ):
        """
        Load configuration object
        """

        # Otherwise there may be a config argument
       
        if warden_configuration_file is None:
            log.critical('No Warden configuration file supplied! Please use the "warden_configuration_file" parameter.')
            sys.exit()

        warden_configuration_file = os.path.abspath(os.path.expanduser(warden_configuration_file))
        try:
            with open(warden_configuration_file) as f: pass
        except IOError:
            log.error('The warden config file specified ("%s") does not exist!' % warden_configuration_file)
            raise

        self.configuration = ConfigParser.RawConfigParser()
        self.configuration.read(warden_configuration_file)

        # Setup logger
        # this is the stdout log level
        loglevel = getattr(logging, self.configuration.get('warden','loglevel'))
        log.setLevel(loglevel)

        self.startuptime = None
        self.shutdowntime = None

        # pull new config values into configuration object

        if new_graphite_root is not None:
            self.configuration.set('carbon', 'graphite_root', str(new_graphite_root))

        if carbon_config_path is not None:
            self.configuration.set('carbon', 'configuration', str(carbon_config_path))

        if diamond_config_path is not None:
            self.configuration.set('diamond', 'configuration', str(diamond_config_path))

        if gentry_settings_path is not None:
            self.configuration.set('gentry', 'gentry_settings_py_path', str(gentry_settings_path))

        if start_stmp_forwarder is False:
            self.configuration.set('smtp_forwarder', 'enabled', str(start_stmp_forwarder))

        if smtp_forwarder_config_path is not None:
            self.configuration.set('smtp_forwarder', 'configuration', str(smtp_forwarder_config_path))

        log.info('Initialising Warden..')
        try:
            # initialise Carbon, daemon services are setup here, but the event reactor is not yet run
            self.carbon = CarbonManager(
                self.configuration.get('carbon', 'graphite_root'),
                self.configuration.get('carbon', 'configuration'))

            # initialise Gentry, this will also perform database manipulation for Sentry
            self.gentry = GentryManager(
                self.configuration.get('gentry', 'gentry_settings_py_path'))

            # initialise Diamond, not much is required here
            self.diamond = DiamondManager(
                self.configuration.get('diamond', 'diamond_root'),
                self.configuration.get('diamond', 'configuration'),
                getattr(logging, self.configuration.get('diamond','loglevel')))

            if self.configuration.getboolean('smtp_forwarder', 'enabled'):
                self.smtpforward = SMTPForwarderManager(dict(self.configuration.items('smtp_forwarder')))

        except Exception:
            log.exception("An error occured during initialisation.")
            sys.exit(1)
Ejemplo n.º 3
0
class WardenServer(object):
    """
    Warden is a solution for controlling Carbon daemons, Sentry, Graphite-web and Diamond all within a single process.
    The sub systems all run in separate threads and can be shutdown gracefully using sigint or stop commands.
    """
    
    def __init__(self, home):
        """
        Load configuration object
        """
        AutoConf.autoconf(home)
        self.configuration = AutoConf.get_warden_conf()

        # Setup logger
        # this is the stdout log level
        loglevel = getattr(logging, self.configuration.get('warden', {}).get('loglevel', 'INFO'))
        log.setLevel(loglevel)

        self.startuptime = None
        self.shutdowntime = None
        self.smtp_forwarder_enabled = str(self.configuration.get('smtp_forwarder', {}).get('enabled', '')).lower() in ('true', 't', '1', 'yes', 'y')

        log.info('Initialising Warden..')
        try:
            # initialise Carbon, daemon services are setup here, but the event reactor is not yet run
            self.carbon = CarbonManager()

            # initialise Gentry, this will also perform database manipulation for Sentry
            self.gentry = GentryManager()

            # initialise Diamond, not much is required here
            self.diamond = DiamondManager()


            if self.smtp_forwarder_enabled:
                self.smtpforward = SMTPForwarderManager(dict(self.configuration.get('smtp_forwarder', {})))

        except Exception:
            log.exception("An error occured during initialisation.")
            sys.exit(1)

    def _startup(self):
        """
        Start the warden instance
        Carbon, Diamond and Gentry are started in order, and this method will only exit once all are bound to their
        correct ports
        """

        log.info('Starting Warden..')
        try:
            self.carbon.start()
            self._wait_for_start(self.carbon)
            log.info('1. Carbon Started')

            self.diamond.start()
            self._wait_for_start(self.diamond)
            log.info('2. Diamond Started')

            self.gentry.start()
            self._wait_for_start(self.gentry)
            log.info('3. Gentry Started')

            if self.smtp_forwarder_enabled:
                self.smtpforward.start()
                log.info('4. Graphite SMTP forwarder Started')

            # blocking
            log.info('Started Warden.')
            self.startuptime = self.shutdowntime = datetime.datetime.now()

        except Exception, e:
            raise StartupException(e)
Ejemplo n.º 4
0
class WardenServer(object):
    """
    Warden is a solution for controlling Carbon daemons, Sentry, Graphite-web and Diamond all within a single process.
    The sub systems all run in separate threads and can be shutdown gracefully using sigint or stop commands.
    """
    
    def __init__(self,
                 warden_configuration_file,
                 new_graphite_root=None,            # does the graphite root variable need to be changed
                 carbon_config_path=None,           # where are the carbon config files
                 diamond_config_path=None,          # where is the diamond config file
                 gentry_settings_path=None,         # the name of the gentry settings module
                 start_stmp_forwarder=True,
                 smtp_forwarder_config_path=None,
    ):
        """
        Load configuration object
        """

        # Otherwise there may be a config argument
       
        if warden_configuration_file is None:
            log.critical('No Warden configuration file supplied! Please use the "warden_configuration_file" parameter.')
            sys.exit()

        warden_configuration_file = os.path.abspath(os.path.expanduser(warden_configuration_file))
        try:
            with open(warden_configuration_file) as f: pass
        except IOError:
            log.error('The warden config file specified ("%s") does not exist!' % warden_configuration_file)
            raise

        self.configuration = ConfigParser.RawConfigParser()
        self.configuration.read(warden_configuration_file)

        # Setup logger
        # this is the stdout log level
        loglevel = getattr(logging, self.configuration.get('warden','loglevel'))
        log.setLevel(loglevel)

        self.startuptime = None
        self.shutdowntime = None

        # pull new config values into configuration object

        if new_graphite_root is not None:
            self.configuration.set('carbon', 'graphite_root', str(new_graphite_root))

        if carbon_config_path is not None:
            self.configuration.set('carbon', 'configuration', str(carbon_config_path))

        if diamond_config_path is not None:
            self.configuration.set('diamond', 'configuration', str(diamond_config_path))

        if gentry_settings_path is not None:
            self.configuration.set('gentry', 'gentry_settings_py_path', str(gentry_settings_path))

        if start_stmp_forwarder is False:
            self.configuration.set('smtp_forwarder', 'enabled', str(start_stmp_forwarder))

        if smtp_forwarder_config_path is not None:
            self.configuration.set('smtp_forwarder', 'configuration', str(smtp_forwarder_config_path))

        log.info('Initialising Warden..')
        try:
            # initialise Carbon, daemon services are setup here, but the event reactor is not yet run
            self.carbon = CarbonManager(
                self.configuration.get('carbon', 'graphite_root'),
                self.configuration.get('carbon', 'configuration'))

            # initialise Gentry, this will also perform database manipulation for Sentry
            self.gentry = GentryManager(
                self.configuration.get('gentry', 'gentry_settings_py_path'))

            # initialise Diamond, not much is required here
            self.diamond = DiamondManager(
                self.configuration.get('diamond', 'diamond_root'),
                self.configuration.get('diamond', 'configuration'),
                getattr(logging, self.configuration.get('diamond','loglevel')))

            if self.configuration.getboolean('smtp_forwarder', 'enabled'):
                self.smtpforward = SMTPForwarderManager(dict(self.configuration.items('smtp_forwarder')))

        except Exception:
            log.exception("An error occured during initialisation.")
            sys.exit(1)

    def _startup(self):
        """
        Start the warden instance
        Carbon, Diamond and Gentry are started in order, and this method will only exit once all are bound to their
        correct ports
        """

        log.info('Starting Warden..')
        try:
            self.carbon.start()
            self._wait_for_start(self.carbon)
            log.info('1. Carbon Started')

            self.diamond.start()
            self._wait_for_start(self.diamond)
            log.info('2. Diamond Started')

            self.gentry.start()
            self._wait_for_start(self.gentry)
            log.info('3. Gentry Started')

            if self.configuration.getboolean('smtp_forwarder', 'enabled'):
                self.smtpforward.start()
                log.info('4. Graphite SMTP forwarder Started')

            # blocking
            log.info('Started Warden.')
            self.startuptime = self.shutdowntime = datetime.datetime.now()

        except Exception, e:
            raise StartupException(e)