use of com.codahale.metrics.annotation.Timed 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.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.
the class IndexSetsResource method get.
@GET
@Path("{id}")
@Timed
@ApiOperation(value = "Get index set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public IndexSetSummary get(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
checkPermission(RestPermissions.INDEXSETS_READ, id);
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
return indexSetService.get(id).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">"));
}
use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.
the class IndexSetsResource method list.
@GET
@Timed
@ApiOperation(value = "Get a list of all index sets")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetResponse list(@ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("0") int limit, @ApiParam(name = "stats", value = "Include index set stats.") @QueryParam("stats") @DefaultValue("false") boolean computeStats) {
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
List<IndexSetSummary> indexSets;
int count;
if (limit > 0) {
// First collect all index set ids the user is allowed to see.
final Set<String> allowedIds = indexSetService.findAll().stream().filter(indexSet -> isPermitted(RestPermissions.INDEXSETS_READ, indexSet.id())).map(IndexSetConfig::id).collect(Collectors.toSet());
indexSets = indexSetService.findPaginated(allowedIds, limit, skip).stream().map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = allowedIds.size();
} else {
indexSets = indexSetService.findAll().stream().filter(indexSetConfig -> isPermitted(RestPermissions.INDEXSETS_READ, indexSetConfig.id())).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = indexSets.size();
}
final Map<String, IndexSetStats> stats;
if (computeStats) {
stats = indexSetRegistry.getAll().stream().collect(Collectors.toMap(indexSet -> indexSet.getConfig().id(), indexSetStatsCreator::getForIndexSet));
} else {
stats = Collections.emptyMap();
}
return IndexSetResponse.create(count, indexSets, stats);
}
use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.
the class IndexSetsResource method update.
@PUT
@Path("{id}")
@Timed
@ApiOperation(value = "Update index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_UPDATE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 409, message = "Mismatch of IDs in URI path and payload") })
public IndexSetSummary update(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "Index set configuration", required = true) @Valid @NotNull IndexSetUpdateRequest updateRequest) {
checkPermission(RestPermissions.INDEXSETS_EDIT, id);
final IndexSetConfig oldConfig = indexSetService.get(id).orElseThrow(() -> new NotFoundException("Index set <" + id + "> not found"));
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
final boolean isDefaultSet = oldConfig.equals(defaultIndexSet);
if (isDefaultSet && !updateRequest.isWritable()) {
throw new ClientErrorException("Default index set must be writable.", Response.Status.CONFLICT);
}
final IndexSetConfig savedObject = indexSetService.save(updateRequest.toIndexSetConfig(id, oldConfig));
return IndexSetSummary.fromIndexSetConfig(savedObject, isDefaultSet);
}
use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.
the class IndexSetsResource method setDefault.
@PUT
@Path("{id}/default")
@Timed
@ApiOperation(value = "Set default index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_UPDATE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetSummary setDefault(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
checkPermission(RestPermissions.INDEXSETS_EDIT, id);
final IndexSetConfig indexSet = indexSetService.get(id).orElseThrow(() -> new NotFoundException("Index set <" + id + "> does not exist"));
if (!indexSet.isWritable()) {
throw new ClientErrorException("Default index set must be writable.", Response.Status.CONFLICT);
}
clusterConfigService.write(DefaultIndexSetConfig.create(indexSet.id()));
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
return IndexSetSummary.fromIndexSetConfig(indexSet, indexSet.equals(defaultIndexSet));
}
Aggregations