@Test public void reportsTimers() throws Exception { final Timer timer = mock(Timer.class); when(timer.getCount()).thenReturn(1L); when(timer.getMeanRate()).thenReturn(2.0); when(timer.getOneMinuteRate()).thenReturn(3.0); when(timer.getFiveMinuteRate()).thenReturn(4.0); when(timer.getFifteenMinuteRate()).thenReturn(5.0); final Snapshot snapshot = mock(Snapshot.class); final long max = TimeUnit.MILLISECONDS.toNanos(100); when(snapshot.getMax()).thenReturn(max); final double mean = TimeUnit.MILLISECONDS.toNanos(200); when(snapshot.getMean()).thenReturn(mean); final long min = TimeUnit.MILLISECONDS.toNanos(300); when(snapshot.getMin()).thenReturn(min); final double stdDev = TimeUnit.MILLISECONDS.toNanos(400); when(snapshot.getStdDev()).thenReturn(stdDev); final double median = TimeUnit.MILLISECONDS.toNanos(500); when(snapshot.getMedian()).thenReturn(median); final double p75 = TimeUnit.MILLISECONDS.toNanos(600); when(snapshot.get75thPercentile()).thenReturn(p75); final double p95 = TimeUnit.MILLISECONDS.toNanos(700); when(snapshot.get95thPercentile()).thenReturn(p95); final double p98 = TimeUnit.MILLISECONDS.toNanos(800); when(snapshot.get98thPercentile()).thenReturn(p98); final double p99 = TimeUnit.MILLISECONDS.toNanos(900); when(snapshot.get99thPercentile()).thenReturn(p99); final double p999 = TimeUnit.MILLISECONDS.toNanos(1000); when(snapshot.get999thPercentile()).thenReturn(p999); when(timer.getSnapshot()).thenReturn(snapshot); reporter.report(this.map(), this.map(), this.map(), this.map(), map("timer", timer)); int total = 15; assertTimeSeries(total, "timer/count", CUMULATIVE, T0, 1 ); assertTimeSeries(total, "timer/m1_rate", GAUGE, T0, 3.00 ); assertTimeSeries(total, "timer/m5_rate", GAUGE, T0, 4.00 ); assertTimeSeries(total, "timer/m15_rate", GAUGE, T0, 5.00 ); assertTimeSeries(total, "timer/mean_rate", GAUGE, T0, 2.00 ); assertTimeSeries(total, "timer/max", GAUGE, T0, max ); assertTimeSeries(total, "timer/mean", GAUGE, T0, mean ); assertTimeSeries(total, "timer/min", GAUGE, T0, min ); assertTimeSeries(total, "timer/stddev", GAUGE, T0, stdDev ); assertTimeSeries(total, "timer/p50", GAUGE, T0, median ); assertTimeSeries(total, "timer/p75", GAUGE, T0, p75 ); assertTimeSeries(total, "timer/p95", GAUGE, T0, p95 ); assertTimeSeries(total, "timer/p98", GAUGE, T0, p98 ); assertTimeSeries(total, "timer/p99", GAUGE, T0, p99 ); assertTimeSeries(total, "timer/p999", GAUGE, T0, p999 ); }
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { String now = new DateTime(clock.getTime(), 0).toStringRfc3339(); try { List<TimeSeries> timeSeriesList = Lists.newArrayList(); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { final TimeSeries timeSeries = reportGauge(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Counter> entry : counters.entrySet()) { final TimeSeries timeSeries = reportCounter(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { final List<TimeSeries> histogramTimeSeries = reportHistogram(entry.getKey(), entry.getValue(), now); if (histogramTimeSeries != null) { timeSeriesList.addAll(histogramTimeSeries); } } for (Map.Entry<String, Meter> entry : meters.entrySet()) { final List<TimeSeries> meterTimeSeries = reportMetered(entry.getKey(), entry.getValue(), now); if (meterTimeSeries != null) { timeSeriesList.addAll(meterTimeSeries); } } for (Map.Entry<String, Timer> entry : timers.entrySet()) { final List<TimeSeries> timerTimeSeries = reportTimer(entry.getKey(), entry.getValue(), now); if (timerTimeSeries != null) { timeSeriesList.addAll(timerTimeSeries); } } if (!timeSeriesList.isEmpty()) { if (timeSeriesList.size() > 200) { final BatchRequest batch = monitoring.batch(); for (List<TimeSeries> partition : Iterables.partition(timeSeriesList, 200)) { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(partition); Monitoring.Projects.TimeSeries.Create create = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest); create.queue(batch, new CreateTimeSeriesJsonBatchCallback(partition)); } batch.execute(); } else { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(timeSeriesList); final Empty empty = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest).execute(); if (!empty.isEmpty()) { LOGGER.warn(empty.toPrettyString()); } } } } catch (IOException e) { LOGGER.warn("Unable to report to Stackdriver", e); } }
StackdriverMonitoringReporter extends ScheduledReporter { @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { String now = new DateTime(clock.getTime(), 0).toStringRfc3339(); try { List<TimeSeries> timeSeriesList = Lists.newArrayList(); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { final TimeSeries timeSeries = reportGauge(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Counter> entry : counters.entrySet()) { final TimeSeries timeSeries = reportCounter(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { final List<TimeSeries> histogramTimeSeries = reportHistogram(entry.getKey(), entry.getValue(), now); if (histogramTimeSeries != null) { timeSeriesList.addAll(histogramTimeSeries); } } for (Map.Entry<String, Meter> entry : meters.entrySet()) { final List<TimeSeries> meterTimeSeries = reportMetered(entry.getKey(), entry.getValue(), now); if (meterTimeSeries != null) { timeSeriesList.addAll(meterTimeSeries); } } for (Map.Entry<String, Timer> entry : timers.entrySet()) { final List<TimeSeries> timerTimeSeries = reportTimer(entry.getKey(), entry.getValue(), now); if (timerTimeSeries != null) { timeSeriesList.addAll(timerTimeSeries); } } if (!timeSeriesList.isEmpty()) { if (timeSeriesList.size() > 200) { final BatchRequest batch = monitoring.batch(); for (List<TimeSeries> partition : Iterables.partition(timeSeriesList, 200)) { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(partition); Monitoring.Projects.TimeSeries.Create create = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest); create.queue(batch, new CreateTimeSeriesJsonBatchCallback(partition)); } batch.execute(); } else { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(timeSeriesList); final Empty empty = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest).execute(); if (!empty.isEmpty()) { LOGGER.warn(empty.toPrettyString()); } } } } catch (IOException e) { LOGGER.warn("Unable to report to Stackdriver", e); } } }
StackdriverMonitoringReporter extends ScheduledReporter { @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { String now = new DateTime(clock.getTime(), 0).toStringRfc3339(); try { List<TimeSeries> timeSeriesList = Lists.newArrayList(); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { final TimeSeries timeSeries = reportGauge(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Counter> entry : counters.entrySet()) { final TimeSeries timeSeries = reportCounter(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { final List<TimeSeries> histogramTimeSeries = reportHistogram(entry.getKey(), entry.getValue(), now); if (histogramTimeSeries != null) { timeSeriesList.addAll(histogramTimeSeries); } } for (Map.Entry<String, Meter> entry : meters.entrySet()) { final List<TimeSeries> meterTimeSeries = reportMetered(entry.getKey(), entry.getValue(), now); if (meterTimeSeries != null) { timeSeriesList.addAll(meterTimeSeries); } } for (Map.Entry<String, Timer> entry : timers.entrySet()) { final List<TimeSeries> timerTimeSeries = reportTimer(entry.getKey(), entry.getValue(), now); if (timerTimeSeries != null) { timeSeriesList.addAll(timerTimeSeries); } } if (!timeSeriesList.isEmpty()) { if (timeSeriesList.size() > 200) { final BatchRequest batch = monitoring.batch(); for (List<TimeSeries> partition : Iterables.partition(timeSeriesList, 200)) { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(partition); Monitoring.Projects.TimeSeries.Create create = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest); create.queue(batch, new CreateTimeSeriesJsonBatchCallback(partition)); } batch.execute(); } else { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(timeSeriesList); final Empty empty = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest).execute(); if (!empty.isEmpty()) { LOGGER.warn(empty.toPrettyString()); } } } } catch (IOException e) { LOGGER.warn("Unable to report to Stackdriver", e); } } private  StackdriverMonitoringReporter(MetricRegistry registry, Monitoring monitoring, String projectId, Clock clock, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter); }
StackdriverMonitoringReporter extends ScheduledReporter { @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { String now = new DateTime(clock.getTime(), 0).toStringRfc3339(); try { List<TimeSeries> timeSeriesList = Lists.newArrayList(); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { final TimeSeries timeSeries = reportGauge(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Counter> entry : counters.entrySet()) { final TimeSeries timeSeries = reportCounter(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { final List<TimeSeries> histogramTimeSeries = reportHistogram(entry.getKey(), entry.getValue(), now); if (histogramTimeSeries != null) { timeSeriesList.addAll(histogramTimeSeries); } } for (Map.Entry<String, Meter> entry : meters.entrySet()) { final List<TimeSeries> meterTimeSeries = reportMetered(entry.getKey(), entry.getValue(), now); if (meterTimeSeries != null) { timeSeriesList.addAll(meterTimeSeries); } } for (Map.Entry<String, Timer> entry : timers.entrySet()) { final List<TimeSeries> timerTimeSeries = reportTimer(entry.getKey(), entry.getValue(), now); if (timerTimeSeries != null) { timeSeriesList.addAll(timerTimeSeries); } } if (!timeSeriesList.isEmpty()) { if (timeSeriesList.size() > 200) { final BatchRequest batch = monitoring.batch(); for (List<TimeSeries> partition : Iterables.partition(timeSeriesList, 200)) { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(partition); Monitoring.Projects.TimeSeries.Create create = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest); create.queue(batch, new CreateTimeSeriesJsonBatchCallback(partition)); } batch.execute(); } else { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(timeSeriesList); final Empty empty = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest).execute(); if (!empty.isEmpty()) { LOGGER.warn(empty.toPrettyString()); } } } } catch (IOException e) { LOGGER.warn("Unable to report to Stackdriver", e); } } private  StackdriverMonitoringReporter(MetricRegistry registry, Monitoring monitoring, String projectId, Clock clock, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter); static Builder forRegistry(MetricRegistry registry); @Override void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers); }
StackdriverMonitoringReporter extends ScheduledReporter { @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { String now = new DateTime(clock.getTime(), 0).toStringRfc3339(); try { List<TimeSeries> timeSeriesList = Lists.newArrayList(); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { final TimeSeries timeSeries = reportGauge(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Counter> entry : counters.entrySet()) { final TimeSeries timeSeries = reportCounter(entry.getKey(), entry.getValue(), now); if (timeSeries != null) { timeSeriesList.add(timeSeries); } } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { final List<TimeSeries> histogramTimeSeries = reportHistogram(entry.getKey(), entry.getValue(), now); if (histogramTimeSeries != null) { timeSeriesList.addAll(histogramTimeSeries); } } for (Map.Entry<String, Meter> entry : meters.entrySet()) { final List<TimeSeries> meterTimeSeries = reportMetered(entry.getKey(), entry.getValue(), now); if (meterTimeSeries != null) { timeSeriesList.addAll(meterTimeSeries); } } for (Map.Entry<String, Timer> entry : timers.entrySet()) { final List<TimeSeries> timerTimeSeries = reportTimer(entry.getKey(), entry.getValue(), now); if (timerTimeSeries != null) { timeSeriesList.addAll(timerTimeSeries); } } if (!timeSeriesList.isEmpty()) { if (timeSeriesList.size() > 200) { final BatchRequest batch = monitoring.batch(); for (List<TimeSeries> partition : Iterables.partition(timeSeriesList, 200)) { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(partition); Monitoring.Projects.TimeSeries.Create create = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest); create.queue(batch, new CreateTimeSeriesJsonBatchCallback(partition)); } batch.execute(); } else { CreateTimeSeriesRequest timeSeriesRequest = new CreateTimeSeriesRequest(); timeSeriesRequest.setTimeSeries(timeSeriesList); final Empty empty = monitoring.projects().timeSeries().create(this.timeSeriesName, timeSeriesRequest).execute(); if (!empty.isEmpty()) { LOGGER.warn(empty.toPrettyString()); } } } } catch (IOException e) { LOGGER.warn("Unable to report to Stackdriver", e); } } private  StackdriverMonitoringReporter(MetricRegistry registry, Monitoring monitoring, String projectId, Clock clock, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter); static Builder forRegistry(MetricRegistry registry); @Override void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers);  }