@Override
  public void report(
      SortedMap<String, Gauge> gauges,
      SortedMap<String, Counter> counters,
      SortedMap<String, Histogram> histograms,
      SortedMap<String, Meter> meters,
      SortedMap<String, Timer> timers) {
    final Date timestamp = new Date(clock.getTime());

    List<DBObject> docs =
        Lists.newArrayListWithExpectedSize(
            gauges.size() + counters.size() + histograms.size() + meters.size() + timers.size());

    collectGaugeReports(docs, gauges, timestamp);
    collectCounterReports(docs, counters, timestamp);
    collectHistogramReports(docs, histograms, timestamp);
    collectMeterReports(docs, meters, timestamp);
    collectTimerReports(docs, timers, timestamp);

    try {
      final DBCollection collection =
          mongoConnection.getDatabase().getCollection("graylog2_metrics");
      // don't hang on to the data for too long.
      final BasicDBObject indexField = new BasicDBObject("timestamp", 1);
      final BasicDBObject indexOptions = new BasicDBObject("expireAfterSeconds", 5 * 60);
      collection.createIndex(indexField, indexOptions);

      collection.insert(docs, WriteConcern.UNACKNOWLEDGED);
    } catch (Exception e) {
      LOG.warn("Unable to write graylog2 metrics to mongodb. Ignoring this error.", e);
    }
  }
 @Inject
 private Builder(
     MetricRegistry registry, MongoConnection mongoConnection, ServerStatus serverStatus) {
   this.registry = registry;
   this.mongoConnection = mongoConnection;
   this.serverStatus = serverStatus;
   this.clock = Clock.defaultClock();
   this.rateUnit = TimeUnit.SECONDS;
   this.durationUnit = TimeUnit.MILLISECONDS;
   this.filter = MetricFilter.ALL;
 }