Returns a list of MetricMetadata for GRR server components.
770020
def GetMetadata():
  """"""
  return [
      # GRR user-management metrics.
      stats_utils.CreateEventMetadata(
          "acl_check_time", fields=[("check_type", str)]),
      stats_utils.CreateCounterMetadata(
          "approval_searches",
          fields=[("reason_presence", str), ("source", str)]),

      # Cronjob metrics.
      stats_utils.CreateCounterMetadata("cron_internal_error"),
      stats_utils.CreateCounterMetadata(
          "cron_job_failure", fields=[("cron_job_id", str)]),
      stats_utils.CreateCounterMetadata(
          "cron_job_timeout", fields=[("cron_job_id", str)]),
      stats_utils.CreateEventMetadata(
          "cron_job_latency", fields=[("cron_job_id", str)]),

      # Access-control metrics.
      stats_utils.CreateCounterMetadata("grr_expired_tokens"),

      # Datastore metrics.
      stats_utils.CreateCounterMetadata("grr_commit_failure"),
      stats_utils.CreateCounterMetadata("datastore_retries"),
      stats_utils.CreateGaugeMetadata(
          "datastore_size",
          int,
          docstring="Size of data store in bytes",
          units="BYTES"),
      stats_utils.CreateCounterMetadata("grr_task_retransmission_count"),
      stats_utils.CreateCounterMetadata("grr_task_ttl_expired_count"),
      stats_utils.CreateEventMetadata(
          "db_request_latency",
          fields=[("call", str)],
          bins=[0.05 * 1.2**x for x in range(30)]),  # 50ms to ~10 secs
      stats_utils.CreateCounterMetadata(
          "db_request_errors", fields=[("call", str), ("type", str)]),

      # Threadpool metrics.
      stats_utils.CreateGaugeMetadata(
          "threadpool_outstanding_tasks", int, fields=[("pool_name", str)]),
      stats_utils.CreateGaugeMetadata(
          "threadpool_threads", int, fields=[("pool_name", str)]),
      stats_utils.CreateGaugeMetadata(
          "threadpool_cpu_use", float, fields=[("pool_name", str)]),
      stats_utils.CreateCounterMetadata(
          "threadpool_task_exceptions", fields=[("pool_name", str)]),
      stats_utils.CreateEventMetadata(
          "threadpool_working_time", fields=[("pool_name", str)]),
      stats_utils.CreateEventMetadata(
          "threadpool_queueing_time", fields=[("pool_name", str)]),

      # Worker and flow-related metrics.
      stats_utils.CreateCounterMetadata("grr_flows_stuck"),
      stats_utils.CreateCounterMetadata(
          "worker_bad_flow_objects", fields=[("type", str)]),
      stats_utils.CreateCounterMetadata(
          "worker_session_errors", fields=[("type", str)]),
      stats_utils.CreateCounterMetadata(
          "worker_flow_lock_error",
          docstring="Worker lock failures. We expect these to be high when the "
          "systemis idle."),
      stats_utils.CreateEventMetadata(
          "worker_flow_processing_time", fields=[("flow", str)]),
      stats_utils.CreateEventMetadata("worker_time_to_retrieve_notifications"),
      stats_utils.CreateCounterMetadata("grr_flow_completed_count"),
      stats_utils.CreateCounterMetadata("grr_flow_errors"),
      stats_utils.CreateCounterMetadata("grr_flow_invalid_flow_count"),
      stats_utils.CreateCounterMetadata("grr_request_retransmission_count"),
      stats_utils.CreateCounterMetadata("grr_response_out_of_order"),
      stats_utils.CreateCounterMetadata("grr_unique_clients"),
      stats_utils.CreateCounterMetadata("grr_worker_states_run"),
      stats_utils.CreateCounterMetadata("grr_well_known_flow_requests"),
      stats_utils.CreateCounterMetadata("flow_starts", fields=[("flow", str)]),
      stats_utils.CreateCounterMetadata("flow_errors", fields=[("flow", str)]),
      stats_utils.CreateCounterMetadata(
          "flow_completions", fields=[("flow", str)]),
      stats_utils.CreateCounterMetadata(
          "well_known_flow_requests", fields=[("flow", str)]),
      stats_utils.CreateCounterMetadata(
          "well_known_flow_errors", fields=[("flow", str)]),
      stats_utils.CreateEventMetadata("fleetspeak_last_ping_latency_millis"),

      # Hunt-related metrics.
      stats_utils.CreateCounterMetadata(
          "hunt_output_plugin_verifications", fields=[("status", str)]),
      stats_utils.CreateCounterMetadata(
          "hunt_output_plugin_verification_errors"),
      stats_utils.CreateCounterMetadata(
          "hunt_output_plugin_errors", fields=[("plugin", str)]),
      stats_utils.CreateCounterMetadata(
          "hunt_results_ran_through_plugin", fields=[("plugin", str)]),
      stats_utils.CreateCounterMetadata("hunt_results_compacted"),
      stats_utils.CreateCounterMetadata(
          "hunt_results_compaction_locking_errors"),
      stats_utils.CreateCounterMetadata("hunt_results_added"),

      # Metric used to identify the master in a distributed server setup.
      stats_utils.CreateGaugeMetadata("is_master", int),

      # GRR-API metrics.
      stats_utils.CreateEventMetadata(
          "api_method_latency",
          fields=[("method_name", str), ("protocol", str), ("status", str)]),
      stats_utils.CreateEventMetadata(
          "api_access_probe_latency",
          fields=[("method_name", str), ("protocol", str), ("status", str)]),

      # Client-related metrics.
      stats_utils.CreateCounterMetadata("grr_client_crashes"),
      stats_utils.CreateCounterMetadata(
          "client_pings_by_label", fields=[("label", str)]),

      # Metrics specific to GRR frontends.
      stats_utils.CreateGaugeMetadata(
          "frontend_active_count", int, fields=[("source", str)]),
      stats_utils.CreateGaugeMetadata("frontend_max_active_count", int),
      stats_utils.CreateCounterMetadata(
          "frontend_http_requests", fields=[("action", str), ("protocol",
                                                              str)]),
      stats_utils.CreateCounterMetadata(
          "frontend_in_bytes", fields=[("source", str)]),
      stats_utils.CreateCounterMetadata(
          "frontend_out_bytes", fields=[("source", str)]),
      stats_utils.CreateCounterMetadata(
          "frontend_request_count", fields=[("source", str)]),
      stats_utils.CreateCounterMetadata(
          "frontend_inactive_request_count", fields=[("source", str)]),
      stats_utils.CreateEventMetadata(
          "frontend_request_latency", fields=[("source", str)]),
      stats_utils.CreateEventMetadata("grr_frontendserver_handle_time"),
      stats_utils.CreateCounterMetadata("grr_frontendserver_handle_num"),
      stats_utils.CreateGaugeMetadata("grr_frontendserver_client_cache_size",
                                      int),
      stats_utils.CreateCounterMetadata("grr_messages_sent"),
      stats_utils.CreateCounterMetadata(
          "grr_pub_key_cache", fields=[("type", str)]),
  ]
