use of com.codahale.metrics.logback.InstrumentedAppender in project chassis by Kixeye.
the class ChassisConfiguration method metricRegistry.
/**
* Initializes the metrics registry
*
* @return metric registry bean
*/
@Bean
public MetricRegistry metricRegistry() {
final MetricRegistry bean = new MetricRegistry();
// add JVM metrics
bean.register("jvm.gc", new GarbageCollectorMetricSet());
bean.register("jvm.memory", new MemoryUsageGaugeSet());
bean.register("jvm.thread-states", new ThreadStatesGaugeSet());
bean.register("jvm.fd", new FileDescriptorRatioGauge());
bean.register("jvm.load-average", new Gauge<Double>() {
private OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
public Double getValue() {
try {
return mxBean.getSystemLoadAverage();
} catch (Exception e) {
// not supported
return -1d;
}
}
});
// add Logback metrics
final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
final InstrumentedAppender appender = new InstrumentedAppender(bean);
appender.setContext(root.getLoggerContext());
appender.start();
root.addAppender(appender);
return bean;
}
use of com.codahale.metrics.logback.InstrumentedAppender in project dropwizard by dropwizard.
the class DefaultLoggingFactory method configureInstrumentation.
private void configureInstrumentation(Logger root, MetricRegistry metricRegistry) {
final InstrumentedAppender appender = new InstrumentedAppender(metricRegistry);
appender.setContext(loggerContext);
appender.start();
root.addAppender(appender);
}
use of com.codahale.metrics.logback.InstrumentedAppender in project ninja by ninjaframework.
the class MetricsServiceImpl method start.
@Start(order = 10)
@Override
public void start() {
String applicationName = ninjaProps.getWithDefault(NinjaConstant.applicationName, "Ninja");
/*
* Register optional metrics
*/
if (ninjaProps.getBooleanWithDefault("metrics.jvm.enabled", false)) {
registerAll("jvm.gc", new GarbageCollectorMetricSet());
registerAll("jvm.memory", new MemoryUsageGaugeSet());
registerAll("jvm.threads", new ThreadStatesGaugeSet());
registerAll("jvm.classes", new ClassLoadingGaugeSet());
log.debug("Registered JVM-Metrics integration");
}
if (ninjaProps.getBooleanWithDefault("metrics.logback.enabled", false)) {
final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
final ch.qos.logback.classic.Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
final InstrumentedAppender appender = new InstrumentedAppender(metricRegistry);
appender.setContext(root.getLoggerContext());
appender.start();
root.addAppender(appender);
log.debug("Registered Logback-Metrics integration");
}
/*
* MBeans for VisualVM, JConsole, or JMX
*/
if (ninjaProps.getBooleanWithDefault("metrics.mbeans.enabled", true)) {
JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).inDomain(applicationName).build();
reporter.start();
reporters.add(reporter);
log.debug("Started Ninja Metrics MBeans reporter");
}
log.info("Ninja Metrics is ready for collection.");
}
Aggregations