Returns a {@code Metric} collected from {@link Timer}.

@param dropwizardMetric the metric name.
@param timer the timer object to collect
@return a {@code Metric}.
324127
private Metric collectTimer(MetricName dropwizardMetric, Timer timer) {
    String metricName = DropWizardUtils.generateFullMetricName(dropwizardMetric.getKey(), "timer");
    String metricDescription =
        DropWizardUtils.generateFullMetricDescription(dropwizardMetric.getKey(), timer);
    final AbstractMap.SimpleImmutableEntry<List<LabelKey>, List<LabelValue>> labels =
        DropWizardUtils.generateLabels(dropwizardMetric);
    return collectSnapshotAndCount(
        metricName,
        metricDescription,
        labels.getKey(),
        labels.getValue(),
        NS_UNIT,
        timer.getSnapshot(),
        timer.getCount());
  }
882871
public long getCooldownExpirationByTriggerAndMetric(Trigger trigger, Metric metric) {
    	String key = _hashTriggerAndMetric(trigger, metric);
		return this.cooldownExpirationByTriggerAndMetric.containsKey(key) ? this.cooldownExpirationByTriggerAndMetric.get(key) : 0;
    }
883968
public Double getMemoryMetric(ID metricToCollect) {

        GlobalMemory mem = getMemory();

        if (PlatformMetricType.MEMORY_AVAILABLE.getMetricTypeId().equals(metricToCollect)) {
            return Double.valueOf(mem.getAvailable());
        } else if (PlatformMetricType.MEMORY_TOTAL.getMetricTypeId().equals(metricToCollect)) {
            return Double.valueOf(mem.getTotal());
        } else {
            throw new UnsupportedOperationException("Invalid memory metric to collect: " + metricToCollect);
        }
    }
577177
static void flushMetricsLogger(final MetricsLogger metricsLogger) {
        metricsLogger.flushToString(MetricsManager::queue);
        MetricsManager.rootMetricsLogger.flushToString(MetricsManager::queue);
    }
1080354
@Override
    protected void collectMetrics(final Metrics metrics) {
        for (final JvmMetricsCollector collector : _collectorsEnabled) {
            collector.collect(metrics, _managementFactory);
        }
    }
1344111
public MetricFilter metricsFilter() {
        if (id() == null) {
            return (name, metric) -> false;
        }
        return (name, metric) -> metricNames.contains(name);

    }
206379
public static MetricContext getMetricContext(State state, Class<?> klazz) {
    return getMetricContext(state, klazz, new ArrayList<Tag<?>>());
  }
849598
@Override
  public SortedMap<String, Meter> getMeters(MetricFilter filter) {
    return this.innerMetricContext.getMeters(filter);
  }
230287
public Metric getMetric(String metricName) {
    // [START getMetric]
    Metric metric = logging.getMetric(metricName);
    if (metric == null) {
      // metric was not found
    }
    // [END getMetric]
    return metric;
  }
425700
MetricFamilySamples fromGauge(String dropwizardName, Gauge gauge) {
        Object obj = gauge.getValue();
        double value;
        if (obj instanceof Number) {
            value = ((Number) obj).doubleValue();
        } else if (obj instanceof Boolean) {
            value = ((Boolean) obj) ? 1 : 0;
        } else {
            LOGGER.log(Level.FINE, String.format("Invalid type for Gauge %s: %s", sanitizeMetricName(dropwizardName),
                    obj == null ? "null" : obj.getClass().getName()));
            return null;
        }
        MetricFamilySamples.Sample sample = sampleBuilder.createSample(dropwizardName, "",
                new ArrayList<String>(), new ArrayList<String>(), value);
        return new MetricFamilySamples(sample.name, Type.GAUGE, getHelpMessage(dropwizardName, gauge), Arrays.asList(sample));
    }
203830
MetricFamilySamples fromHistogram(String dropwizardName, Histogram histogram) {
        return fromSnapshotAndCount(dropwizardName, histogram.getSnapshot(), histogram.getCount(), 1.0,
                getHelpMessage(dropwizardName, histogram));
    }
