Beispiel #1
0
 def get_monitoring_infos(self, cache_size, cache_capacity):
     # type: (int, int) -> List[metrics_pb2.MonitoringInfo]
     """Returns the metrics scoped to the current bundle."""
     metrics = self._context.metrics
     if len(metrics) == 0:
         # No metrics collected, do not report
         return []
     # Add all missing metrics which were not reported
     for key in Metrics.ALL_METRICS:
         if key not in metrics:
             metrics[key] = 0
     # Gauges which reflect the state since last queried
     gauges = [
         monitoring_infos.int64_gauge(self.PREFIX + name, val)
         for name, val in metrics.items()
     ]
     gauges.append(
         monitoring_infos.int64_gauge(self.PREFIX + 'size', cache_size))
     gauges.append(
         monitoring_infos.int64_gauge(self.PREFIX + 'capacity',
                                      cache_capacity))
     # Counters for the summary across all metrics
     counters = [
         monitoring_infos.int64_counter(self.PREFIX + name + '_total', val)
         for name, val in metrics.items()
     ]
     # Reinitialize metrics for this thread/bundle
     metrics.clear()
     return gauges + counters
Beispiel #2
0
    def to_runner_api_monitoring_infos(self, transform_id):
        """Returns a list of MonitoringInfos for the metrics in this container."""
        all_user_metrics = []
        for k, v in self.counters.items():
            all_user_metrics.append(
                monitoring_infos.int64_counter(
                    user_metric_urn(k.namespace, k.name),
                    v.to_runner_api_monitoring_info(),
                    ptransform=transform_id))

        for k, v in self.distributions.items():
            all_user_metrics.append(
                monitoring_infos.int64_distribution(
                    user_metric_urn(k.namespace, k.name),
                    v.get_cumulative().to_runner_api_monitoring_info(),
                    ptransform=transform_id))

        for k, v in self.gauges.items():
            all_user_metrics.append(
                monitoring_infos.int64_gauge(
                    user_metric_urn(k.namespace, k.name),
                    v.get_cumulative().to_runner_api_monitoring_info(),
                    ptransform=transform_id))
        return {monitoring_infos.to_key(mi): mi for mi in all_user_metrics}
Beispiel #3
0
  def to_runner_api_monitoring_infos(self, transform_id):
    """Returns a list of MonitoringInfos for the metrics in this container."""
    all_user_metrics = []
    for k, v in self.counters.items():
      all_user_metrics.append(monitoring_infos.int64_counter(
          user_metric_urn(k.namespace, k.name),
          v.to_runner_api_monitoring_info(),
          ptransform=transform_id
      ))

    for k, v in self.distributions.items():
      all_user_metrics.append(monitoring_infos.int64_distribution(
          user_distribution_metric_urn(k.namespace, k.name),
          v.get_cumulative().to_runner_api_monitoring_info(),
          ptransform=transform_id
      ))

    for k, v in self.gauges.items():
      all_user_metrics.append(monitoring_infos.int64_gauge(
          user_metric_urn(k.namespace, k.name),
          v.get_cumulative().to_runner_api_monitoring_info(),
          ptransform=transform_id
      ))
    return {monitoring_infos.to_key(mi) : mi for mi in all_user_metrics}