@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())); 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"); final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry) .outputTo(LoggerFactory.getLogger("metrics")) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(jHipsterProperties.getMetrics().getLogs().getReportFrequency(), TimeUnit.SECONDS); } }
/** * Construct the Cruise Control * * @param config the configuration of Cruise Control. */ public KafkaCruiseControl(KafkaCruiseControlConfig config) { _config = config; _time = new SystemTime(); // initialize some of the static state of Kafka Cruise Control; Load.init(config); ModelUtils.init(config); ModelParameters.init(config); _dropwizardMetricRegistry = new MetricRegistry(); _reporter = JmxReporter.forRegistry(_dropwizardMetricRegistry).inDomain(_metricsPrefix).build(); // Instantiate the components. _loadMonitor = new LoadMonitor(config, _time, _dropwizardMetricRegistry); _goalOptimizerExecutor = Executors.newSingleThreadExecutor(new KafkaCruiseControlThreadFactory("GoalOptimizerExecutor", true, null)); _goalOptimizer = new GoalOptimizer(config, _loadMonitor, _time, _dropwizardMetricRegistry); _executor = new Executor(config, _time, _dropwizardMetricRegistry); _anomalyDetector = new AnomalyDetector(config, _loadMonitor, this, _time, _dropwizardMetricRegistry); }
@Override public void configureReporters(final MetricRegistry metricRegistry) { final Logger perfStatsLogger = LoggerFactory.getLogger(casProperties.getMetrics().getLoggerName()); registerReporter(Slf4jReporter .forRegistry(metricRegistry) .outputTo(perfStatsLogger) .convertRatesTo(TimeUnit.MILLISECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build()) .start(casProperties.getMetrics().getRefreshInterval(), TimeUnit.SECONDS); registerReporter(JmxReporter .forRegistry(metricRegistry) .build()); }
/** * Start metrics reporter. * */ protected void startReporter() { switch (cxt.conf.reporter) { case "console": consoleReporter = ConsoleReporter.forRegistry(cxt.register) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); consoleReporter.start(cxt.conf.report_interval, TimeUnit.SECONDS); break; case "jmx": jmxReporter = JmxReporter.forRegistry(cxt.register).build(); jmxReporter.start(); break; default: break; } }
public void init() { try { if (config.isJMXEnabled()) { jmxReporter = JmxReporter.forRegistry(metrics).build(); jmxReporter.start(); } if (config.isAutoShutDown()) { autoShutDownScheduler .scheduleWithFixedDelay(this::shutDown, delayInSecs, delayInSecs, SECONDS); } logger.info("Initializing StatCollector file : " + statFileName); statChannel = FileChannel.open(Paths.get(statFileName), CREATE, WRITE); } catch (IOException e) { logger.error("Error while creating stat file " + statFileName, e); } rsyncFailed = metrics.meter(name(INDUCTOR, "rsyncFailure")); woFailed = metrics.meter(name(INDUCTOR, "woFailure")); format = new DecimalFormat(); format.setMaximumFractionDigits(2); statScheduler .scheduleWithFixedDelay(this::writeStat, delayInSecs, delayInSecs, SECONDS); }
public static void main(String[] args) throws Exception { try { Log.info("Starting application"); org.apache.log4j.PropertyConfigurator.configure(getProperties("log4j.properties")); org.apache.log4j.BasicConfigurator.configure(); JmxReporter.forRegistry(metricRegistry).build().start(); Properties producerProps = getProperties("producer.properties"); Properties appProperties = getProperties("app.properties"); int port = Integer.parseInt(appProperties.getProperty("port", "6306")); boolean useInternalMeter = Integer.parseInt(appProperties.getProperty("useInternalMeter", "0")) > 0; eventSender = new EventSender(producerProps); httpServer = new HttpServer(eventSender, getValidatorFactory(), useInternalMeter).listen(port); Log.info("Application started"); } catch (Exception ex) { Log.error("Main error", ex); } Runtime.getRuntime().addShutdownHook(new Thread(Application::shutdown)); new BufferedReader(new InputStreamReader(System.in)).readLine(); }
public static void enableJvm() { if (bEnableJvm) return; METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet()); METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet()); METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet()); METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge()); METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_BUFFERS, new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); final JmxReporter jmxReporter = JmxReporter.forRegistry(METRIC_REGISTRY).build(); jmxReporter.start(); bEnableJvm = true; }
@Override public void configureReporters(MetricRegistry metricRegistry) { final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory(); final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME); final InstrumentedAppender metrics = new InstrumentedAppender(metricRegistry); metrics.setContext(root.getLoggerContext()); metrics.start(); root.addAppender(metrics); JmxReporter.forRegistry(metricRegistry).build().start(); Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry) .outputTo(LoggerFactory.getLogger("metrics")) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(1, TimeUnit.MINUTES); }
private static void init() { // Init JMX reporter reporter = JmxReporter.forRegistry(registry).build(); reporter.start(); // Init graphite reporter Graphite graphite = getGraphite(); GraphiteReporter graphiteReporter; if (graphite == null) { graphiteReporter = null; } else { graphiteReporter = GraphiteReporter.forRegistry(registry).prefixedWith(PREFIX).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite); graphiteReporter.start(AuditConfig.GRAPHITE_REPORT_PERIOD_SEC, TimeUnit.SECONDS); } }
@Named("APIResourceConfig") @Singleton @Provides public ResourceConfig getAPIResourceConfig(StateMachineResource stateMachineResource, DeploymentUnitResource deploymentUnitResource, StatusResource statusResource, MetricRegistry metricRegistry) { ResourceConfig resourceConfig = new ResourceConfig(); //Register codahale metrics and publish to jmx resourceConfig.register(new InstrumentedResourceMethodApplicationListener(metricRegistry)); JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build(); //register resources resourceConfig.register(stateMachineResource); resourceConfig.register(deploymentUnitResource); resourceConfig.register(statusResource); resourceConfig.register(CORSFilter.class); jmxReporter.start(); return resourceConfig; }
@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); } }
@Override public void activateService() { metricRegistry = new MetricRegistry(); healthCheckRegistry = new HealthCheckRegistry(); CodahaleMetricsDeclaration declaration = descriptor.metaInfo( CodahaleMetricsDeclaration.class ); prefix = declaration.prefix() != null ? declaration.prefix() : app.name(); fqcn = declaration.fqcn(); if( declaration.jmx() ) { JmxReporter jmxReporter = JmxReporter.forRegistry( metricRegistry ).build(); jmxReporter.start(); reporters.add( jmxReporter ); } for( Function<MetricRegistry, Reporter> reporterFactory : declaration.reportersFactories()) { reporters.add( reporterFactory.apply( metricRegistry ) ); } }
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); }
public static void main(String[] args) { SpringApplication.run(MonetaSpringBootApplication.class, args); // Find and read application configuration MonetaConfiguration config = new MonetaConfiguration(); // Install all health checks HealthCheckRegistry registry = new HealthCheckRegistry(); for (String checkName : MonetaEnvironment.getConfiguration() .getHealthChecks() .keySet()) { registry.register(checkName, MonetaEnvironment.getConfiguration() .getHealthChecks() .get(checkName)); } ActuatorHealthIndicator.setHealthCheckRegistry(registry); // Install metrics and JMX MetricRegistry metricRegistry = new MetricRegistry(); final JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry) .build(); jmxReporter.start(); }
private void registerJmxReporter(@NonNull final RunRightFastVerticleDeployment deployment) { if (verticleJmxReporters.containsKey(deployment)) { return; } if (globalDeployedVerticles.values().contains(deployment)) { return; } final RunRightFastVerticleId verticleId = deployment.getRunRightFastVerticleId(); final JmxReporter jmxReporter = JmxReporter.forRegistry(deployment.getMetricRegistry()) .inDomain(verticleId.verticleJmxDomain("metrics")) .convertDurationsTo(TimeUnit.MILLISECONDS) .convertRatesTo(TimeUnit.SECONDS) .build(); jmxReporter.start(); verticleJmxReporters = ImmutableMap.<RunRightFastVerticleDeployment, JmxReporter>builder() .putAll(verticleJmxReporters) .put(deployment, jmxReporter) .build(); }
/** * It appears to be ok to start multiple JMX reporters for the same MetricRegistry within the same domain. */ @Test public void testStartingDuplicateMetricsJmxReporter() { final MetricRegistry metricRegistry = new MetricRegistry(); final List<JmxReporter> reporters = new LinkedList<>(); try { for (int i = 0; i < 2; i++) { reporters.add(jmxReporter(metricRegistry)); } } finally { reporters.stream().forEach(JmxReporter::stop); } metricRegistry.counter("counter").inc(); log.info("counter = " + metricRegistry.counter("counter").getCount()); }
@Provides(type = Type.SET) ContextConfigurator provideJMX(final MetricRegistry metrics) { return new ContextConfigurator() { private JmxReporter reporter; @Override public void init(ServletContextHandler context) { context.setAttribute("com.codahale.metrics.servlets.MetricsServlet.registry", metrics); ServletHolder servlet = new ServletHolder(new JMXJsonServlet()); context.addServlet(servlet, "/rest/v1/system/jmx"); } @Override public void start() { reporter = JmxReporter.forRegistry(metrics).build(); reporter.start(); } @Override public void stop() { if(reporter != null) { reporter.stop(); reporter.close(); } } }; }
@Override public void startDefaultEndpoint() { String domain = (String)configuration.get("domain"); if (domain == null) { domain = "metrics"; } LOGGER.fine("Starting JMX reporter at domain: " + domain); JmxReporter .forRegistry(registry) .inDomain(domain) .convertDurationsTo(TimeUnit.MILLISECONDS) .convertRatesTo(TimeUnit.MINUTES) .build() .start(); }