Ejemplo n.º 1
0
 def _run_agent(self, agent):
     subscription = agent.subscription
     send_data = self._write_indirectly
     consumer = PubSubConsumer(agent, send_data)
     with logging.LogContext(subscription=subscription):
         return self._run_consumer(consumer)
Ejemplo n.º 2
0
 def do(self, job, session):
     with logging.LogContext(**job.brief):
         self._process(job.is_expired, job.message, session)
Ejemplo n.º 3
0
    def get_tasks(self):
        if not self.stanza_configs:
            return None

        conf_mgr = cm.ConfManager(self.server_uri, self.session_key)

        settings = conf_mgr.all_stanzas_as_dicts(self.conf_file,
                                                 do_reload=False)

        # set logging level for our logger
        set_log_level(settings[tac.log_stanza][tac.log_level])

        proxy_info = tpc.get_proxy_info(self.session_key)
        tasks, creds = {}, {}
        for stanza in self.stanza_configs:
            input_name = scutil.extract_datainput_name(stanza[tac.name])
            with logging.LogContext(datainput=input_name):
                stanza[tac.interval] = tacommon.get_interval(stanza, 60)
                stanza[tac.polling_interval] = stanza[tac.interval]
                stanza[acc.period] = int(stanza[acc.period])

                if stanza[acc.period] > 86400 or stanza[acc.period] < 60:
                    logger.error(
                        "Granularity(period) is not in range[60, 86400], ignore this input.",
                        Period=stanza[acc.period],
                        ErrorCode="ConfigurationError",
                        ErrorDetail=
                        "Invalid Granularity(period). It's out of range [60, 86400]."
                    )
                    continue

                if stanza[tac.polling_interval] % stanza[acc.period]:
                    logger.error(
                        "Polling interval is not multiple of period, ignore this input.",
                        Period=stanza[acc.period],
                        ErrorCode="ConfigurationError",
                        ErrorDetail=
                        "Polling interval should be a multiple of granularity(period)."
                    )
                    continue

                stanza[tac.datainput] = input_name
                stanza[tac.sourcetype] = stanza.get(tac.sourcetype,
                                                    "aws:cloudwatch")
                metric_names = stanza[acc.metric_names].strip()
                if metric_names != ".*":
                    metric_names = json.loads(metric_names)
                else:
                    metric_names = None
                stanza[acc.metric_names] = metric_names

                stanza[acc.metric_dimensions] = json.loads(
                    stanza[acc.metric_dimensions])
                stanza[acc.statistics] = json.loads(stanza[acc.statistics])

                stanza[tac.log_level] = settings[tac.log_stanza][tac.log_level]

                stanza[tac.aws_account] = stanza.get('aws_account')
                stanza[tac.aws_iam_role] = stanza.get('aws_iam_role')

                stanza[acc.use_metric_format] = scutil.is_true(
                    stanza.get(acc.use_metric_format, False))

                stanza.update(self.metas)
                stanza.update(proxy_info)
                stanza.update(settings[tac.global_settings])
                stanza[tac.use_hec] = scutil.is_true(
                    stanza.get(tac.use_hec, False))
                stanza[acc.max_api_saver_time] = \
                    int(stanza.get(acc.max_api_saver_time, 7200))

                region_tasks = {}
                tasks[stanza[tac.datainput]] = region_tasks
                for region in stanza[tac.aws_region].split(","):
                    region = region.strip()
                    if not region:
                        continue

                    task = {}
                    task.update(stanza)
                    task[tac.aws_region] = region
                    task[tac.region] = region
                    num, rtasks = self._expand_task(task)
                    if rtasks:
                        region_tasks[region] = rtasks
                    stanza[region] = num

                if not region_tasks:
                    logger.warning("No metric/dimension has been found.")
        all_tasks = []
        for region_tasks in tasks.itervalues():
            for rtasks in region_tasks.itervalues():
                all_tasks.extend(rtasks)
        tacommon.handle_hec(all_tasks, "aws_cloudwatch")

        return all_tasks
Ejemplo n.º 4
0
def get_metrics(config):
    with logging.LogContext(metrics_dimensions=config[acc.metric_dimensions]):
        dimension_filters = get_dimension_filters(
            config[acc.metric_dimensions])
        metrics = list_metrics(config, dimension_filters)
    return metrics
Ejemplo n.º 5
0
 def _gather_results_wrapper(metric_name, logging_ctx):
     with logging.LogContext(prefix=logging_ctx):
         _gather_results(metric_name)