Search in sources :

Example 66 with Timed

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;
}
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 67 with Timed

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 + ">"));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Produces(javax.ws.rs.Produces) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) DELETE(javax.ws.rs.DELETE) IndexSetStatsCreator(org.graylog2.indexer.IndexSetStatsCreator) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) SystemJobManager(org.graylog2.system.jobs.SystemJobManager) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Response(javax.ws.rs.core.Response) AuditEventTypes(org.graylog2.audit.AuditEventTypes) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) DuplicateKeyException(com.mongodb.DuplicateKeyException) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) IndexSetValidator(org.graylog2.indexer.IndexSetValidator) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) Objects.requireNonNull(java.util.Objects.requireNonNull) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexSetUpdateRequest(org.graylog2.rest.resources.system.indexer.requests.IndexSetUpdateRequest) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) RestResource(org.graylog2.shared.rest.resources.RestResource) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 68 with Timed

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);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Produces(javax.ws.rs.Produces) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) DELETE(javax.ws.rs.DELETE) IndexSetStatsCreator(org.graylog2.indexer.IndexSetStatsCreator) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) SystemJobManager(org.graylog2.system.jobs.SystemJobManager) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Response(javax.ws.rs.core.Response) AuditEventTypes(org.graylog2.audit.AuditEventTypes) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) DuplicateKeyException(com.mongodb.DuplicateKeyException) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) IndexSetValidator(org.graylog2.indexer.IndexSetValidator) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) Objects.requireNonNull(java.util.Objects.requireNonNull) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexSetUpdateRequest(org.graylog2.rest.resources.system.indexer.requests.IndexSetUpdateRequest) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) RestResource(org.graylog2.shared.rest.resources.RestResource) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 69 with Timed

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);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 70 with Timed

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));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)414 ApiOperation (io.swagger.annotations.ApiOperation)255 ApiResponses (io.swagger.annotations.ApiResponses)196 Path (javax.ws.rs.Path)169 Counted (com.codahale.metrics.annotation.Counted)128 Produces (javax.ws.rs.Produces)112 GET (javax.ws.rs.GET)107 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)105 AuditEvent (org.graylog2.audit.jersey.AuditEvent)82 POST (javax.ws.rs.POST)78 Consumes (javax.ws.rs.Consumes)58 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)53 NotFoundException (javax.ws.rs.NotFoundException)52 PUT (javax.ws.rs.PUT)52 URI (java.net.URI)45 DELETE (javax.ws.rs.DELETE)45 BadRequestException (javax.ws.rs.BadRequestException)41 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)41 HashMap (java.util.HashMap)34 Event (keywhiz.log.Event)29