@Test public void testExportCounter() { AlibabaMetricsExports exports = new AlibabaMetricsExports(clock); Counter c1 = new BucketCounterImpl(1, 5, clock); MetricManager.getIMetricManager().register("test", MetricName.build("prom.test.counter").level(MetricLevel.CRITICAL), c1); for (int i = 0; i < 10; i++) { c1.inc(); } clock.addSeconds(1); List<Collector.MetricFamilySamples> samples = exports.collect(); Assert.assertEquals(2, samples.size()); Assert.assertEquals("prom_test_counter_count", samples.get(0).name); Assert.assertEquals(10, samples.get(0).samples.get(0).value, 0.0001d); Assert.assertEquals("prom_test_counter_bucket_count", samples.get(1).name); Assert.assertEquals(10, samples.get(1).samples.get(0).value, 0.0001d); }
@Override public List<MetricFamilySamples> collect() { List<String> groups = MetricManager.getIMetricManager().listMetricGroups(); List<MetricFamilySamples> samples = new ArrayList<MetricFamilySamples>(); long curTs = clock.getTime(); for (String group : groups) { MetricRegistry metricRegistry = MetricManager.getIMetricManager().getMetricRegistryByGroup(group); for (Map.Entry<MetricName, Counter> entry : metricRegistry.getCounters().entrySet()) { fromCounter(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Meter> entry : metricRegistry.getMeters().entrySet()) { fromMeter(samples, entry.getKey(), entry.getValue(), curTs, true); } for (Map.Entry<MetricName, Gauge> entry : metricRegistry.getGauges().entrySet()) { fromGauge(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, Timer> entry : metricRegistry.getTimers().entrySet()) { fromTimer(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Histogram> entry : metricRegistry.getHistograms().entrySet()) { fromHistogram(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, ClusterHistogram> entry : metricRegistry.getClusterHistograms().entrySet()) { fromClusterHistogram(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Compass> entry : metricRegistry.getCompasses().entrySet()) { fromCompass(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, FastCompass> entry : metricRegistry.getFastCompasses().entrySet()) { fromFastCompass(samples, entry.getKey(), entry.getValue(), curTs); } } return samples; }
AlibabaMetricsExports extends Collector { @Override public List<MetricFamilySamples> collect() { List<String> groups = MetricManager.getIMetricManager().listMetricGroups(); List<MetricFamilySamples> samples = new ArrayList<MetricFamilySamples>(); long curTs = clock.getTime(); for (String group : groups) { MetricRegistry metricRegistry = MetricManager.getIMetricManager().getMetricRegistryByGroup(group); for (Map.Entry<MetricName, Counter> entry : metricRegistry.getCounters().entrySet()) { fromCounter(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Meter> entry : metricRegistry.getMeters().entrySet()) { fromMeter(samples, entry.getKey(), entry.getValue(), curTs, true); } for (Map.Entry<MetricName, Gauge> entry : metricRegistry.getGauges().entrySet()) { fromGauge(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, Timer> entry : metricRegistry.getTimers().entrySet()) { fromTimer(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Histogram> entry : metricRegistry.getHistograms().entrySet()) { fromHistogram(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, ClusterHistogram> entry : metricRegistry.getClusterHistograms().entrySet()) { fromClusterHistogram(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Compass> entry : metricRegistry.getCompasses().entrySet()) { fromCompass(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, FastCompass> entry : metricRegistry.getFastCompasses().entrySet()) { fromFastCompass(samples, entry.getKey(), entry.getValue(), curTs); } } return samples; } }
AlibabaMetricsExports extends Collector { @Override public List<MetricFamilySamples> collect() { List<String> groups = MetricManager.getIMetricManager().listMetricGroups(); List<MetricFamilySamples> samples = new ArrayList<MetricFamilySamples>(); long curTs = clock.getTime(); for (String group : groups) { MetricRegistry metricRegistry = MetricManager.getIMetricManager().getMetricRegistryByGroup(group); for (Map.Entry<MetricName, Counter> entry : metricRegistry.getCounters().entrySet()) { fromCounter(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Meter> entry : metricRegistry.getMeters().entrySet()) { fromMeter(samples, entry.getKey(), entry.getValue(), curTs, true); } for (Map.Entry<MetricName, Gauge> entry : metricRegistry.getGauges().entrySet()) { fromGauge(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, Timer> entry : metricRegistry.getTimers().entrySet()) { fromTimer(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Histogram> entry : metricRegistry.getHistograms().entrySet()) { fromHistogram(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, ClusterHistogram> entry : metricRegistry.getClusterHistograms().entrySet()) { fromClusterHistogram(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Compass> entry : metricRegistry.getCompasses().entrySet()) { fromCompass(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, FastCompass> entry : metricRegistry.getFastCompasses().entrySet()) { fromFastCompass(samples, entry.getKey(), entry.getValue(), curTs); } } return samples; } AlibabaMetricsExports();  AlibabaMetricsExports(Clock clock); }
AlibabaMetricsExports extends Collector { @Override public List<MetricFamilySamples> collect() { List<String> groups = MetricManager.getIMetricManager().listMetricGroups(); List<MetricFamilySamples> samples = new ArrayList<MetricFamilySamples>(); long curTs = clock.getTime(); for (String group : groups) { MetricRegistry metricRegistry = MetricManager.getIMetricManager().getMetricRegistryByGroup(group); for (Map.Entry<MetricName, Counter> entry : metricRegistry.getCounters().entrySet()) { fromCounter(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Meter> entry : metricRegistry.getMeters().entrySet()) { fromMeter(samples, entry.getKey(), entry.getValue(), curTs, true); } for (Map.Entry<MetricName, Gauge> entry : metricRegistry.getGauges().entrySet()) { fromGauge(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, Timer> entry : metricRegistry.getTimers().entrySet()) { fromTimer(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Histogram> entry : metricRegistry.getHistograms().entrySet()) { fromHistogram(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, ClusterHistogram> entry : metricRegistry.getClusterHistograms().entrySet()) { fromClusterHistogram(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Compass> entry : metricRegistry.getCompasses().entrySet()) { fromCompass(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, FastCompass> entry : metricRegistry.getFastCompasses().entrySet()) { fromFastCompass(samples, entry.getKey(), entry.getValue(), curTs); } } return samples; } AlibabaMetricsExports();  AlibabaMetricsExports(Clock clock); @Override List<MetricFamilySamples> collect(); void fromCounter(List<MetricFamilySamples> samples, MetricName metricName, Counter counter, long timestamp); void fromGauge(List<MetricFamilySamples> samples, MetricName metricName, Gauge gauge); void fromTimer(List<MetricFamilySamples> samples, MetricName metricName, Timer timer, long timestamp); void fromMeter(List<MetricFamilySamples> samples, MetricName metricName, Metered meter, long timestamp,
                          boolean collectBucketCount); void fromHistogram(List<MetricFamilySamples> samples, MetricName metricName, Histogram histogram); void fromClusterHistogram(List<MetricFamilySamples> samples, MetricName metricName,
                                     ClusterHistogram clusterHistogram, long timestamp); void fromCompass(List<MetricFamilySamples> samples, MetricName metricName, Compass compass, long timestamp); void fromFastCompass(List<MetricFamilySamples> samples, MetricName metricName,
                                FastCompass fastCompass, long timestamp); }
AlibabaMetricsExports extends Collector { @Override public List<MetricFamilySamples> collect() { List<String> groups = MetricManager.getIMetricManager().listMetricGroups(); List<MetricFamilySamples> samples = new ArrayList<MetricFamilySamples>(); long curTs = clock.getTime(); for (String group : groups) { MetricRegistry metricRegistry = MetricManager.getIMetricManager().getMetricRegistryByGroup(group); for (Map.Entry<MetricName, Counter> entry : metricRegistry.getCounters().entrySet()) { fromCounter(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Meter> entry : metricRegistry.getMeters().entrySet()) { fromMeter(samples, entry.getKey(), entry.getValue(), curTs, true); } for (Map.Entry<MetricName, Gauge> entry : metricRegistry.getGauges().entrySet()) { fromGauge(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, Timer> entry : metricRegistry.getTimers().entrySet()) { fromTimer(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Histogram> entry : metricRegistry.getHistograms().entrySet()) { fromHistogram(samples, entry.getKey(), entry.getValue()); } for (Map.Entry<MetricName, ClusterHistogram> entry : metricRegistry.getClusterHistograms().entrySet()) { fromClusterHistogram(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, Compass> entry : metricRegistry.getCompasses().entrySet()) { fromCompass(samples, entry.getKey(), entry.getValue(), curTs); } for (Map.Entry<MetricName, FastCompass> entry : metricRegistry.getFastCompasses().entrySet()) { fromFastCompass(samples, entry.getKey(), entry.getValue(), curTs); } } return samples; } AlibabaMetricsExports();  AlibabaMetricsExports(Clock clock); @Override List<MetricFamilySamples> collect(); void fromCounter(List<MetricFamilySamples> samples, MetricName metricName, Counter counter, long timestamp); void fromGauge(List<MetricFamilySamples> samples, MetricName metricName, Gauge gauge); void fromTimer(List<MetricFamilySamples> samples, MetricName metricName, Timer timer, long timestamp); void fromMeter(List<MetricFamilySamples> samples, MetricName metricName, Metered meter, long timestamp,
                          boolean collectBucketCount); void fromHistogram(List<MetricFamilySamples> samples, MetricName metricName, Histogram histogram); void fromClusterHistogram(List<MetricFamilySamples> samples, MetricName metricName,
                                     ClusterHistogram clusterHistogram, long timestamp); void fromCompass(List<MetricFamilySamples> samples, MetricName metricName, Compass compass, long timestamp); void fromFastCompass(List<MetricFamilySamples> samples, MetricName metricName,
                                FastCompass fastCompass, long timestamp);  }