Search in sources :

Example 16 with DBCursor

use of com.mongodb.DBCursor in project graylog2-server by Graylog2.

the class StreamRuleServiceImpl method streamRuleCountByStream.

@Override
public Map<String, Long> streamRuleCountByStream() {
    final DBCursor streamIds = collection(StreamImpl.class).find(new BasicDBObject(), new BasicDBObject("_id", 1));
    final Map<String, Long> streamRules = new HashMap<>(streamIds.size());
    for (DBObject keys : streamIds) {
        final ObjectId streamId = (ObjectId) keys.get("_id");
        streamRules.put(streamId.toHexString(), streamRuleCount(streamId));
    }
    return streamRules;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) HashMap(java.util.HashMap) ObjectId(org.bson.types.ObjectId) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 17 with DBCursor

use of com.mongodb.DBCursor in project graylog2-server by Graylog2.

the class OutputServiceImpl method countByType.

@Override
public Map<String, Long> countByType() {
    final DBCursor outputTypes = dbCollection.find(null, new BasicDBObject(OutputImpl.FIELD_TYPE, 1));
    final Map<String, Long> outputsCountByType = new HashMap<>(outputTypes.count());
    for (DBObject outputType : outputTypes) {
        final String type = (String) outputType.get(OutputImpl.FIELD_TYPE);
        if (type != null) {
            final Long oldValue = outputsCountByType.get(type);
            final Long newValue = (oldValue == null) ? 1 : oldValue + 1;
            outputsCountByType.put(type, newValue);
        }
    }
    return outputsCountByType;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) HashMap(java.util.HashMap) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 18 with DBCursor

use of com.mongodb.DBCursor in project graylog2-server by Graylog2.

the class MetricsHistoryResource method historicSingleMetric.

