Returns the metric indicator depending on the metric type

@param AbstractMetric $metric

@return string
489430
protected function getMetricIndicator(AbstractMetric $metric)
    {
        switch ($metric->getType()) {
            case Set::TYPE:       return 's';
            case Gauge::TYPE:     return 'g';
            case Timer::TYPE:     return 'ms';
            case Counter::TYPE:   return 'c';
            case Histogram::TYPE: return 'h';

            default:
                throw new \InvalidArgumentException('Metric type is not a valid DataDog metric: '.$metric->getType());
        }
    }
979158
public function data($metrics = [])
    {
        if (func_num_args() === 0) {
            return $this->_metrics;
        }

        $this->_metrics = $metrics + $this->_metrics;

        if ($this->_metrics['lloc']) {
            $this->_metrics['percent'] = ($this->_metrics['cloc'] * 100) / $this->_metrics['lloc'];
        } else {
            $this->_metrics['percent'] = 100;
        }
    }
529102
@Get("/metrics")
  @ProducesJson
  public ObjectNode fetchMetricsFromMicrometer() {
    ObjectNode metricsJson = factory.objectNode();
    // Get the Zipkin Custom meters for constructing the Metrics endpoint
    for (Meter meter : meterRegistry.getMeters()) {
      String name = meter.getId().getName();
      if (!name.startsWith("zipkin_collector")) continue;
      String transport = meter.getId().getTag("transport");
      if (transport == null) continue;
      switch (meter.getId().getType()) {
        case COUNTER:
          metricsJson.put("counter." + name + "." + transport,
            ((Counter) meter).count());
          continue;
        case GAUGE:
          metricsJson.put("gauge." + name + "." + transport,
            ((Gauge) meter).value());
      }
    }
    return metricsJson;
  }
1173036
public function getMetrics()
    {
        if ($this->metrics === null) {
            $this->metrics = new Metrics($this->coverage);
        }

        return $this->metrics;
    }
1082719
public function send(AbstractMetric $metric)
    {
        $data = $this->getData($metric);
        $tags = array_merge($data, $metric->getTags());
        $this->logger->log($this->level, $this->getMessage($data), $tags);
    }
674820
protected function getMetricsToggles()
    {
        $i = 0;
        $metrics = array();
        foreach ($this->availableMetrics as $metric => $metricData) {
            $unit = Metrics::getUnit($metric, $this->idSite);
            $change = isset($metricData['change']) ? $metricData['change'] : false;

            list($first, $last) = $this->getFirstAndLastDataPointsForMetric($metric);
            $fractionDigits = max($this->getFractionDigits($first), $this->getFractionDigits($last));

            $details = Piwik::translate('RowEvolution_MetricBetweenText', array(
                NumberFormatter::getInstance()->format($first, $fractionDigits, $fractionDigits) . $unit,
                NumberFormatter::getInstance()->format($last, $fractionDigits, $fractionDigits) . $unit,
            ));

            if ($change !== false) {
                $lowerIsBetter = Metrics::isLowerValueBetter($metric);
                if (substr($change, 0, 1) == '+') {
                    $changeClass = $lowerIsBetter ? 'bad' : 'good';
                    $changeImage = $lowerIsBetter ? 'arrow_up_red' : 'arrow_up';
                } else if (substr($change, 0, 1) == '-') {
                    $changeClass = $lowerIsBetter ? 'good' : 'bad';
                    $changeImage = $lowerIsBetter ? 'arrow_down_green' : 'arrow_down';
                } else {
                    $changeClass = 'neutral';
                    $changeImage = false;
                }

                $change = '<span class="' . $changeClass . '">'
                    . ($changeImage ? '<img src="plugins/MultiSites/images/' . $changeImage . '.png" /> ' : '')
                    . $change . '</span>';

                $details .= ', ' . Piwik::translate('RowEvolution_MetricChangeText', $change);
            }

            // set metric min/max text (used as tooltip for details)
            $max = isset($metricData['max']) ? $metricData['max'] : 0;
            $min = isset($metricData['min']) ? $metricData['min'] : 0;
            $minmax = Piwik::translate('RowEvolution_MetricMinMax', array(
                $metricData['name'],
                NumberFormatter::getInstance()->formatNumber($min, $fractionDigits, $fractionDigits) . $unit,
                NumberFormatter::getInstance()->formatNumber($max, $fractionDigits, $fractionDigits) . $unit,
            ));

            $newMetric = array(
                'label'     => $metricData['name'],
                'details'   => $details,
                'minmax'    => $minmax,
                'sparkline' => $this->getSparkline($metric),
            );
            // Multi Rows, each metric can be for a particular row and display an icon
            if (!empty($metricData['logo'])) {
                $newMetric['logo'] = $metricData['logo'];
            }

            // TODO: this check should be determined by metric metadata, not hardcoded here
            if ($metric == 'nb_users'
                && $first == 0
                && $last == 0
            ) {
                $newMetric['hide'] = true;
            }

            $metrics[] = $newMetric;
            $i++;
        }

        return $metrics;
    }
