Esempio n. 1
0
    def configure(self):
        enabled = self.scalr_config.get('analytics', {}).get('enabled', False)
        if not enabled:
            sys.stdout.write('Analytics is disabled. Exit\n')
            sys.exit(0)
        helper.update_config(
            self.scalr_config.get('analytics', {}).get('connections',
                                                       {}).get('scalr', {}),
            self.config['connections']['mysql'])
        helper.update_config(
            self.scalr_config.get('analytics',
                                  {}).get('connections',
                                          {}).get('analytics', {}),
            self.config['connections']['analytics'])
        helper.update_config(
            self.scalr_config.get('analytics', {}).get('poller', {}),
            self.config)
        helper.validate_config(self.config)

        self.config['pool_size'] = max(11, self.config['pool_size'])
        self.iteration_timeout = self.config['interval'] - 5

        crypto_key_path = os.path.join(self.scalr_dir, 'app/etc/.cryptokey')
        self.crypto_key = cryptotool.read_key(crypto_key_path)
        self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql'])
        self.analytics_db = dbmanager.ScalrDB(
            self.config['connections']['analytics'])
        self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db)
        self.pool = helper.GPool(pool_size=self.config['pool_size'])

        socket.setdefaulttimeout(self.config['instances_connection_timeout'])
Esempio n. 2
0
    def configure(self):
        enabled = self.scalr_config.get('analytics', {}).get('enabled', False)
        if not enabled:
            sys.stdout.write('Analytics is disabled. Exit\n')
            sys.exit(0)

        # set date_from
        if self.args['--date-from']:
            dtime_from = datetime.datetime.strptime(self.args['--date-from'],
                                                    '%Y-%m-%d')
            two_weeks_ago = datetime.datetime.utcnow() + datetime.timedelta(
                days=-14)
            assert_msg = 'Processing is not supported for dtime-from more than two weeks ago'
            assert dtime_from > two_weeks_ago, assert_msg
            self.config['dtime_from'] = dtime_from

        # set date_to
        if self.args['--date-to']:
            dtime_to = datetime.datetime.strptime(self.args['--date-to'],
                                                  '%Y-%m-%d')
            dtime_to = dtime_to.replace(minute=59, second=59)
            self.config['dtime_to'] = dtime_to

        # update config
        helper.update_config(
            self.scalr_config.get('analytics', {}).get('connections',
                                                       {}).get('scalr', {}),
            self.config['connections']['mysql'])

        helper.update_config(
            self.scalr_config.get('analytics',
                                  {}).get('connections',
                                          {}).get('analytics', {}),
            self.config['connections']['analytics'])

        helper.update_config(
            self.scalr_config.get('analytics', {}).get('processing', {}),
            self.config)

        self.config['platform'] = self.args['--platform'] or False

        helper.validate_config(self.config)

        self.iteration_timeout = self.config['interval'] - self.error_sleep

        crypto_key_path = os.path.join(os.path.dirname(self.args['--config']),
                                       '.cryptokey')
        self.crypto_key = cryptotool.read_key(crypto_key_path)

        self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql'])
        self.analytics_db = dbmanager.ScalrDB(
            self.config['connections']['analytics'])
        self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db)

        self.pool = helper.GPool(pool_size=self.config['pool_size'])

        socket.setdefaulttimeout(self.config['instances_connection_timeout'])
Esempio n. 3
0
    def configure(self):
        helper.update_config(self.scalr_config.get('dbqueue_event', {}),
                             self.config)
        helper.validate_config(self.config)
        socket.setdefaulttimeout(self.config['instances_connection_timeout'])

        self._db = dbmanager.ScalrDB(self.config['connections']['mysql'])
        self._pool = helper.GPool(pool_size=self.config['pool_size'])
Esempio n. 4
0
 def __init__(self):
     super(DBQueueEvent, self).__init__(pid_file=CONFIG['pid_file'])
     self._db = dbmanager.ScalrDB(CONFIG['connections']['mysql'])
     self._pool = gevent.pool.Pool(CONFIG['pool_size'])
     self.observers = {
         'MailEventObserver': self.mail_event_observer,
         'RESTEventObserver': self.rest_event_observer,
     }