@GET
@Timed
@ApiOperation(value = "Get history of a single metric", notes = "The maximum retention time is currently only 5 minutes.")
public Map<String, Object> historicSingleMetric(@ApiParam(name = "metricName", required = true) @PathParam("metricName") String metricName, @ApiParam(name = "after", value = "Only values for after this UTC timestamp (1970 epoch)") @QueryParam("after") @DefaultValue("-1") long after) {
    checkPermission(RestPermissions.METRICS_READHISTORY, metricName);
    BasicDBObject andQuery = new BasicDBObject();
    final List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
    obj.add(new BasicDBObject("name", metricName));
    if (after != -1) {
        obj.add(new BasicDBObject("$gt", new BasicDBObject("$gt", new Date(after))));
    }
    andQuery.put("$and", obj);
    final DBCursor cursor = mongoConnection.getDatabase().getCollection("graylog2_metrics").find(andQuery).sort(new BasicDBObject("timestamp", 1));
    final Map<String, Object> metricsData = Maps.newHashMap();
    metricsData.put("name", metricName);
    final List<Object> values = Lists.newArrayList();
    metricsData.put("values", values);
    while (cursor.hasNext()) {
        final DBObject value = cursor.next();
        metricsData.put("node", value.get("node"));
        final MetricType metricType = MetricType.valueOf(((String) value.get("type")).toUpperCase(Locale.ENGLISH));
        Map<String, Object> dataPoint = Maps.newHashMap();
        values.add(dataPoint);
        dataPoint.put("timestamp", value.get("timestamp"));
        metricsData.put("type", metricType.toString().toLowerCase(Locale.ENGLISH));
        switch(metricType) {
            case GAUGE:
                final Object gaugeValue = value.get("value");
                dataPoint.put("value", gaugeValue);
                break;
            case COUNTER:
                dataPoint.put("count", value.get("count"));
                break;
            case HISTOGRAM:
                dataPoint.put("75-percentile", value.get("75-percentile"));
                dataPoint.put("95-percentile", value.get("95-percentile"));
                dataPoint.put("98-percentile", value.get("98-percentile"));
                dataPoint.put("99-percentile", value.get("99-percentile"));
                dataPoint.put("999-percentile", value.get("999-percentile"));
                dataPoint.put("max", value.get("max"));
                dataPoint.put("min", value.get("min"));
                dataPoint.put("mean", value.get("mean"));
                dataPoint.put("median", value.get("median"));
                dataPoint.put("std_dev", value.get("std_dev"));
                break;
            case METER:
                dataPoint.put("count", value.get("count"));
                dataPoint.put("1-minute-rate", value.get("1-minute-rate"));
                dataPoint.put("5-minute-rate", value.get("5-minute-rate"));
                dataPoint.put("15-minute-rate", value.get("15-minute-rate"));
                dataPoint.put("mean-rate", value.get("mean-rate"));
                break;
            case TIMER:
                dataPoint.put("count", value.get("count"));
                dataPoint.put("rate-unit", value.get("rate-unit"));
                dataPoint.put("1-minute-rate", value.get("1-minute-rate"));
                dataPoint.put("5-minute-rate", value.get("5-minute-rate"));
                dataPoint.put("15-minute-rate", value.get("15-minute-rate"));
                dataPoint.put("mean-rate", value.get("mean-rate"));
                dataPoint.put("duration-unit", value.get("duration-unit"));
                dataPoint.put("75-percentile", value.get("75-percentile"));
                dataPoint.put("95-percentile", value.get("95-percentile"));
                dataPoint.put("98-percentile", value.get("98-percentile"));
                dataPoint.put("99-percentile", value.get("99-percentile"));
                dataPoint.put("999-percentile", value.get("999-percentile"));
                dataPoint.put("max", value.get("max"));
                dataPoint.put("min", value.get("min"));
                dataPoint.put("mean", value.get("mean"));
                dataPoint.put("median", value.get("median"));
                dataPoint.put("stddev", value.get("stddev"));
                break;
        }
    }
    return metricsData;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Date(java.util.Date) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 19 with DBCursor

use of com.mongodb.DBCursor in project jackrabbit-oak by apache.

the class MongoVersionGCSupport method logSplitDocIdsTobeDeleted.

private void logSplitDocIdsTobeDeleted(DBObject query) {
    // Fetch only the id
    final BasicDBObject keys = new BasicDBObject(Document.ID, 1);
    List<String> ids;
    DBCursor cursor = getNodeCollection().find(query, keys).setReadPreference(store.getConfiguredReadPreference(NODES));
    try {
        ids = ImmutableList.copyOf(Iterables.transform(cursor, new Function<DBObject, String>() {

            @Override
            public String apply(DBObject input) {
                return (String) input.get(Document.ID);
            }
        }));
    } finally {
        cursor.close();
    }
    StringBuilder sb = new StringBuilder("Split documents with following ids were deleted as part of GC \n");
    Joiner.on(StandardSystemProperty.LINE_SEPARATOR.value()).appendTo(sb, ids);
    LOG.debug(sb.toString());
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 20 with DBCursor

use of com.mongodb.DBCursor in project jackrabbit-oak by apache.

the class MongoBlobStore method getAllChunkIds.

@Override
public Iterator<String> getAllChunkIds(long maxLastModifiedTime) throws Exception {
    DBCollection collection = getBlobCollection();
    DBObject fields = new BasicDBObject();
    fields.put(MongoBlob.KEY_ID, 1);
    QueryBuilder builder = new QueryBuilder();
    if (maxLastModifiedTime != 0 && maxLastModifiedTime != -1) {
        builder.and(MongoBlob.KEY_LAST_MOD).lessThanEquals(maxLastModifiedTime);
    }
    final DBCursor cur = collection.find(builder.get(), fields).hint(fields).addOption(Bytes.QUERYOPTION_SLAVEOK);
    //TODO The cursor needs to be closed
    return new AbstractIterator<String>() {

        @Override
        protected String computeNext() {
            if (cur.hasNext()) {
                MongoBlob blob = (MongoBlob) cur.next();
                if (blob != null) {
                    return blob.getId();
                }
            }
            return endOfData();
        }
    };
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) QueryBuilder(com.mongodb.QueryBuilder) AbstractIterator(com.google.common.collect.AbstractIterator) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Aggregations

DBCursor (com.mongodb.DBCursor)54 BasicDBObject (com.mongodb.BasicDBObject)46 DBObject (com.mongodb.DBObject)45 DBCollection (com.mongodb.DBCollection)23 MongoException (com.mongodb.MongoException)8 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 Function (com.google.common.base.Function)6 BasicDBList (com.mongodb.BasicDBList)6 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)6 JSONObject (org.json.JSONObject)6 Test (org.junit.Test)6 QueryBuilder (com.mongodb.QueryBuilder)5 ObjectId (org.locationtech.geogig.api.ObjectId)4 DB (com.mongodb.DB)3 Map (java.util.Map)3 Nonnull (javax.annotation.Nonnull)3 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)3 GridFSDBFile (com.mongodb.gridfs.GridFSDBFile)2 VCollection (de.fhg.igd.mongomvcc.VCollection)2