def __init__(self, configuration): self.dest_path = os.environ.get('WATCHER_APPDYNAMICS_DEST_PATH') if not self.dest_path: raise RuntimeError( 'AppDyanmics watcher agent initialization failed. Env variable ' 'WATCHER_APPDYNAMICS_DEST_PATH must be set.') self.cluster_id = configuration['cluster_id'] self.tpl = load_template(TPL_NAME) self.logs = {} self._first_run = True logger.info('AppDynamics watcher agent initialization complete!')
def test_tpl_render(monkeypatch, kwargs, expected): tpl = load_template(TPL_NAME) config = tpl.render(**kwargs) assert json.loads(config) == expected
def __init__(self, configuration): cluster_id = configuration['cluster_id'] self.scalyr_sampling_rules = ScalyrAgent.parse_scalyr_sampling_rules( configuration.get('scalyr_sampling_rules') or [], ) self.api_key_file = os.environ.get('WATCHER_SCALYR_API_KEY_FILE') self.api_key = None self.dest_path = os.environ.get('WATCHER_SCALYR_DEST_PATH') self.scalyr_server = os.environ.get('WATCHER_SCALYR_SERVER') self.json_parsers_mapping = self.make_json_parsers_mapping( os.environ.get('WATCHER_SCALYR_PARSE_LINES_JSON', ''), ) self.enable_profiling = os.environ.get('WATCHER_SCALYR_ENABLE_PROFILING', '').lower() == 'true' cluster_alias = os.environ.get('CLUSTER_ALIAS', 'none') cluster_environment = os.environ.get('CLUSTER_ENVIRONMENT', 'production') node_name = os.environ.get('CLUSTER_NODE_NAME', 'unknown') if not all([self.api_key_file, self.dest_path]): raise RuntimeError('Scalyr watcher agent initialization failed. ' 'Env variables WATCHER_SCALYR_API_KEY_FILE and ' 'WATCHER_SCALYR_DEST_PATH must be set.') self.config_path = os.environ.get('WATCHER_SCALYR_CONFIG_PATH', SCALYR_CONFIG_PATH) if not os.path.isdir(os.path.dirname(self.config_path)): raise RuntimeError( 'Scalyr watcher agent initialization failed. {} config path does not exist.'.format( self.config_path)) if not os.path.isfile(self.api_key_file): raise RuntimeError( 'Scalyr watcher agent initialization failed. {} API key file does not exist.'.format( self.api_key_file)) if not os.path.isdir(self.dest_path): raise RuntimeError( 'Scalyr watcher agent initialization failed. {} destination path does not exist.'.format( self.dest_path)) else: watched_containers = os.listdir(self.dest_path) logger.info('Scalyr watcher agent found %d watched containers.', len(watched_containers)) logger.debug('Scalyr watcher agent found the following watched containers: %s', watched_containers) self.journald = None journald_monitor = os.environ.get('WATCHER_SCALYR_JOURNALD', False) if journald_monitor: attributes_str = os.environ.get('WATCHER_SCALYR_JOURNALD_ATTRIBUTES', '{}') extra_fields_str = os.environ.get('WATCHER_SCALYR_JOURNALD_EXTRA_FIELDS', '{}') self.journald = { 'journal_path': os.environ.get('WATCHER_SCALYR_JOURNALD_PATH'), 'attributes': json.loads(attributes_str), 'extra_fields': json.loads(extra_fields_str), 'write_rate': int(os.environ.get('WATCHER_SCALYR_JOURNALD_WRITE_RATE', SCALYR_DEFAULT_WRITE_RATE)), 'write_burst': int(os.environ.get('WATCHER_SCALYR_JOURNALD_WRITE_BURST', SCALYR_DEFAULT_WRITE_BURST)), } self.server_attributes = { 'serverHost': cluster_id, 'cluster': cluster_id, 'cluster_environment': cluster_environment, 'cluster_alias': cluster_alias, 'environment': cluster_environment, 'node': node_name, 'parser': SCALYR_DEFAULT_PARSER } self.tpl = load_template(TPL_NAME) self.logs = {} self._first_run = True logger.info('Scalyr watcher agent initialization complete!')