Esempio n. 5
0
    def configure(self):
        try:
            rrd_dir = self.scalr_config['stats_poller']['rrd_db_dir']
        except KeyError:
            rrd_dir = self.scalr_config['load_statistics']['rrd']['dir']
        self.config['rrd_dir'] = rrd_dir
        helper.validate_config(self.config)

        self._db = dbmanager.ScalrDB(self.config['connections']['mysql'])
Esempio n. 6
0
    def configure(self):
        helper.update_config(self.scalr_config.get('msg_sender', {}),
                             self.config)
        helper.validate_config(self.config)
        socket.setdefaulttimeout(self.config['instances_connection_timeout'])

        self._db = dbmanager.ScalrDB(self.config['connections']['mysql'])
        self._pool = helper.GPool(pool_size=self.config['pool_size'])
        self.max_processing_messages = 2 * self.config['pool_size']
Esempio n. 7
0
    def configure(self):
        helper.update_config(
                self.scalr_config.get('scalarizr_update', {}).get('service', {}), self.config)
        helper.validate_config(self.config)
        if self.config['interval']:
            self.iteration_timeout = int(self.config['interval'])
        socket.setdefaulttimeout(self.config['instances_connection_timeout'])

        self._db = dbmanager.ScalrDB(self.config['connections']['mysql'])
        self._pool = helper.GPool(pool_size=self.config['pool_size'])
Esempio n. 8
0
    def configure(self):
        helper.update_config(
            self.scalr_config.get('dbqueue_event', {}), self.config)
        helper.validate_config(self.config)
        socket.setdefaulttimeout(self.config['instances_connection_timeout'])

        self._db = dbmanager.ScalrDB(self.config['connections']['mysql'])
        self._pool = helper.GPool(pool_size=self.config['pool_size'])

        proxy_settings = helper.get_proxy_settings(self.scalr_config, 'system.webhooks')
        if proxy_settings:
            self.proxy = {
                'http': proxy_settings['url'],
                'https': proxy_settings['url']
            }
Esempio n. 9
0
    def __init__(self):
        self._db = dbmanager.ScalrDB(CONFIG['connections']['mysql'])
        self.plotters = {
            'cpu': rrd.plot_cpu,
            'la': rrd.plot_la,
            'mem': rrd.plot_mem,
            'net': rrd.plot_net,
            'snum': rrd.plot_snum,
        }

        import os
        import threading

        os_local = threading.local()
        for k, v in os.__dict__.iteritems():
            os_local.__setattr__(k, v)
        os = os_local
Esempio n. 10
0
    def configure(self):
        enabled = self.scalr_config.get('analytics', {}).get('enabled', False)
        if not enabled:
            sys.stdout.write('Analytics is disabled. Exit\n')
            sys.exit(0)
        helper.update_config(
            self.scalr_config.get('analytics', {}).get('connections',
                                                       {}).get('scalr', {}),
            self.config['connections']['mysql'])
        helper.update_config(
            self.scalr_config.get('analytics',
                                  {}).get('connections',
                                          {}).get('analytics', {}),
            self.config['connections']['analytics'])
        helper.update_config(
            self.scalr_config.get('analytics', {}).get('processing', {}),
            self.config)
        helper.validate_config(self.config)

        self.config['pool_size'] = max(21, self.config['pool_size'])
        self.config['recalculate'] = self.args['--recalculate']
        self.config['date_from'] = self.args['--date-from']
        self.config['date_to'] = self.args['--date-to']
        self.config['platform'] = self.args['--platform']

        if self.config['recalculate']:
            self.iteration_timeout = None
        else:
            self.iteration_timeout = self.config['interval'] - 5

        self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql'])
        self.analytics_db = dbmanager.DB(
            self.config['connections']['analytics'])
        self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db)
        self._pool = helper.GPool(pool_size=self.config['pool_size'])

        socket.setdefaulttimeout(self.config['instances_connection_timeout'])
