@Test public void reportsIntegerGaugeValues() throws Exception { reporter.report(map("gauge", gauge(1)), this.map(), this.map(), this.map(), this.map()); assertTimeSeries(1, "gauge", GAUGE, T0, 1 ); }
@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);  }