private ServletContextHandler getMetricsHandler() { MetricRegistry registry = Metrics.getRegistry(); HealthCheckRegistry healthCheckRegistry = Metrics.getHealthCheckRegistry(); healthCheckRegistry.register("rotation", new Rotation(configuration.getRotationStatusFilePath())); registry.registerAll(new GarbageCollectorMetricSet()); registry.registerAll(new MemoryUsageGaugeSet()); registry.registerAll(new ThreadStatesGaugeSet()); registry.registerAll(new JvmAttributeGaugeSet()); ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setContextPath("/__metrics"); servletContextHandler.setAttribute(MetricsServlet.class.getCanonicalName() + ".registry", registry); servletContextHandler.setAttribute(HealthCheckServlet.class.getCanonicalName() + ".registry", healthCheckRegistry); servletContextHandler.addServlet(new ServletHolder(new AdminServlet()), "/*"); return servletContextHandler; }
@PostConstruct public void init() { log.debug("Registering JVM gauges"); metricRegistry.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet()); metricRegistry.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet()); metricRegistry.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet()); metricRegistry.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge()); metricRegistry.register(PROP_METRIC_REG_JVM_BUFFERS, new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); metricRegistry.register(PROP_METRIC_REG_JVM_ATTRIBUTE_SET, new JvmAttributeGaugeSet()); if (jHipsterProperties.getMetrics().getJmx().isEnabled()) { log.debug("Initializing Metrics JMX reporting"); JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build(); jmxReporter.start(); } if (jHipsterProperties.getMetrics().getLogs().isEnabled()) { log.info("Initializing Metrics Log reporting"); Marker metricsMarker = MarkerFactory.getMarker("metrics"); final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry) .outputTo(LoggerFactory.getLogger("metrics")) .markWith(metricsMarker) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(jHipsterProperties.getMetrics().getLogs().getReportFrequency(), TimeUnit.SECONDS); } }
public static void initialize(MetricRegistry registry) { if (Metrics.registry != null) { throw new IllegalStateException("Metrics were already initialized."); } Metrics.registry = registry; registry.register("memory_usage", new MemoryUsageGaugeSet()); registry.register("garbage_collector", new GarbageCollectorMetricSet()); registry.register("jvm_attributes", new JvmAttributeGaugeSet()); final JmxReporter jmxReporter = JmxReporter.forRegistry(registry).build(); jmxReporter.start(); final Slf4jReporter slf4jReporter = Slf4jReporter.forRegistry(registry) .outputTo(LoggerFactory.getLogger("com.puresoltechnologies.famility.server.metrics")) .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(); slf4jReporter.start(1, TimeUnit.MINUTES); }
@PostConstruct public void init() { log.debug("Registering JVM gauges"); metricRegistry.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet()); metricRegistry.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet()); metricRegistry.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet()); metricRegistry.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge()); metricRegistry.register(PROP_METRIC_REG_JVM_BUFFERS, new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); metricRegistry.register(PROP_METRIC_REG_JVM_ATTRIBUTE_SET, new JvmAttributeGaugeSet()); if (hikariDataSource != null) { log.debug("Monitoring the datasource"); hikariDataSource.setMetricRegistry(metricRegistry); } if (jHipsterProperties.getMetrics().getJmx().isEnabled()) { log.debug("Initializing Metrics JMX reporting"); JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build(); jmxReporter.start(); } if (jHipsterProperties.getMetrics().getLogs().isEnabled()) { log.info("Initializing Metrics Log reporting"); Marker metricsMarker = MarkerFactory.getMarker("metrics"); final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry) .outputTo(LoggerFactory.getLogger("metrics")) .markWith(metricsMarker) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(jHipsterProperties.getMetrics().getLogs().getReportFrequency(), TimeUnit.SECONDS); } }
@PostConstruct public void init() { log.debug("Registering JVM gauges"); metricRegistry.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet()); metricRegistry.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet()); metricRegistry.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet()); metricRegistry.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge()); metricRegistry.register(PROP_METRIC_REG_JVM_BUFFERS, new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); metricRegistry.register(PROP_METRIC_REG_JVM_ATTRIBUTE_SET, new JvmAttributeGaugeSet()); metricRegistry.register(PROP_METRIC_REG_JCACHE_STATISTICS, new JCacheGaugeSet()); if (hikariDataSource != null) { log.debug("Monitoring the datasource"); hikariDataSource.setMetricRegistry(metricRegistry); } if (jHipsterProperties.getMetrics().getJmx().isEnabled()) { log.debug("Initializing Metrics JMX reporting"); JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build(); jmxReporter.start(); } if (jHipsterProperties.getMetrics().getLogs().isEnabled()) { log.info("Initializing Metrics Log reporting"); Marker metricsMarker = MarkerFactory.getMarker("metrics"); final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry) .outputTo(LoggerFactory.getLogger("metrics")) .markWith(metricsMarker) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(jHipsterProperties.getMetrics().getLogs().getReportFrequency(), TimeUnit.SECONDS); } }
private void initRegistry() { // add JVM statistics metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet()); metricRegistry.register("jvm.vm", new JvmAttributeGaugeSet()); metricRegistry.register("jvm.garbage-collectors", new GarbageCollectorMetricSet()); metricRegistry.register("jvm.thread-states", new ThreadStatesGaugeSet()); if (hBaseAsyncOperationMetrics != null) { Map<String, Metric> metrics = hBaseAsyncOperationMetrics.getMetrics(); for (Map.Entry<String, Metric> metric : metrics.entrySet()) { metricRegistry.register(metric.getKey(), metric.getValue()); } } }
@Test public void testJVM() throws InterruptedException { METRIC_REGISTRY.register("jvm.memory", new MemoryUsageGaugeSet()); METRIC_REGISTRY.register("jvm.vm", new JvmAttributeGaugeSet()); METRIC_REGISTRY.register("jvm.gc", new GarbageCollectorMetricSet()); METRIC_REGISTRY.register("jvm.thread", new ThreadStatesGaugeSet()); METRIC_REGISTRY.register("jvm.class", new ClassLoadingGaugeSet()); METRIC_REGISTRY.register("jvm.fd", new FileDescriptorRatioGauge()); Thread.sleep(5 * 1000); }
@Inject public MetricsServlet(final MetricRegistry registry) { super(registry); // JVM metrics are no longer automatically added in codahale-metrics registry.register(name("jvm", "vm"), new JvmAttributeGaugeSet()); registry.register(name("jvm", "memory"), new MemoryUsageGaugeSet()); registry.register(name("jvm", "buffers"), new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); registry.register(name("jvm", "fd_usage"), new FileDescriptorRatioGauge()); registry.register(name("jvm", "thread-states"), new ThreadStatesGaugeSet()); registry.register(name("jvm", "garbage-collectors"), new GarbageCollectorMetricSet()); }
public JvmAttributeGaugeSet registerJvmAttributeMonitor(MonitorName monitorName) { if (monitorName == null) { throw new NullPointerException("monitorName must not be null"); } return this.delegate.register(monitorName.getName(), new JvmAttributeGaugeSet()); }