Esempio n. 11
0
 def __init__(self):
     super(MsgSender, self).__init__(pid_file=CONFIG['pid_file'])
     self._db = dbmanager.ScalrDB(CONFIG['connections']['mysql'],
                                  pool_size=1)
     self._pool = gevent.pool.Pool(CONFIG['pool_size'])
Esempio n. 12
0
 def __init__(self):
     self._db = dbmanager.ScalrDB(CONFIG['connections']['mysql'],
                                  pool_size=1)
Esempio n. 13
0
 def __init__(self, config, scalr_config):
     self.config = config
     self.scalr_config = scalr_config
     self._db = dbmanager.ScalrDB(self.config['connections']['mysql'], pool_size=1)
Esempio n. 14
0
    def configure(self):
        enabled = self.scalr_config.get('analytics', {}).get('enabled', False)
        if not enabled:
            sys.stdout.write('Analytics is disabled. Exit\n')
            sys.exit(0)

        utcnow = datetime.datetime.utcnow().replace(microsecond=0)
        if self.args['--date-from']:
            dtime_from = datetime.datetime.strptime(self.args['--date-from'],
                                                    '%Y-%m-%d')
            if not self.args['--recalculate']:
                if self.args['--billing'] in ('aws-detailed-billing', 'azure'):
                    three_months_ago = utcnow + datetime.timedelta(days=-119)
                    assert_msg = 'Processing is not supported for dtime-from more than four months ago'
                    assert dtime_from > three_months_ago, assert_msg
                else:
                    two_weeks_ago = utcnow + datetime.timedelta(days=-14)
                    assert_msg = 'Processing is not supported for dtime-from more than two weeks ago'
                    assert dtime_from > two_weeks_ago, assert_msg
            self.config['dtime_from'] = dtime_from
        if self.args['--date-to']:
            dtime_to = datetime.datetime.strptime(self.args['--date-to'],
                                                  '%Y-%m-%d')
            self.config['dtime_to'] = dtime_to

        helper.update_config(
            self.scalr_config.get('analytics', {}).get('connections',
                                                       {}).get('scalr', {}),
            self.config['connections']['mysql'])
        helper.update_config(
            self.scalr_config.get('analytics',
                                  {}).get('connections',
                                          {}).get('analytics', {}),
            self.config['connections']['analytics'])
        helper.update_config(
            self.scalr_config.get('analytics', {}).get('processing', {}),
            self.config)

        if self.args['--billing']:
            self.config['billing'] = (self.args['--billing'], )
        if self.args['--platform']:
            assert_msg = "--platform option supported only for 'poller' billing type"
            assert 'poller' in self.config['billing'], assert_msg
            self.config['platform'] = (self.args['--platform'], )

        helper.validate_config(self.config)

        crypto_key_path = os.path.join(os.path.dirname(self.args['--config']),
                                       '.cryptokey')
        self.config['crypto_key'] = cryptotool.read_key(crypto_key_path)
        self.config['azure_app_client_id'] = self.scalr_config.get(
            'azure', {}).get('app_client_id')
        self.config['azure_app_secret_key'] = self.scalr_config.get(
            'azure', {}).get('app_secret_key')

        self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql'])
        self.analytics_db = dbmanager.ScalrDB(
            self.config['connections']['analytics'])
        self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db)

        if self.args['--year']:
            # XXX pymysql.connect issue
            time.sleep(0)
            quarters_calendar = self.analytics.get_quarters_calendar()
            year = int(self.args['--year'])
            quarter = int(self.args['--quarter'] or 1)
            dtime_from, dtime_to = quarters_calendar.dtime_for_quarter(
                quarter, year=year)
            self.config['dtime_from'] = dtime_from
            self.config['dtime_to'] = min(utcnow, dtime_to)

        self.config['proxy']['aws'] = helper.get_proxy_settings(
            self.scalr_config, 'aws')
        self.config['proxy']['azure'] = helper.get_proxy_settings(
            self.scalr_config, 'azure')

        socket.setdefaulttimeout(self.config['instances_connection_timeout'])