-
Notifications
You must be signed in to change notification settings - Fork 19
Monitoring
Tjahzi tracks its operational statistics in many internal counters. It tracks http errors, timeouts and tcp errors in separate counters. It also records exceptions and their stack traces. If you want to get access to them or expose them to your monitoring system this is the instruction on how to do that.
-
First you need to get hold of the appender from Log4j logging system:
Click to toggle code example
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.LoggerContext; ... LoggerContext context = (LoggerContext) LogManager.getContext(false); LokiAppender loki = context.getConfiguration().getAppender("Loki");
Where
"Loki"
is the name of the appender you specified in the configuration file:<appenders> <Loki name="Loki"> ... </Loki> </appenders>
-
Then you can install a new
MonitoringModule
loki.setMonitoringModule(...)
-
You can use simple
StandardMonitoringModule
that tracks events in counters that will have access to.StandardMonitoringModule monitoringModule = new StandardMonitoringModule() loki.setMonitoringModule(monitoringModule)
-
You can implement your own or use Dropwizard based implementation.
-
First you need to get hold of the appender from Logback logging system. It is a little more involved than with Log4
Click to toggle code example
import ch.qos.logback.classic.LoggerContext; import pl.tkowalcz.tjahzi.logback.LokiAppender; import java.util.Spliterators; import java.util.stream.StreamSupport; ... public static LokiAppender getLokiAppender(LoggerContext context) { return (LokiAppender) context .getLoggerList() .stream() .flatMap( logger -> StreamSupport.stream( Spliterators.spliteratorUnknownSize(logger.iteratorForAppenders(), 0), false ) ) .filter(appender -> appender instanceof LokiAppender) .findAny() .orElseThrow(() -> new AssertionError("Expected to find Loki appender")); }
Where "Loki" is the name of the appender you specified in the configuration file:
<appender name="Loki" class="pl.tkowalcz.tjahzi.logback.LokiAppender"> ... </appender>
-
Follow steps 2+ from Log4j section.
If you are using Dropwizard library for monitoring your application then Tjahzi comes with implmeentation of monitoring module that integrates with MetricRegistry
.
loki.setMonitoringModule(
new DropwizardMonitoringModule(
metricRegistry,
"appender.loki"
)
);
Where "appender.loki
is a prefix added to all metric names that Tjahzi will create.