Exemplo n.º 1
0
    def __init__(self, new_graphite_root=None, carbon_conf_file=None):
        """
        Build the storage directory and prepare for Start. The storage directory
        is in the GRAPHITE_ROOT folder which is used by all of the carbon daemons.
        GRAPHITE_ROOT can be modified as shown by:
            os.environ["GRAPHITE_ROOT"] = some_storage_directory
        """

        log.debug("Initialising Carbon..")

        # If an overriding graphite_root is provided: set os.environ['GRAPHITE_ROOT']
        if new_graphite_root is not None:
            os.environ["GRAPHITE_ROOT"] = normalize_path(new_graphite_root)

        # Log current GRAPHITE_ROOT
        log.debug("GRAPHITE_ROOT = %s" % os.environ['GRAPHITE_ROOT'])

        # If the path to the carbon.conf file is supplied: use it
        if carbon_conf_file is not None:
            self.carbon_config_file = normalize_path(carbon_conf_file)
        else:
            # otherwise build the path using GRAPHITE_ROOT
            self.carbon_config_file = os.path.join(os.environ['GRAPHITE_ROOT'], 'conf','carbon.conf')

        #read config file, used mostly to get the port its running on
        self.configuration = SafeConfigParser()
        self.configuration.read(self.carbon_config_file)

        self.application_service = service.MultiService()
        self.reactor_thread = None
Exemplo n.º 2
0
    def __init__(self, new_graphite_root=None, carbon_conf_file=None):
        """
        Build the storage directory and prepare for Start. The storage directory
        is in the GRAPHITE_ROOT folder which is used by all of the carbon daemons.
        GRAPHITE_ROOT can be modified as shown by:
            os.environ["GRAPHITE_ROOT"] = some_storage_directory
        """

        log.debug("Initialising Carbon..")

        # If an overriding graphite_root is provided: set os.environ['GRAPHITE_ROOT']
        if new_graphite_root is not None:
            os.environ["GRAPHITE_ROOT"] = normalize_path(new_graphite_root)

        # Log current GRAPHITE_ROOT
        log.debug("GRAPHITE_ROOT = %s" % os.environ['GRAPHITE_ROOT'])

        # If the path to the carbon.conf file is supplied: use it
        if carbon_conf_file is not None:
            self.carbon_config_file = normalize_path(carbon_conf_file)
        else:
            # otherwise build the path using GRAPHITE_ROOT
            self.carbon_config_file = os.path.join(os.environ['GRAPHITE_ROOT'],
                                                   'conf', 'carbon.conf')

        #read config file, used mostly to get the port its running on
        self.configuration = SafeConfigParser()
        self.configuration.read(self.carbon_config_file)

        self.application_service = service.MultiService()
        self.reactor_thread = None
Exemplo n.º 3
0
    def __init__(self,
                 diamond_root=None,
                 diamond_conf_file=None,
                 diamond_stdout_lvl=None):
        self.thread = None
        self.config = None

        log.debug('Initialising Diamond..')

        if diamond_root is not None:
            diamond_root = normalize_path(diamond_root)
            os.environ['DIAMOND_ROOT'] = diamond_root
            log.debug('$DIAMOND_ROOT=%s' % os.environ['DIAMOND_ROOT'])
        else:
            diamond_root = os.environ['DIAMOND_ROOT']

        if diamond_conf_file is None:
            diamond_conf_file = os.path.join(diamond_root, 'diamond.conf')

        diamond_conf_file = normalize_path(diamond_conf_file)

        if os.path.exists(diamond_conf_file):
            self.config = configobj.ConfigObj(diamond_conf_file)
            self.config['configfile'] = diamond_conf_file
        else:
            print >> sys.stderr, "ERROR: Config file: %s does not exist." % diamond_conf_file
            sys.exit(1)

        if diamond_stdout_lvl is None:
            diamond_stdout_lvl = logging.ERROR

        self.log_diamond = logging.getLogger('diamond')
        self.log_diamond.setLevel(logging.DEBUG)
        self.log_diamond.propagate = False

        #       LOG to STDOUT
        formatter = logging.Formatter(
            '[%(asctime)s][%(levelname)s][%(message)s]')
        streamHandler = logging.StreamHandler(sys.stdout)
        streamHandler.setFormatter(formatter)
        streamHandler.setLevel(diamond_stdout_lvl)

        # LOG to File
        fileHandler = logging.FileHandler(
            os.path.join(diamond_root, 'diamond.log'))
        fileHandler.setFormatter(formatter)
        fileHandler.setLevel(logging.DEBUG)

        self.log_diamond.addHandler(streamHandler)
        self.log_diamond.addHandler(fileHandler)
        self.log_diamond.disabled = False
