@Override
  public Map<String, Metric> getMetrics() {
    final Map<String, Metric> gauges = new HashMap<String, Metric>();

    long cumulativeGCTime = 0L;

    for (final GarbageCollectorMXBean gc : garbageCollectors) {
      final String name = WHITESPACE.matcher(gc.getName()).replaceAll("-");

      gauges.put(name(name, "count"), new Gauge<Long>() {
        @Override
        public Long getValue() {
          return gc.getCollectionCount();
        }
      });

      gauges.put(name(name, "time"), new Gauge<Long>() {
        @Override
        public Long getValue() {
          return gc.getCollectionTime();
        }
      });

      cumulativeGCTime += gc.getCollectionTime();
    }

    final long uptime = ManagementFactory.getRuntimeMXBean().getUptime();
    final Double gc2UptimeRatio = (double)cumulativeGCTime / uptime;

    gauges.put("jvmUptime", new Gauge<Long>() {
      @Override
      public Long getValue() {
        return uptime;
      }
    });

    gauges.put("gc2UptimeRatio", new Gauge<Double>() {
      @Override
      public Double getValue() {
        return gc2UptimeRatio;
      }
    });

    return Collections.unmodifiableMap(gauges);
  }
@return Returns a map of defined gauges.
app/com/linkedin/drelephant/metrics/CustomGarbageCollectorMetricSet.java