Fetches the metric object corresponding to the given name.
197
def _GetMetric(self, metric_name):
    """"""
    if metric_name in self._counter_metrics:
      return self._counter_metrics[metric_name]
    elif metric_name in self._event_metrics:
      return self._event_metrics[metric_name]
    elif metric_name in self._gauge_metrics:
      return self._gauge_metrics[metric_name]
    else:
      raise ValueError("Metric %s is not registered." % metric_name)
674563
public function getMetric($name) {
        if (isset($this->metrics[$name])) {
            return $this->metrics[$name];
        }

        throw new MetricNotFoundException("Metric $name not found");
    }
451400
def query_metric_definition(self, metric_type, metric_id):
        
        return self._get(self._get_metrics_single_url(metric_type, metric_id))
411232
def _get_metrics_to_collect(self, instance_key, additional_metrics):
        
        if instance_key not in self.metrics_to_collect_by_instance:
            self.metrics_to_collect_by_instance[instance_key] = self._build_metric_list_to_collect(additional_metrics)
        return self.metrics_to_collect_by_instance[instance_key]
33338
public final void updateMetric(MetricName name, Object value) {
        if (!started) {
            return;
        }
        PcpValueInfo info = metricData.get(name);
        if (info == null) {
            throw new IllegalArgumentException("Metric " + name
                    + " was not added before initialising the writer");
        }
        updateValue(info, value);
    }
1046383
def _get_value_from_json(self, dict_path, metrics_json):
        
        for key in dict_path.split('.'):
            if key in metrics_json:
                metrics_json = metrics_json.get(key)
            else:
                return None
        return metrics_json
606658
private Deferred<Object> resolveMetric() {
    if (metric == null || metric.isEmpty()) {
      throw new IllegalArgumentException("The metric cannot be empty");
    }
    if (tags == null) {
      throw new IllegalArgumentException("Tags cannot be null or empty "
          + "when getting a TSUID");
    }
    
    class TagsCB implements Callback<Object, ArrayList<byte[]>> {
      @Override
      public Object call(final ArrayList<byte[]> tag_list) throws Exception {
        setTagUIDs(tag_list);
        return null;
      }
      @Override
      public String toString() {
        return "Tag resolution callback";
      }
    }
    
    class MetricCB implements Callback<Deferred<Object>, byte[]> {
      @Override
      public Deferred<Object> call(final byte[] uid) 
          throws Exception {
        setMetricUID(uid);
        if (tags.isEmpty()) {
          setTagUIDs(new ArrayList<byte[]>(0));
          return null;
        }
        return Tags.resolveAllAsync(tsdb, tags).addCallback(new TagsCB());
      }
      @Override
      public String toString() {
        return "Metric resolution callback";
      }
    }
    
    return tsdb.getUIDAsync(UniqueIdType.METRIC, metric)
        .addCallbackDeferring(new MetricCB());
  }
1164042
def _fetch_metric(self, metric_name):
        
        request = {
            'Namespace': self.CLOUDWATCH_NAMESPACE,
            'MetricName': metric_name,
            'Dimensions': [
                {
                    'Name': 'TrainingJobName',
                    'Value': self.name
                }
            ],
            'StartTime': self._time_interval['start_time'],
            'EndTime': self._time_interval['end_time'],
            'Period': self._period,
            'Statistics': ['Average'],
        }
        raw_cwm_data = self._cloudwatch.get_metric_statistics(**request)['Datapoints']
        if len(raw_cwm_data) == 0:
            logging.warning("Warning: No metrics called %s found" % metric_name)
            return

        # Process data: normalize to starting time, and sort.
        base_time = min(raw_cwm_data, key=lambda pt: pt['Timestamp'])['Timestamp']
        all_xy = []
        for pt in raw_cwm_data:
            y = pt['Average']
            x = (pt['Timestamp'] - base_time).total_seconds()
            all_xy.append([x, y])
        all_xy = sorted(all_xy, key=lambda x: x[0])

        # Store everything in _data to make a dataframe from
        for elapsed_seconds, value in all_xy:
            self._add_single_metric(elapsed_seconds, metric_name, value)
403045
private static String getWorkerMetricName(String name) {
    String result = CACHED_METRICS.get(name);
    if (result != null) {
      return result;
    }
    return CACHED_METRICS.computeIfAbsent(name,
        n -> getMetricNameWithUniqueId(InstanceType.WORKER, name));
  }