1030090
public int getStatValueAsInteger(T metric, String interval) {
        if (metric.isRateMetric()) {
            return (int)(getStatValueAsDouble(metric, interval));
        }
        return getMonitoredStatValue(metric).getValueAsInt(interval);
    }
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;
  }
130125
@RequestMapping(method = RequestMethod.GET)
  public ApplicationRegistry getMetrics(@RequestParam Map<String, String> filters)
    throws IOException {
    boolean all = filters.get("all") != null;
    String filterMeterNameRegex = filters.getOrDefault("meterNameRegex", "");
    String filterTagNameRegex = filters.getOrDefault("tagNameRegex", "");
    String filterTagValueRegex = filters.getOrDefault("tagValueRegex", "");
    TagMeasurementFilter queryFilter = new TagMeasurementFilter(
        filterMeterNameRegex, filterTagNameRegex, filterTagValueRegex);
    Predicate<Measurement> filter;
    if (all) {
      filter = queryFilter;
    } else {
      filter = queryFilter.and(getDefaultMeasurementFilter());
    }

    ApplicationRegistry response = new ApplicationRegistry();
    response.setApplicationName(applicationName);
    response.setApplicationVersion(applicationVersion);
    response.setMetrics(encodeRegistry(registry, filter));
    return response;
  }
616562
public static Timer newTimer(MeterRegistry registry, String name, Iterable<Tag> tags) {
        requireNonNull(registry, "registry");
        requireNonNull(name, "name");
        requireNonNull(tags, "tags");

        final Duration maxExpectedValue =
                Optional.ofNullable(distStatCfg.getMaximumExpectedValue())
                        .map(Duration::ofNanos).orElse(null);
        final Duration minExpectedValue =
                Optional.ofNullable(distStatCfg.getMinimumExpectedValue())
                        .map(Duration::ofNanos).orElse(null);

        return Timer.builder(name)
                    .tags(tags)
                    .maximumExpectedValue(maxExpectedValue)
                    .minimumExpectedValue(minExpectedValue)
                    .publishPercentiles(distStatCfg.getPercentiles())
                    .publishPercentileHistogram(distStatCfg.isPercentileHistogram())
                    .distributionStatisticBufferLength(distStatCfg.getBufferLength())
                    .distributionStatisticExpiry(distStatCfg.getExpiry())
                    .register(registry);
    }
402003
private Metric collectMeter(MetricName dropwizardMetric, Meter meter) {
    String metricName = DropWizardUtils.generateFullMetricName(dropwizardMetric.getKey(), "meter");
    String metricDescription =
        DropWizardUtils.generateFullMetricDescription(dropwizardMetric.getKey(), meter);
    final AbstractMap.SimpleImmutableEntry<List<LabelKey>, List<LabelValue>> labels =
        DropWizardUtils.generateLabels(dropwizardMetric);

    MetricDescriptor metricDescriptor =
        MetricDescriptor.create(
            metricName, metricDescription, DEFAULT_UNIT, Type.CUMULATIVE_INT64, labels.getKey());
    TimeSeries timeSeries =
        TimeSeries.createWithOnePoint(
            labels.getValue(),
            Point.create(Value.longValue(meter.getCount()), clock.now()),
            cumulativeStartTimestamp);

    return Metric.createWithOneTimeSeries(metricDescriptor, timeSeries);
  }
130393
public static MetricsLogger getMetricsLogger(final String dimensions) {
        if (MetricsManager.instance != null) {
            final Map<String, String> dimensionsMap = DimensionsUtils.parseDimensions(dimensions);
            if (!dimensionsMap.isEmpty()) {
                dimensionsMap.put("service", MetricsManager.instance.serviceName);
                if (MetricsManager.instance.env.length() > 0) {
                    dimensionsMap.put("env", MetricsManager.instance.env);
                }
                return MetricsManager.instance.metricsLoggers.computeIfAbsent(
                        DimensionsUtils.serializeDimensionsToString(dimensionsMap), key -> new MetricsLogger(dimensionsMap));
            } else {
                throw new IllegalArgumentException("Dimensions must be valid and non-empty");
            }
        }
        return dummyLogger;
    }