705413
public function getSum($metric, $tags, $endDt = null) {
        if (null == $metric) {
            return 0;
        }
        
        $min = intval(date('i'));
        $minutes = $min > 45 ? 45 : ( $min > 30 ? 30 : ( $min > 15 ? 15 : '00') );       
        $lastHourDt = date("Y-m-d") . "T" . date('H') . ":$minutes:00Z";
  
        $where = [];
        
        if (!isset($endDt)) {
            $endDt = '2100-01-01T00:00:00Z';
        }
        
        if (strtotime($endDt) < strtotime($lastHourDt)) {
           return 0;
        }
        
        $where[] = "time >= '" . $lastHourDt . "' AND time <= '" . $endDt . "'";
        
        foreach ($tags as $key => $val) {
            $where[] = "$key = '" . $val . "'";
        }

        $points = $this->db->getQueryBuilder()
                ->from($metric)
                ->where($where)
                ->sum('value')
                ->getResultSet()
                ->getPoints();
        
        return isset($points[0]) && isset($points[0]["sum"]) ? $points[0]["sum"] : 0;
    }
409701
public function update(Metric $metric)
    {
        try {
            $metric = execute(new UpdateMetricCommand(
                $metric,
                Binput::get('name'),
                Binput::get('suffix'),
                Binput::get('description'),
                Binput::get('default_value'),
                Binput::get('calc_type'),
                Binput::get('display_chart'),
                Binput::get('places'),
                Binput::get('default_view', Binput::get('view')),
                Binput::get('threshold'),
                Binput::get('order'),
                Binput::get('visible')
            ));
        } catch (QueryException $e) {
            throw new BadRequestHttpException();
        }

        return $this->item($metric);
    }
190468
public com.google.protobuf.ByteString
      getMetricBytes() {
    java.lang.Object ref = metric_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      metric_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
405063
public function removeMetric($name) {
        if (isset($this->metrics[$name])) {
            unset($this->metrics[$name]);

            return $this;
        }

        throw new MetricNotFoundException("Metric $name not found");
    }
576053
public function gauge($metric, $level, array $tags = array(), $sampleRate = AbstractMetric::DEFAULT_SAMPLE_RATE)
    {
        return new Gauge($this->prefix($metric), $level, array_merge($this->defaultTags, $tags), $sampleRate);
    }
1135317
protected function getConcrete($abstract)
	{
		if ( ! is_null($concrete = $this->getContextualConcrete($abstract)))
		{
			return $concrete;
		}

		// If we don't have a registered resolver or concrete for the type, we'll just
		// assume each type is a concrete name and will attempt to resolve it as is
		// since the container should be able to resolve concretes automatically.
		if ( ! isset($this->bindings[$abstract]))
		{
			if ($this->missingLeadingSlash($abstract) &&
				isset($this->bindings['\\'.$abstract]))
			{
				$abstract = '\\'.$abstract;
			}

			return $abstract;
		}

		return $this->bindings[$abstract]['concrete'];
	}
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)
1081155
public Object getMetric(String key) throws MetricsException {
		MetricsKey mk = new MetricsKey(key);
		MetricsProvider provider = getProvider(mk.getProvider());
		return provider.getValue(mk);
	}
1148512
protected function getSparkline($metric)
    {
        // sparkline is always echoed, so we need to buffer the output
        $view = $this->getRowEvolutionGraph($graphType = 'sparkline', $metrics = array($metric => $metric));

        ob_start();
        $view->render();
        $spark = ob_get_contents();
        ob_end_clean();

        // undo header change by sparkline renderer
        Common::sendHeader('Content-type: text/html');

        // base64 encode the image and put it in an img tag
        $spark = base64_encode($spark);
        return '<img width="100" height="25" src="data:image/png;base64,' . $spark . '" />';
    }
41536
protected function recurse(array $metrics)
    {
        $flat = array();
        $metrics = (array) $metrics;

        foreach ($metrics as $metric => $value) {
            // name & children are meta data, not metrics
            if (!in_array($metric, array('name', 'children'))) {
                $name = isset($metrics['name']) ? $metrics['name'] : '';
                $flat[$metric][$name] = $value;
            }
        }

        if (isset($metrics['children'])) {
            foreach ($metrics['children'] as $child) {
                $childTotals = $this->recurse($child);
                $flat = array_merge_recursive($flat, $childTotals);
            }
        }

        foreach ($flat as $metric => $data) {
            // array_merge_recursive will merge into an array of values if there
            // are multiple things with the same name, in which case we'll just
            // go with the last occurrence
            $flat[$metric] = array_map(function ($value) {
                return is_array($value) ? array_pop($value) : $value;
            }, $flat[$metric]);
        }

        return $flat;
    }
674563
public function getMetric($name) {
        if (isset($this->metrics[$name])) {
            return $this->metrics[$name];
        }

        throw new MetricNotFoundException("Metric $name not found");
    }