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'])
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'])
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'])
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'])