@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
 public OutputServiceImpl(
     MongoConnection mongoConnection,
     MongoJackObjectMapperProvider mapperProvider,
     StreamService streamService,
     OutputRegistry outputRegistry) {
   this.streamService = streamService;
   final String collectionName = OutputImpl.class.getAnnotation(CollectionName.class).value();
   this.dbCollection = mongoConnection.getDatabase().getCollection(collectionName);
   this.coll =
       JacksonDBCollection.wrap(
           dbCollection, OutputImpl.class, String.class, mapperProvider.get());
   this.outputRegistry = outputRegistry;
 }