695380
def metric(slug, num=1, category=None, expire=None, date=None):
    """"""
    get_r().metric(slug, num=num, category=category, expire=expire, date=date)
994522
def _metric_unit_from_name(metric_name):
    
    for item in _PATTERN_UNIT_LIST:
        pattern, unit = item
        if pattern.match(metric_name):
            return unit
    return None
874207
def _extract_metric_from_map(self, _m, messages, obj_map, obj_help):
        
        _obj = metrics_pb2.MetricFamily()
        _obj.name = _m
        _obj.type = self.METRIC_TYPES.index(obj_map[_m])
        if _m in obj_help:
            _obj.help = obj_help[_m]
        # trick for histograms
        _newlbl = _m
        if obj_map[_m] == 'histogram':
            _newlbl = '{}_bucket'.format(_m)
        # Loop through the array of metrics ({labels, value}) built earlier
        for _metric in messages[_newlbl]:
            # in the case of quantiles and buckets, they need to be grouped by labels
            if obj_map[_m] in ['summary', 'histogram'] and len(_obj.metric) > 0:
                _label_exists = False
                _metric_minus = {k: v for k, v in list(iteritems(_metric['labels'])) if k not in ['quantile', 'le']}
                _metric_idx = 0
                for mls in _obj.metric:
                    _tmp_lbl = {idx.name: idx.value for idx in mls.label}
                    if _metric_minus == _tmp_lbl:
                        _label_exists = True
                        break
                    _metric_idx = _metric_idx + 1
                if _label_exists:
                    _g = _obj.metric[_metric_idx]
                else:
                    _g = _obj.metric.add()
            else:
                _g = _obj.metric.add()
            if obj_map[_m] == 'counter':
                _g.counter.value = float(_metric['value'])
            elif obj_map[_m] == 'gauge':
                _g.gauge.value = float(_metric['value'])
            elif obj_map[_m] == 'summary':
                if '{}_count'.format(_m) in messages:
                    _g.summary.sample_count = long(self.get_metric_value_by_labels(messages, _metric, _m, 'count'))
                if '{}_sum'.format(_m) in messages:
                    _g.summary.sample_sum = self.get_metric_value_by_labels(messages, _metric, _m, 'sum')
            # TODO: see what can be done with the untyped metrics
            elif obj_map[_m] == 'histogram':
                if '{}_count'.format(_m) in messages:
                    _g.histogram.sample_count = long(self.get_metric_value_by_labels(messages, _metric, _m, 'count'))
                if '{}_sum'.format(_m) in messages:
                    _g.histogram.sample_sum = self.get_metric_value_by_labels(messages, _metric, _m, 'sum')
            # last_metric = len(_obj.metric) - 1
            # if last_metric >= 0:
            for lbl in _metric['labels']:
                # In the string format, the quantiles are in the labels
                if lbl == 'quantile':
                    # _q = _obj.metric[last_metric].summary.quantile.add()
                    _q = _g.summary.quantile.add()
                    _q.quantile = float(_metric['labels'][lbl])
                    _q.value = float(_metric['value'])
                # The upper_bounds are stored as "le" labels on string format
                elif obj_map[_m] == 'histogram' and lbl == 'le':
                    # _q = _obj.metric[last_metric].histogram.bucket.add()
                    _q = _g.histogram.bucket.add()
                    _q.upper_bound = float(_metric['labels'][lbl])
                    _q.cumulative_count = long(float(_metric['value']))
                else:
                    # labels deduplication
                    is_in_labels = False
                    for _existing_lbl in _g.label:
                        if lbl == _existing_lbl.name:
                            is_in_labels = True
                    if not is_in_labels:
                        _l = _g.label.add()
                        _l.name = lbl
                        _l.value = _metric['labels'][lbl]
        return _obj
1344111
public MetricFilter metricsFilter() {
        if (id() == null) {
            return (name, metric) -> false;
        }
        return (name, metric) -> metricNames.contains(name);

    }
1299803
def get_metrics(tag):
    
    if tag is None:
        return metrics.metrics_by_name_list(metrics.metrics())
    else:
        return metrics.metrics_by_tag(tag)
462209
public static AsmMetric find(String name) {
        for (AsmMetricRegistry registry : allRegistries) {
            AsmMetric metric = registry.getMetric(name);
            if (metric != null) {
                return metric;
            }
        }
        return null;
    }
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;
  }
49394
async def get_metrics(self):
        
        metrics = await self.model.get_metrics(self.tag)
        return metrics[self.name]