131839
static Map<String, Double> processMetrics(String prefix, Iterable<MetricsInfo> metrics) {
    Map<String, Double> map = new HashMap<>();
    for (MetricsInfo r : metrics) {
      try {
        map.put(prefix + r.getName(), Double.valueOf(r.getValue()));
      } catch (NumberFormatException ne) {
        LOG.log(Level.SEVERE, "Could not parse metric, Name: "
            + r.getName() + " Value: " + r.getValue(), ne);
      }
    }
    return map;
  }
1058271
def process_metrics(self, snmp_data):
        ""
        self.metrics = {}
        for i in range(0, len(snmp_data)):
            mib_name = self.models[self.modem_type]['metrics'][i]
            conv = metric_mib[mib_name]['conv']
            self.metrics[mib_name] = conv(snmp_data[i])
993
static List<DataPoint> adapt(Metric metric) {
    MetricDescriptor metricDescriptor = metric.getMetricDescriptor();
    MetricType metricType = getType(metricDescriptor.getType());
    if (metricType == null) {
      return Collections.emptyList();
    }

    DataPoint.Builder shared = DataPoint.newBuilder();
    shared.setMetric(metricDescriptor.getName());
    shared.setMetricType(metricType);

    ArrayList<DataPoint> datapoints = Lists.newArrayList();
    for (TimeSeries timeSeries : metric.getTimeSeriesList()) {
      DataPoint.Builder builder = shared.clone();
      builder.addAllDimensions(
          createDimensions(metricDescriptor.getLabelKeys(), timeSeries.getLabelValues()));

      List<Point> points = timeSeries.getPoints();
      datapoints.ensureCapacity(datapoints.size() + points.size());
      for (Point point : points) {
        datapoints.add(builder.setValue(createDatum(point.getValue())).build());
      }
    }
    return datapoints;
  }
