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;
}
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;
}
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;
}
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());
}
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();
}
};
}
Aggregations