Search in sources :

Example 76 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class LoggersResource method messages.

@GET
@Timed
@ApiOperation(value = "Get recent internal log messages")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Memory appender is disabled."), @ApiResponse(code = 500, message = "Memory appender is broken.") })
@Path("/messages/recent")
@Produces(MediaType.APPLICATION_JSON)
public LogMessagesSummary messages(@ApiParam(name = "limit", value = "How many log messages should be returned", defaultValue = "500", allowableValues = "range[0, infinity]") @QueryParam("limit") @DefaultValue("500") @Min(0L) int limit, @ApiParam(name = "level", value = "Which log level (or higher) should the messages have", defaultValue = "ALL", allowableValues = "[OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL]") @QueryParam("level") @DefaultValue("ALL") @NotEmpty String level) {
    final Appender appender = getAppender(MEMORY_APPENDER_NAME);
    if (appender == null) {
        throw new NotFoundException("Memory appender is disabled. Please refer to the example log4j.xml file.");
    }
    if (!(appender instanceof MemoryAppender)) {
        throw new InternalServerErrorException("Memory appender is not an instance of MemoryAppender. Please refer to the example log4j.xml file.");
    }
    final Level logLevel = Level.toLevel(level, Level.ALL);
    final MemoryAppender memoryAppender = (MemoryAppender) appender;
    final List<InternalLogMessage> messages = new ArrayList<>(limit);
    for (LogEvent event : memoryAppender.getLogMessages(limit)) {
        final Level eventLevel = event.getLevel();
        if (!eventLevel.isMoreSpecificThan(logLevel)) {
            continue;
        }
        final ThrowableProxy thrownProxy = event.getThrownProxy();
        final String throwable;
        if (thrownProxy == null) {
            throwable = null;
        } else {
            throwable = thrownProxy.getExtendedStackTraceAsString();
        }
        final Marker marker = event.getMarker();
        messages.add(InternalLogMessage.create(event.getMessage().getFormattedMessage(), event.getLoggerName(), eventLevel.toString(), marker == null ? null : marker.toString(), new DateTime(event.getTimeMillis(), DateTimeZone.UTC), throwable, event.getThreadName(), event.getContextData().toMap()));
    }
    return LogMessagesSummary.create(messages);
}
Also used : Appender(org.apache.logging.log4j.core.Appender) MemoryAppender(org.graylog2.log4j.MemoryAppender) MemoryAppender(org.graylog2.log4j.MemoryAppender) LogEvent(org.apache.logging.log4j.core.LogEvent) ArrayList(java.util.ArrayList) NotFoundException(javax.ws.rs.NotFoundException) Marker(org.apache.logging.log4j.Marker) ThrowableProxy(org.apache.logging.log4j.core.impl.ThrowableProxy) DateTime(org.joda.time.DateTime) InternalLogMessage(org.graylog2.rest.models.system.loggers.responses.InternalLogMessage) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Level(org.apache.logging.log4j.Level) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 77 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class OutputResource method delete.

@DELETE
@Path("/{outputId}")
@Timed
@ApiOperation(value = "Delete output")
@RequiresPermissions(RestPermissions.OUTPUTS_TERMINATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream/output on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_OUTPUT_DELETE)
public void delete(@ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId) throws org.graylog2.database.NotFoundException {
    checkPermission(RestPermissions.OUTPUTS_TERMINATE);
    final Output output = outputService.load(outputId);
    outputService.destroy(output);
}
Also used : Output(org.graylog2.plugin.streams.Output) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 78 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class InputStatesResource method start.

@PUT
@Path("/{inputId}")
@Timed
@ApiOperation(value = "(Re-)Start specified input on this node")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_START)
public InputCreated start(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
    inputService.find(inputId);
    final InputCreated result = InputCreated.create(inputId);
    this.serverEventBus.post(result);
    return result;
}
Also used : InputCreated(org.graylog2.rest.models.system.inputs.responses.InputCreated) 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 79 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class InputsResource method get.

@GET
@Timed
@ApiOperation(value = "Get information of a single input on this node")
@Path("/{inputId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input.") })
public InputSummary get(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
    checkPermission(RestPermissions.INPUTS_READ, inputId);
    final Input input = inputService.find(inputId);
    return getInputSummary(input);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) 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 80 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class InputsResource method terminate.

@DELETE
@Timed
@Path("/{inputId}")
@ApiOperation(value = "Terminate input on this node")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_DELETE)
public void terminate(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
    final Input input = inputService.find(inputId);
    inputService.destroy(input);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) 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