Exemplo n.º 4
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        if gentry_settings_file is None:
            os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'
        else:
            n = 'j5_warden_gentry_settings'
            os.environ['DJANGO_SETTINGS_MODULE'] = n
            if not sys.modules.has_key(n):
                imp.load_source(
                    n, warden_utils.normalize_path(gentry_settings_file))

        log.debug('$DJANGO_SETTINGS_MODULE = %s' %
                  os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f:
                pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError(
                'Gentry Database was not found at "%s". Please use warden-setup to initialise it.'
                % dbfile)

        self.thread = self.GentryServerThread()
Exemplo n.º 5
0
    def __init__(self, diamond_root=None, diamond_conf_file=None, diamond_stdout_lvl=None):
        self.thread = None
        self.config = None

        log.debug('Initialising Diamond..')

        if diamond_root is not None:
            diamond_root = normalize_path(diamond_root)
            os.environ['DIAMOND_ROOT'] = diamond_root
            log.debug('$DIAMOND_ROOT=%s' % os.environ['DIAMOND_ROOT'])
        else:
            diamond_root = os.environ['DIAMOND_ROOT']

        if diamond_conf_file is None:
            diamond_conf_file = os.path.join(diamond_root, 'diamond.conf')

        diamond_conf_file = normalize_path(diamond_conf_file)

        if os.path.exists(diamond_conf_file):
            self.config = configobj.ConfigObj(diamond_conf_file)
            self.config['configfile'] = diamond_conf_file
        else:
            print >> sys.stderr, "ERROR: Config file: %s does not exist." % diamond_conf_file
            sys.exit(1)

        if diamond_stdout_lvl is None:
            diamond_stdout_lvl = logging.ERROR

        self.log_diamond = logging.getLogger('diamond')
        self.log_diamond.setLevel(logging.DEBUG)
        self.log_diamond.propagate = False

        #       LOG to STDOUT
        formatter = logging.Formatter('[%(asctime)s][%(levelname)s][%(message)s]')
        streamHandler = logging.StreamHandler(sys.stdout)
        streamHandler.setFormatter(formatter)
        streamHandler.setLevel(diamond_stdout_lvl)

        # LOG to File
        fileHandler = logging.FileHandler(os.path.join(diamond_root,'diamond.log'))
        fileHandler.setFormatter(formatter)
        fileHandler.setLevel(logging.DEBUG)

        self.log_diamond.addHandler(streamHandler)
        self.log_diamond.addHandler(fileHandler)
        self.log_diamond.disabled = False
Exemplo n.º 6
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        if gentry_settings_file is None:
            os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'
        else:
            n = 'j5_warden_gentry_settings'
            os.environ['DJANGO_SETTINGS_MODULE'] = n
            if not sys.modules.has_key(n):
                imp.load_source(n, warden_utils.normalize_path(gentry_settings_file))

        log.debug('$DJANGO_SETTINGS_MODULE = %s' % os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        # hook loggers
        import graphite.logger
        self.graphitelog = graphite.logger.log

        # FILE HANDLERS STDOUT
        self.graphitelog.metricAccessLogger.addHandler(self.make_and_return_filehandler('metricAccessLogger', os.path.expanduser('~/.graphite/metric_access.log')))
        self.graphitelog.cacheLogger.addHandler(self.make_and_return_filehandler('cacheLogger',  os.path.expanduser('~/.graphite/.graphite/cache.log')))
        self.graphitelog.renderingLogger.addHandler(self.make_and_return_filehandler('renderingLogger',  os.path.expanduser('~/.graphite/.graphite/rendering.log')))
        self.graphitelog.infoLogger.addHandler(self.make_and_return_filehandler('infoLogger',  os.path.expanduser('~/.graphite/.graphite/info.log')))
        self.graphitelog.exceptionLogger.addHandler(self.make_and_return_filehandler('exceptionLogger',  os.path.expanduser('~/.graphite/.graphite/exception.log')))

        # STREAM HANDLERS STDOUT
        self.graphitelog.metricAccessLogger.addHandler(self.make_and_return_streamhandler('metricAccessLogger'))
        self.graphitelog.cacheLogger.addHandler(self.make_and_return_streamhandler('cacheLogger'))
        self.graphitelog.renderingLogger.addHandler(self.make_and_return_streamhandler('renderingLogger'))
        self.graphitelog.infoLogger.addHandler(self.make_and_return_streamhandler('infoLogger'))
        self.graphitelog.exceptionLogger.addHandler(self.make_and_return_streamhandler('exceptionLogger'))

        self.graphitelog.infoLogger.propagate = False
        self.graphitelog.exceptionLogger.propagate = False
        self.graphitelog.cacheLogger.propagate = False
        self.graphitelog.metricAccessLogger.propagate = False
        self.graphitelog.renderingLogger.propagate = False

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f: pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError('Gentry Database was not found at "%s". Please use warden-setup to initialise it.' % dbfile)

        self.thread = self.GentryServerThread()
Exemplo n.º 7
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        if gentry_settings_file is None:
            os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'
        else:
            n = 'j5_warden_gentry_settings'
            os.environ['DJANGO_SETTINGS_MODULE'] = n
            if not sys.modules.has_key(n):
                imp.load_source(n, warden_utils.normalize_path(gentry_settings_file))

        log.debug('$DJANGO_SETTINGS_MODULE = %s' % os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f: pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError('Gentry Database was not found at "%s". Please use warden-setup to initialise it.' % dbfile)

        self.thread = self.GentryServerThread()
Exemplo n.º 8
0
    def __init__(self, gentry_settings_file=None):

        log.debug('Initialising Gentry..')

        if gentry_settings_file is None:
            os.environ['DJANGO_SETTINGS_MODULE'] = 'gentry.settings'
        else:
            n = 'j5_warden_gentry_settings'
            os.environ['DJANGO_SETTINGS_MODULE'] = n
            if not sys.modules.has_key(n):
                imp.load_source(
                    n, warden_utils.normalize_path(gentry_settings_file))

        log.debug('$DJANGO_SETTINGS_MODULE = %s' %
                  os.environ['DJANGO_SETTINGS_MODULE'])
        from django.conf import settings

        # hook loggers
        import graphite.logger
        self.graphitelog = graphite.logger.log

        # FILE HANDLERS STDOUT
        self.graphitelog.metricAccessLogger.addHandler(
            self.make_and_return_filehandler(
                'metricAccessLogger',
                os.path.expanduser('~/.graphite/metric_access.log')))
        self.graphitelog.cacheLogger.addHandler(
            self.make_and_return_filehandler(
                'cacheLogger',
                os.path.expanduser('~/.graphite/.graphite/cache.log')))
        self.graphitelog.renderingLogger.addHandler(
            self.make_and_return_filehandler(
                'renderingLogger',
                os.path.expanduser('~/.graphite/.graphite/rendering.log')))
        self.graphitelog.infoLogger.addHandler(
            self.make_and_return_filehandler(
                'infoLogger',
                os.path.expanduser('~/.graphite/.graphite/info.log')))
        self.graphitelog.exceptionLogger.addHandler(
            self.make_and_return_filehandler(
                'exceptionLogger',
                os.path.expanduser('~/.graphite/.graphite/exception.log')))

        # STREAM HANDLERS STDOUT
        self.graphitelog.metricAccessLogger.addHandler(
            self.make_and_return_streamhandler('metricAccessLogger'))
        self.graphitelog.cacheLogger.addHandler(
            self.make_and_return_streamhandler('cacheLogger'))
        self.graphitelog.renderingLogger.addHandler(
            self.make_and_return_streamhandler('renderingLogger'))
        self.graphitelog.infoLogger.addHandler(
            self.make_and_return_streamhandler('infoLogger'))
        self.graphitelog.exceptionLogger.addHandler(
            self.make_and_return_streamhandler('exceptionLogger'))

        self.graphitelog.infoLogger.propagate = False
        self.graphitelog.exceptionLogger.propagate = False
        self.graphitelog.cacheLogger.propagate = False
        self.graphitelog.metricAccessLogger.propagate = False
        self.graphitelog.renderingLogger.propagate = False

        dbfile = settings.DATABASES['default']['NAME']
        #exists
        try:
            with open(dbfile) as f:
                pass
            management.execute_from_command_line(['manage.py', 'migrate'])
        except:
            raise IOError(
                'Gentry Database was not found at "%s". Please use warden-setup to initialise it.'
                % dbfile)

        self.thread = self.GentryServerThread()