@Test public void testWithTags() throws IOException { try ( MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName() + ".testGraphiteReporter") .addTag(new Tag<String>("taskId", "task_testjob_123")) .addTag(new Tag<String>("forkBranchName", "fork_1")).build(); GraphiteReporter graphiteReporter = GraphiteReporter.Factory.newBuilder() .withGraphitePusher(graphitePusher) .withMetricContextName(CONTEXT_NAME) .build(new Properties());) { Counter counter = metricContext.counter(MetricRegistry.name(METRIC_PREFIX, COUNTER)); counter.inc(5l); graphiteReporter.report(new TreeMap<String, Gauge>(), metricContext.getCounters(), new TreeMap<String, Histogram>(), new TreeMap<String, Meter>(), new TreeMap<String, Timer>(), metricContext.getTagMap()); Assert.assertEquals(getMetricValue("task_testjob_123.fork_1." + METRIC_PREFIX, COUNTER, Measurements.COUNT), Long.toString(5l)); } }
@Override protected void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers, Map<String, Object> tags) { String prefix = getMetricNamePrefix(tags); long timestamp = System.currentTimeMillis() / 1000l; try { for (Map.Entry<String, Gauge> gauge : gauges.entrySet()) { reportGauge(prefix, gauge.getKey(), gauge.getValue(), timestamp); } for (Map.Entry<String, Counter> counter : counters.entrySet()) { reportCounter(prefix, counter.getKey(), counter.getValue(), timestamp); } for (Map.Entry<String, Histogram> histogram : histograms.entrySet()) { reportHistogram(prefix, histogram.getKey(), histogram.getValue(), timestamp); } for (Map.Entry<String, Meter> meter : meters.entrySet()) { reportMetered(prefix, meter.getKey(), meter.getValue(), timestamp); } for (Map.Entry<String, Timer> timer : timers.entrySet()) { reportTimer(prefix, timer.getKey(), timer.getValue(), timestamp); } this.graphitePusher.flush(); } catch (IOException ioe) { LOGGER.error("Error sending metrics to Graphite", ioe); try { this.graphitePusher.close(); } catch (IOException innerIoe) { LOGGER.error("Error closing the Graphite sender", innerIoe); } } }
GraphiteReporter extends ConfiguredScheduledReporter { @Override protected void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers, Map<String, Object> tags) { String prefix = getMetricNamePrefix(tags); long timestamp = System.currentTimeMillis() / 1000l; try { for (Map.Entry<String, Gauge> gauge : gauges.entrySet()) { reportGauge(prefix, gauge.getKey(), gauge.getValue(), timestamp); } for (Map.Entry<String, Counter> counter : counters.entrySet()) { reportCounter(prefix, counter.getKey(), counter.getValue(), timestamp); } for (Map.Entry<String, Histogram> histogram : histograms.entrySet()) { reportHistogram(prefix, histogram.getKey(), histogram.getValue(), timestamp); } for (Map.Entry<String, Meter> meter : meters.entrySet()) { reportMetered(prefix, meter.getKey(), meter.getValue(), timestamp); } for (Map.Entry<String, Timer> timer : timers.entrySet()) { reportTimer(prefix, timer.getKey(), timer.getValue(), timestamp); } this.graphitePusher.flush(); } catch (IOException ioe) { LOGGER.error("Error sending metrics to Graphite", ioe); try { this.graphitePusher.close(); } catch (IOException innerIoe) { LOGGER.error("Error closing the Graphite sender", innerIoe); } } } }
GraphiteReporter extends ConfiguredScheduledReporter { @Override protected void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers, Map<String, Object> tags) { String prefix = getMetricNamePrefix(tags); long timestamp = System.currentTimeMillis() / 1000l; try { for (Map.Entry<String, Gauge> gauge : gauges.entrySet()) { reportGauge(prefix, gauge.getKey(), gauge.getValue(), timestamp); } for (Map.Entry<String, Counter> counter : counters.entrySet()) { reportCounter(prefix, counter.getKey(), counter.getValue(), timestamp); } for (Map.Entry<String, Histogram> histogram : histograms.entrySet()) { reportHistogram(prefix, histogram.getKey(), histogram.getValue(), timestamp); } for (Map.Entry<String, Meter> meter : meters.entrySet()) { reportMetered(prefix, meter.getKey(), meter.getValue(), timestamp); } for (Map.Entry<String, Timer> timer : timers.entrySet()) { reportTimer(prefix, timer.getKey(), timer.getValue(), timestamp); } this.graphitePusher.flush(); } catch (IOException ioe) { LOGGER.error("Error sending metrics to Graphite", ioe); try { this.graphitePusher.close(); } catch (IOException innerIoe) { LOGGER.error("Error closing the Graphite sender", innerIoe); } } } GraphiteReporter(Builder<?> builder, Config config); }
GraphiteReporter extends ConfiguredScheduledReporter { @Override protected void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers, Map<String, Object> tags) { String prefix = getMetricNamePrefix(tags); long timestamp = System.currentTimeMillis() / 1000l; try { for (Map.Entry<String, Gauge> gauge : gauges.entrySet()) { reportGauge(prefix, gauge.getKey(), gauge.getValue(), timestamp); } for (Map.Entry<String, Counter> counter : counters.entrySet()) { reportCounter(prefix, counter.getKey(), counter.getValue(), timestamp); } for (Map.Entry<String, Histogram> histogram : histograms.entrySet()) { reportHistogram(prefix, histogram.getKey(), histogram.getValue(), timestamp); } for (Map.Entry<String, Meter> meter : meters.entrySet()) { reportMetered(prefix, meter.getKey(), meter.getValue(), timestamp); } for (Map.Entry<String, Timer> timer : timers.entrySet()) { reportTimer(prefix, timer.getKey(), timer.getValue(), timestamp); } this.graphitePusher.flush(); } catch (IOException ioe) { LOGGER.error("Error sending metrics to Graphite", ioe); try { this.graphitePusher.close(); } catch (IOException innerIoe) { LOGGER.error("Error closing the Graphite sender", innerIoe); } } } GraphiteReporter(Builder<?> builder, Config config);  }
GraphiteReporter extends ConfiguredScheduledReporter { @Override protected void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers, Map<String, Object> tags) { String prefix = getMetricNamePrefix(tags); long timestamp = System.currentTimeMillis() / 1000l; try { for (Map.Entry<String, Gauge> gauge : gauges.entrySet()) { reportGauge(prefix, gauge.getKey(), gauge.getValue(), timestamp); } for (Map.Entry<String, Counter> counter : counters.entrySet()) { reportCounter(prefix, counter.getKey(), counter.getValue(), timestamp); } for (Map.Entry<String, Histogram> histogram : histograms.entrySet()) { reportHistogram(prefix, histogram.getKey(), histogram.getValue(), timestamp); } for (Map.Entry<String, Meter> meter : meters.entrySet()) { reportMetered(prefix, meter.getKey(), meter.getValue(), timestamp); } for (Map.Entry<String, Timer> timer : timers.entrySet()) { reportTimer(prefix, timer.getKey(), timer.getValue(), timestamp); } this.graphitePusher.flush(); } catch (IOException ioe) { LOGGER.error("Error sending metrics to Graphite", ioe); try { this.graphitePusher.close(); } catch (IOException innerIoe) { LOGGER.error("Error closing the Graphite sender", innerIoe); } } } GraphiteReporter(Builder<?> builder, Config config);   }