985671
def getMetadata(self, remote, address, key):
        """"""
        if self._server is not None:
            # pylint: disable=E1121
            return self._server.getAllMetadata(remote, address, key)
56641
def _cache_metrics_metadata(self, instance):
        
        # ## <TEST-INSTRUMENTATION>
        t = Timer()
        # ## </TEST-INSTRUMENTATION>

        i_key = self._instance_key(instance)
        self.metadata_cache.init_instance(i_key)
        self.log.info("Warming metrics metadata cache for instance {}".format(i_key))
        server_instance = self._get_server_instance(instance)
        perfManager = server_instance.content.perfManager
        custom_tags = instance.get('tags', [])

        new_metadata = {}
        metric_ids = []
        # Use old behaviour with metrics to collect defined by our constants
        if self.in_compatibility_mode(instance, log_warning=True):
            for counter in perfManager.perfCounter:
                metric_name = self.format_metric_name(counter, compatibility=True)
                new_metadata[counter.key] = {'name': metric_name, 'unit': counter.unitInfo.key}
                # Build the list of metrics we will want to collect
                if instance.get("all_metrics") or metric_name in BASIC_METRICS:
                    metric_ids.append(vim.PerformanceManager.MetricId(counterId=counter.key, instance="*"))
        else:
            collection_level = instance.get("collection_level", 1)
            for counter in perfManager.QueryPerfCounterByLevel(collection_level):
                new_metadata[counter.key] = {"name": self.format_metric_name(counter), "unit": counter.unitInfo.key}
                # Build the list of metrics we will want to collect
                metric_ids.append(vim.PerformanceManager.MetricId(counterId=counter.key, instance="*"))

        self.log.info("Finished metadata collection for instance {}".format(i_key))
        # Reset metadata
        self.metadata_cache.set_metadata(i_key, new_metadata)
        self.metadata_cache.set_metric_ids(i_key, metric_ids)

        self.cache_config.set_last(CacheConfig.Metadata, i_key, time.time())

        # ## <TEST-INSTRUMENTATION>
        self.histogram('datadog.agent.vsphere.metric_metadata_collection.time', t.total(), tags=custom_tags)
397868
def metric_parts(metric):
    """"""
    operator, met = resolve_metric_as_tuple(metric)
    return operator.name, met.name
289221
def _GetMetadataForClients(self, client_urns):
    """"""

    result = {}
    metadata_to_fetch = set()

    for urn in client_urns:
      try:
        result[urn] = self._cached_metadata[urn]
      except KeyError:
        metadata_to_fetch.add(urn)

    if metadata_to_fetch:
      if data_store.RelationalDBEnabled():
        client_ids = set(urn.Basename() for urn in metadata_to_fetch)
        infos = data_store.REL_DB.MultiReadClientFullInfo(client_ids)

        fetched_metadata = [
            export.GetMetadata(client_id, info)
            for client_id, info in infos.items()
        ]
      else:
        client_fds = aff4.FACTORY.MultiOpen(
            metadata_to_fetch, mode="r", token=self.token)

        fetched_metadata = [
            export.GetMetadataLegacy(client_fd, token=self.token)
            for client_fd in client_fds
        ]

      for metadata in fetched_metadata:
        metadata.source_urn = self.source_urn

        self._cached_metadata[metadata.client_urn] = metadata
        result[metadata.client_urn] = metadata
        metadata_to_fetch.remove(metadata.client_urn)

      for urn in metadata_to_fetch:
        default_mdata = export.ExportedMetadata(source_urn=self.source_urn)
        result[urn] = default_mdata
        self._cached_metadata[urn] = default_mdata

    return [result[urn] for urn in client_urns]
