Skip to content

Instantly share code, notes, and snippets.

@johann8384
Created June 9, 2017 02:23
Show Gist options
  • Save johann8384/dc92bfb3fb88197ed48de12acc23a5ef to your computer and use it in GitHub Desktop.
Save johann8384/dc92bfb3fb88197ed48de12acc23a5ef to your computer and use it in GitHub Desktop.
static {
// Collect jvm and system metrics by default
Metrics.registerMetricSet("jvm.gc", new GarbageCollectorMetricSet());
Metrics.registerMetricSet("jvm.memory", new MemoryUsageGaugeSet());
Metrics.registerMetricSet("jvm.threads", new ThreadStatesGaugeSet());
Metrics.registerMetricSet("jvm.runtime", new RuntimeMetricSet());
Metrics.registerMetricSet("jvm.os", new OperatingSystemMetricSet());
Metrics.registerMetricSet("jvm.filesystem", new FileSystemMetricSet());
Metrics.registerAll("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()), Metrics.getMetricRegistry());
// Register the basic health check
Metrics.registerHealthCheck("DeadlockDetection", new ThreadDeadlockHealthCheck());
// Register metrics for the logger (it's the WTF per second metric, very important)
final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
final InstrumentedAppender metrics = new InstrumentedAppender(registry);
metrics.setContext(root.getLoggerContext());
metrics.start();
root.addAppender(metrics);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment