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

@param dropwizardName the metric name.
@param gauge the gauge object to collect.
@return a {@code Metric}.
436979
@SuppressWarnings("rawtypes")
  @Nullable
  private Metric collectGauge(String dropwizardName, Gauge gauge) {
    String metricName = DropWizardUtils.generateFullMetricName(dropwizardName, "gauge");
    String metricDescription = DropWizardUtils.generateFullMetricDescription(dropwizardName, gauge);

    // Figure out which gauge instance and call the right method to get value
    Type type;
    Value value;

    Object obj = gauge.getValue();
    if (obj instanceof Number) {
      type = Type.GAUGE_DOUBLE;
      value = Value.doubleValue(((Number) obj).doubleValue());
    } else if (obj instanceof Boolean) {
      type = Type.GAUGE_INT64;
      value = Value.longValue(((Boolean) obj) ? 1 : 0);
    } else {
      // Ignoring Gauge (gauge.getKey()) with unhandled type.
      return null;
    }

    MetricDescriptor metricDescriptor =
        MetricDescriptor.create(
            metricName, metricDescription, DEFAULT_UNIT, type, Collections.<LabelKey>emptyList());
    TimeSeries timeSeries =
        TimeSeries.createWithOnePoint(
            Collections.<LabelValue>emptyList(), Point.create(value, clock.now()), null);
    return Metric.createWithOneTimeSeries(metricDescriptor, timeSeries);
  }
1166233
public static DropwizardMeterRegistry newRegistry(MetricRegistry registry,
                                                      HierarchicalNameMapper nameMapper) {
        return newRegistry(registry, nameMapper, Clock.SYSTEM);
    }
309165
def gauge(self, name, producer):
        
        return self._get_or_add_stat(name, functools.partial(Gauge, producer))
711208
@Override
    public Meter meter(String name) {
        return this.meter(new Metadata(name, MetricType.METERED));
    }
1343161
public static Meter meter(MetricLevel level, String name) {
    return getMetricRegistry(level).meter(METRIC_PREFIX + name);
  }
1227186
static String metricName(final TSDB tsdb, final byte[] row) {
    try {
      return metricNameAsync(tsdb, row).joinUninterruptibly();
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException("Should never be here", e);
    }
  }
1019633
Stream<String> writeGauge(Gauge gauge) {
        Double value = gauge.value();
        if (Double.isFinite(value)) {
            return Stream.of(writeMetric(gauge.getId(), config().clock().wallTime(), value));
        }
        return Stream.empty();
    }
648710
public ResourceMetadata getResourceMetadata() {
    if (poolInfo.getPoolName() == null ||
        !counters.containsKey(MetricName.MIN) ||
        !counters.containsKey(MetricName.MAX) ||
        !counters.containsKey(MetricName.GRANTED) ||
        !counters.containsKey(MetricName.REQUESTED)) {
      return null;
    }

    return new ResourceMetadata(
        PoolInfo.createStringFromPoolInfo(poolInfo),
        counters.get(MetricName.MIN).intValue(),
        counters.get(MetricName.MAX).intValue(),
        counters.get(MetricName.GRANTED).intValue(),
        counters.get(MetricName.REQUESTED).intValue());
  }
244655
@Override
    public final Collection<Metric> gatherMetrics(final ICommandLine cl) throws MetricGatheringException {
        List<Metric> metrics = new ArrayList<Metric>();
        String hostname = cl.getOptionValue("hostname");
        if (hostname == null) {
            throw new MetricGatheringException("No hostname specified.", Status.WARNING, null);
        }

        String port = cl.getOptionValue("port", DEFAULT_PORT);
        String path = cl.getOptionValue("url", DEFAULT_PATH);
        String method = cl.getOptionValue("method", DEFAULT_METHOD);

        int timeout = DEFAULT_TIMEOUT;
        if (cl.hasOption("post")) {
            method = "POST";
        }
        boolean ssl = false;
        if (cl.hasOption("ssl") || cl.getOptionValue("certificate") != null) {
            port = cl.getOptionValue("ssl", DEFAULT_SSL_PORT);
            ssl = true;
        }

        if (cl.hasOption("timeout")) {
            try {
                timeout = Integer.parseInt(cl.getOptionValue("timeout"));
            } catch (NumberFormatException e) {
                throw new MetricGatheringException("Invalid numeric value for timeout.", Status.CRITICAL, e);
            }
        }
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        if (hostname.endsWith("/")) {
            hostname = hostname.substring(0, hostname.length() - 1);
        }

        long then = System.currentTimeMillis();

        String response = getHttpResponse(cl, hostname, port, method, path, timeout, ssl, metrics);
        int elapsed = (int) Utils.milliToSec(System.currentTimeMillis() - then);
        if (response != null) {
            metrics.addAll(analyzeResponse(cl, response, elapsed));
        }
        return metrics;
    }
948993
public IMetric<?> getMetricFromName(final String name) {
    IMetric<?> metric = null;
    if (name != null) {
      for (final IMetric<?> currentMetric : this.metrics) {
        if (currentMetric.getName().equals(name)) {
          metric = currentMetric;
          break;
        }
      }
    }
    return metric;
  }
843151
@Bean
    public MeterRegistry consoleLoggingRegistry(MetricRegistry dropwizardRegistry) {
        DropwizardConfig dropwizardConfig = new DropwizardConfig() {
            @Override
            public String prefix() {
                return "console";
            }

            @Override
            public String get(String key) {
                return null;
            }
        };

        return new DropwizardMeterRegistry(dropwizardConfig, dropwizardRegistry, HierarchicalNameMapper.DEFAULT, Clock.SYSTEM) {
            @Override
            protected Double nullGaugeValue() {
                return null;
            }
        };
    }
1100771
@NonNull
  public static Drop dropIndex(@NonNull String indexName) {
    return dropIndex(CqlIdentifier.fromCql(indexName));
  }
849598
@Override
  public SortedMap<String, Meter> getMeters(MetricFilter filter) {
    return this.innerMetricContext.getMeters(filter);
  }
758652
public Metric createMetricAsync(String metricName)
      throws ExecutionException, InterruptedException {
    // [START createMetricAsync]
    MetricInfo metricInfo = MetricInfo.of(metricName, "severity>=ERROR");
    Future<Metric> future = logging.createAsync(metricInfo);
    // ...
    Metric metric = future.get();
    // [END createMetricAsync]
    return metric;
  }
1222970
private Metric<Double> findCounter(@PathVariable("name") String name) {
		@SuppressWarnings("unchecked")
		Metric<Double> c = (Metric<Double>) metricRepository.findOne(COUNTER_PREFIX + name);
		if (c == null) {
			throw new NoSuchMetricException(name);
		}
		return c;
	}
683240
public static MetricsContext getContext(String refName, String contextName) {
    MetricsContext metricsContext;
    try {
      metricsContext =
        ContextFactory.getFactory().getContext(refName, contextName);
      if (!metricsContext.isMonitoring()) {
        metricsContext.startMonitoring();
      }
    } catch (Exception ex) {
      LOG.error("Unable to create metrics context " + contextName, ex);
      metricsContext = ContextFactory.getNullContext(contextName);
    }
    return metricsContext;
  }
974450
private Metric collectHistogram(MetricName dropwizardMetric, Histogram histogram) {
    String metricName =
        DropWizardUtils.generateFullMetricName(dropwizardMetric.getKey(), "histogram");
    String metricDescription =
        DropWizardUtils.generateFullMetricDescription(dropwizardMetric.getKey(), histogram);
    final AbstractMap.SimpleImmutableEntry<List<LabelKey>, List<LabelValue>> labels =
        DropWizardUtils.generateLabels(dropwizardMetric);

    return collectSnapshotAndCount(
        metricName,
        metricDescription,
        labels.getKey(),
        labels.getValue(),
        DEFAULT_UNIT,
        histogram.getSnapshot(),
        histogram.getCount());
  }