1343148
@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/metrics")
    @Description("Submits externally collected metric data.")
    public Map<String, Object> submitMetrics(@Context HttpServletRequest req, final List<MetricDto> metricDtos) {
        PrincipalUser remoteUser = getRemoteUser(req);

        SystemAssert.requireArgument(metricDtos != null, "Cannot submit null timeseries metrics list.");

        List<Metric> legalMetrics = new ArrayList<>();
        List<MetricDto> illegalMetrics = new ArrayList<>();
        List<String> errorMessages = new ArrayList<>();

        for (MetricDto metricDto : metricDtos) {
            try {
                Metric metric = new Metric(metricDto.getScope(), metricDto.getMetric());
                metric.setTags(metricDto.getTags());
                if (metricDto.getMetatags() != null) {
                    metric.setMetatagsRecord(new MetatagsRecord(metricDto.getMetatags(), metricDto.getMetatagsKey()));
                }

                copyProperties(metric, metricDto);
                legalMetrics.add(metric);
            } catch (Exception e) {
                illegalMetrics.add(metricDto);
                errorMessages.add(e.getMessage());
            }
        }
        _collectionService.submitMetrics(remoteUser, legalMetrics);

        Map<String, Object> result = new HashMap<>();

        result.put("Success", legalMetrics.size() + " metrics");
        result.put("Error", illegalMetrics.size() + " metrics");
        result.put("Error Messages", errorMessages);
        return result;
    }
630436
def metrics(self):
        
        masterThrp, backupThrp = self.getThroughputs(self.instances.masterId)
        r = self.instance_throughput_ratio(self.instances.masterId)
        m = [
            ("{} Monitor metrics:".format(self), None),
            ("Delta", self.Delta),
            ("Lambda", self.Lambda),
            ("Omega", self.Omega),
            ("instances started", self.instances.started),
            ("ordered request counts",
             {i: r[0] for i, r in self.numOrderedRequests.items()}),
            ("ordered request durations",
             {i: r[1] for i, r in self.numOrderedRequests.items()}),
            ("master request latencies", self.masterReqLatencies),
            ("client avg request latencies", {i: self.getLatency(i)
                                              for i in self.instances.ids}),
            ("throughput", {i: self.getThroughput(i)
                            for i in self.instances.ids}),
            ("master throughput", masterThrp),
            ("total requests", self.totalRequests),
            ("avg backup throughput", backupThrp),
            ("master throughput ratio", r)]
        return m
1265542
def _build_session_metric_values(self, session_name):
    """"""

    # result is a list of api_pb2.MetricValue instances.
    result = []
    metric_infos = self._experiment.metric_infos
    for metric_info in metric_infos:
      metric_name = metric_info.name
      try:
        metric_eval = metrics.last_metric_eval(
            self._context.multiplexer,
            session_name,
            metric_name)
      except KeyError:
        # It's ok if we don't find the metric in the session.
        # We skip it here. For filtering and sorting purposes its value is None.
        continue

      # metric_eval is a 3-tuple of the form [wall_time, step, value]
      result.append(api_pb2.MetricValue(name=metric_name,
                                        wall_time_secs=metric_eval[0],
                                        training_step=metric_eval[1],
                                        value=metric_eval[2]))
    return result
372291
def search_metrics(self, query, fromTime=None, toTime=None, requestedDataPoints=600, maxDataPoints=800):
        ''''''
        def millisectimestamp(ts):
            '''Convert UNIX timestamp to milliseconds'''
            if ts > 10**12:
                ts = ts/(10**(len(str(ts))-13))
            else:
                ts = ts*10**(12-len(str(ts)))
            return int(ts)

        params = {'query': [{"query":query, "rowId":"A"}],
                  'startTime': millisectimestamp(fromTime),
                  'endTime': millisectimestamp(toTime),
                  'requestedDataPoints': requestedDataPoints,
                  'maxDataPoints': maxDataPoints}
        r = self.post('/metrics/results', params)
        return json.loads(r.text)
