コード例 #1
0
    def update_last_runtime(self, end):
        """
        write out the updated configuration with the last_run_timestamp
        :param end: the current end time last used with ListMetrics()
        """

        with open(self.config_file_path, 'r+') as cf:
            config = json.load(cf)
            config['last_run_timestamp'] = command.unix_time_millis(end) / 1000
            cf.seek(0)
            json.dump(config, cf)
            cf.truncate()
コード例 #2
0
    def _process_metrics(self, metrics, start, end):
        """
        Loops over all metrics and call GetMetricStatistics() on each that are
        included by the configuration.
        :param metrics: the array of metrics returned from ListMetrics() ('Metrics')
        :param start: the start time
        :param end: the end time
        """

        with WavefrontProxy(self.proxy_host, self.proxy_port, self.is_dry_run) as wf_proxy:
            for m in metrics:
                metric_name = '{}.{}'.format(m['Namespace'].lower().replace('/', '.'),
                                             m['MetricName'].lower())
                point_tags = {'Namespace': m['Namespace']}
                for d in m['Dimensions']:
                    point_tags[d['Name']] = d['Value']

                config = self.get_configuration(m['Namespace'], m['MetricName'])
                if config is None or len(config['stats']) == 0:
                    continue

                stats = self.aws_client.get_metric_statistics(
                    Namespace = m['Namespace'],
                    MetricName = m['MetricName'],
                    StartTime = start,
                    EndTime = end,
                    Period = 60,
                    Statistics = config['stats'])
                source = self._get_source(config, point_tags, m['Dimensions'])
                if not source:
                    logger.warning('Source is not found in %s', m)
                    continue

                number_of_stats = len(config['stats'])
                for stat in stats['Datapoints']:
                    for s in config['stats']:
                        short_name = stat_short_name[s]
                        if number_of_stats == 1 and self.has_suffix_for_single_stat:
                            full_metric_name = metric_name
                        else:
                            full_metric_name = metric_name + '.' + short_name

                        wf_proxy.transmit_metric(
                            self.metric_name_prefix + full_metric_name,
                            stat[s],
                            command.unix_time_millis(stat['Timestamp']),
                            source,
                            point_tags)