710749
def _collect_metrics_async(self, instance, query_specs):
        
        # ## <TEST-INSTRUMENTATION>
        t = Timer()
        # ## </TEST-INSTRUMENTATION>
        i_key = self._instance_key(instance)
        server_instance = self._get_server_instance(instance)
        perfManager = server_instance.content.perfManager
        custom_tags = instance.get('tags', [])
        results = perfManager.QueryPerf(query_specs)
        if results:
            for mor_perfs in results:
                mor_name = str(mor_perfs.entity)
                try:
                    mor = self.mor_cache.get_mor(i_key, mor_name)
                except MorNotFoundError:
                    self.log.error(
                        "Trying to get metrics from object %s deleted from the cache, skipping. "
                        "Consider increasing the parameter `clean_morlist_interval` to avoid that",
                        mor_name,
                    )
                    continue

                for result in mor_perfs.value:
                    counter_id = result.id.counterId
                    if not self.metadata_cache.contains(i_key, counter_id):
                        self.log.debug(
                            "Skipping value for counter {}, because there is no metadata about it".format(
                                ensure_unicode(counter_id)
                            )
                        )
                        continue

                    # Metric types are absolute, delta, and rate
                    metric_name = self.metadata_cache.get_metadata(i_key, result.id.counterId).get('name')

                    if self.in_compatibility_mode(instance):
                        if metric_name not in ALL_METRICS:
                            self.log.debug("Skipping unknown `{}` metric.".format(ensure_unicode(metric_name)))
                            continue

                    if not result.value:
                        self.log.debug(
                            "Skipping `{}` metric because the value is empty".format(ensure_unicode(metric_name))
                        )
                        continue

                    instance_name = result.id.instance or "none"
                    value = self._transform_value(instance, result.id.counterId, result.value[0])

                    tags = ['instance:{}'.format(ensure_unicode(instance_name))]
                    if not mor['hostname']:  # no host tags available
                        tags.extend(mor['tags'])

                    # vsphere "rates" should be submitted as gauges (rate is
                    # precomputed).
                    self.gauge(
                        "vsphere.{}".format(ensure_unicode(metric_name)),
                        value,
                        hostname=mor['hostname'],
                        tags=tags + custom_tags,
                    )

        # ## <TEST-INSTRUMENTATION>
        self.histogram('datadog.agent.vsphere.metric_colection.time', t.total(), tags=custom_tags)
982134
def collect_metrics(local_evaluator=None,
                    remote_evaluators=[],
                    timeout_seconds=180):
    """"""

    episodes, num_dropped = collect_episodes(
        local_evaluator, remote_evaluators, timeout_seconds=timeout_seconds)
    metrics = summarize_episodes(episodes, episodes, num_dropped)
    return metrics
143686
def __get_metrics(self):
        
        esfilters_merge = None
        esfilters_abandon = None
        if self.esfilters:
            esfilters_merge = self.esfilters.copy()
            esfilters_abandon = self.esfilters.copy()

        merged = Merged(self.es_url, self.es_index,
                        start=self.start, end=self.end,
                        esfilters=esfilters_merge, interval=self.interval)

        abandoned = Abandoned(self.es_url, self.es_index,
                              start=self.start, end=self.end,
                              esfilters=esfilters_abandon, interval=self.interval)
        return (merged, abandoned)
895937
def metrics(self) -> list:
        
        my_metrics = [
            FramesMetric("frames"),
            FPSMetric("fps"),
            EpisodeRewardMetric('PMM:episode_rewards'),
            EpisodeRewardMetricQuantile('P09:episode_rewards', quantile=0.9),
            EpisodeRewardMetricQuantile('P01:episode_rewards', quantile=0.1),
            EpisodeLengthMetric("episode_length")
        ]

        return my_metrics + self.algo.metrics() + self.env_roller.metrics()
847943
def getAllMetadata(self, remote, address):
        """"""
        if self._server is not None:
            return self._server.getAllMetadata(remote, address)