public JvmMetricSet() { registerSet("jvm.buffers", new BufferPoolMetricSet(getPlatformMBeanServer())); registerSet("jvm.classloading", new ClassLoadingGaugeSet()); registerSet("jvm.fd", new FileDescriptorMetrics()); registerSet("jvm.gc", new GarbageCollectorMetricSet()); registerSet("jvm.memory", new MemoryUsageGaugeSet()); registerSet("jvm.thread", new CachedThreadStatesGaugeSet(60, TimeUnit.SECONDS)); metrics.put("jvm.uptime", new UptimeGauge()); try { metrics.put("jvm.processCPU", new ProcessCpuTicksGauge()); } catch (ClassNotFoundException | IOException e) { LOGGER.error("Error fetching process CPU usage metrics.", e); } }
public CloudWatchReporter build() { if (withJvmMetrics) { metricRegistry.register("jvm.uptime", (Gauge<Long>) () -> ManagementFactory.getRuntimeMXBean().getUptime()); metricRegistry.register("jvm.current_time", (Gauge<Long>) clock::getTime); metricRegistry.register("jvm.classes", new ClassLoadingGaugeSet()); metricRegistry.register("jvm.fd_usage", new FileDescriptorRatioGauge()); metricRegistry.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet()); metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet()); metricRegistry.register("jvm.thread-states", new ThreadStatesGaugeSet()); } cwRateUnit = toStandardUnit(rateUnit); cwDurationUnit = toStandardUnit(durationUnit); return new CloudWatchReporter(this); }
private void addJVMMetrics(Map<String, Object> configuration) { if (!configuration.containsKey("jvm")) { return; } Set<String> jvmMetrics = new HashSet<String>((List<String>)configuration.get("jvm")); if (jvmMetrics.contains("gc")) { registry.register("gc", new GarbageCollectorMetricSet()); } if (jvmMetrics.contains("threads")) { registry.register("threads", new CachedThreadStatesGaugeSet(10, TimeUnit.SECONDS)); } if (jvmMetrics.contains("memory")) { registry.register("memory", new MemoryUsageGaugeSet()); } if (jvmMetrics.contains("classloader")) { registry.register("memory", new ClassLoadingGaugeSet()); } }
private static void configureJvmMetrics(MetricRegistry registry) { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); registry.register("jvm.buffer-pool", new BufferPoolMetricSet(mBeanServer)); registry.register("jvm.class-loading", new ClassLoadingGaugeSet()); registry.register("jvm.file-descriptor-ratio", new FileDescriptorRatioGauge()); registry.register("jvm.gc", new GarbageCollectorMetricSet()); registry.register("jvm.memory", new MemoryUsageGaugeSet()); registry.register("jvm.threads", new ThreadStatesGaugeSet()); }
@PostConstruct public void init() { // ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry) // .convertRatesTo(TimeUnit.SECONDS) // .convertDurationsTo(TimeUnit.MILLISECONDS) // .build(); // // consoleReporter.start(10, TimeUnit.SECONDS); // Graphite graphite = new Graphite(new InetSocketAddress("192.168.99.100", 2003)); // GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry) // .prefixedWith("com.packt.microservices.geolocation") // .convertRatesTo(TimeUnit.SECONDS) // .convertDurationsTo(TimeUnit.MILLISECONDS) // .filter(MetricFilter.ALL) // .build(graphite); // graphiteReporter.start(60, TimeUnit.SECONDS); geolocationWriteRequestCount = metricRegistry.counter("geolocationWriteRequestCount"); metricRegistry.register("geolocationLastWriteTime", new Gauge<Long>() { @Override public Long getValue() { return geolocationLastWriteTime; } }); metricRegistry.registerAll(new MetricSet() { @Override public Map<String, Metric> getMetrics() { Map<String, Metric> metrics = new HashMap<>(); metrics.put("geolocationMemoryUsage", new MemoryUsageGaugeSet()); metrics.put("geolocationClassLoading", new ClassLoadingGaugeSet()); metrics.put("geolocationGarbageCollector", new GarbageCollectorMetricSet()); return metrics; } }); }
@Override public void run(String... strings) throws Exception { // JVM metrics ala Dropwizard metrics-jvm metricRegistry.registerAll(new MemoryUsageGaugeSet()); metricRegistry.registerAll(new ThreadStatesGaugeSet()); metricRegistry.registerAll(new GarbageCollectorMetricSet()); metricRegistry.registerAll(new ClassLoadingGaugeSet()); // start collecting w/ statsd via ReadyTalk client reporter.start(statsdSettings.getPublishingIntervalInMillis(), TimeUnit.MILLISECONDS); }
@Override public void start() { String applicationName = settings.getApplicationName(); // Register optional metrics if (settings.getBoolean(Settings.Setting.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"); } // MBeans for VisualVM, JConsole, or JMX if (settings.getBoolean(Settings.Setting.metrics_mbeans_enabled, false)) { JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).inDomain(applicationName).build(); reporter.start(); reporters.add(reporter); log.debug("Started metrics MBeans reporter"); } // Add classpath reporters ServiceLocator.locateAll(MetricsReporter.class).forEach((reporter) -> { if (RequireUtil.allowInstance(settings, reporter)) { reporter.start(settings, metricRegistry); reporters.add(reporter); } }); }
/** * @see io.dropwizard.Application#run(io.dropwizard.Configuration, io.dropwizard.setup.Environment) */ public void run(SPQRNodeServerConfiguration configuration, Environment environment) throws Exception { // initialize log4j environment using the settings provided via node configuration initializeLog4j(configuration.getSpqrNode().getLog4jConfiguration()); // check which type of resource management is requested via configuration if(configuration.getResourceManagerConfiguration().getMode() == ResourceManagerMode.REMOTE) { // prepare for use remote resource management: fetch configuration SPQRResourceManagerConfiguration resManCfg = configuration.getResourceManagerConfiguration(); logger.info("[resource manager [mode="+ResourceManagerMode.REMOTE+", protocol="+resManCfg.getProtocol()+", host="+resManCfg.getHost()+", port="+resManCfg.getPort()+"]"); // initialize client to use for remote communication this.resourceManagerClient = new SPQRResourceManagerClient(resManCfg.getProtocol(), resManCfg.getHost(), resManCfg.getPort(), new JerseyClientBuilder(environment).using(configuration.getHttpClient()).build("resourceManagerClient")); // finally: register node with remote resource manager this.nodeId = registerProcessingNode(configuration.getSpqrNode().getProtocol(), configuration.getSpqrNode().getHost(), configuration.getSpqrNode().getServicePort(), configuration.getSpqrNode().getAdminPort(), this.resourceManagerClient); logger.info("node successfully registered [id="+nodeId+", proto="+configuration.getSpqrNode().getProtocol()+", host="+configuration.getSpqrNode().getHost()+", servicePort="+configuration.getSpqrNode().getServicePort()+", adminPort="+configuration.getSpqrNode().getAdminPort()+"]"); } else { this.nodeId = "standalone"; this.resourceManagerClient = null; logger.info("resource manager [mode="+ResourceManagerMode.LOCAL+"]"); } // initialize the micro pipeline manager this.microPipelineManager = new MicroPipelineManager(this.nodeId, loadAndDeployApplicationRepository(configuration.getSpqrNode().getComponentRepositoryFolder()), configuration.getSpqrNode().getNumOfThreads()); logger.info("pipeline manager initialized [threads="+configuration.getSpqrNode().getNumOfThreads()+", repo="+configuration.getSpqrNode().getComponentRepositoryFolder()+"]"); // register exposed resources environment.jersey().register(new MicroPipelineResource(this.microPipelineManager)); // register shutdown handler Runtime.getRuntime().addShutdownHook(new SPQRNodeShutdownHandler(this.microPipelineManager, this.resourceManagerClient, nodeId)); // register metrics handler MetricsHandler handler = new MetricsHandler(); if(configuration.getSpqrNode().getSpqrMetrics() != null) { final SPQRNodeMetricsConfiguration metricsCfg = configuration.getSpqrNode().getSpqrMetrics(); if(metricsCfg.getMetricsReporter() != null && !metricsCfg.getMetricsReporter().isEmpty()) { if(metricsCfg.isAttachClassLoadingMetricCollector()) { handler.register(new ClassLoadingGaugeSet()); } if(metricsCfg.isAttachFileDescriptorMetricCollector()) { handler.register("fs", new FileDescriptorRatioGauge()); } if(metricsCfg.isAttachGCMetricCollector()) { handler.register(new GarbageCollectorMetricSet()); } if(metricsCfg.isAttachMemoryUsageMetricCollector()) { handler.register(new MemoryUsageGaugeSet()); } if(metricsCfg.isAttachThreadStateMetricCollector()) { handler.register(new ThreadStatesGaugeSet()); } MetricsReporterFactory.attachReporters(handler, metricsCfg.getMetricsReporter()); logger.info("metrics[classloader="+metricsCfg.isAttachClassLoadingMetricCollector()+ ",fileSystem="+metricsCfg.isAttachFileDescriptorMetricCollector()+ ",gc="+metricsCfg.isAttachGCMetricCollector()+ ",memory="+metricsCfg.isAttachMemoryUsageMetricCollector()+ ",threadState="+metricsCfg.isAttachThreadStateMetricCollector()+"]"); StringBuffer buf = new StringBuffer(); for(final MicroPipelineMetricsReporterConfiguration mr : metricsCfg.getMetricsReporter()) { buf.append("(id=").append(mr.getId()).append(", type=").append(mr.getType()).append(")"); } logger.info("metricReporters["+buf.toString()+"]"); } } else { logger.info("no metrics and metric reporters configured for processing node '"+nodeId+"'"); } }
private void registerMetrics( Application application, MetricRegistry metrics ) { Config config = application.config().atKey( "metrics" ); // JVM Meters if( config.bool( "jvm.bufferpools.enabled" ) ) { metrics.register( "jvm.bufferpools", new BufferPoolMetricSet( getPlatformMBeanServer() ) ); } if( config.bool( "jvm.threadstates.enabled" ) ) { metrics.register( "jvm.threadstates", new ThreadStatesGaugeSet() ); } if( config.bool( "jvm.classloading.enabled" ) ) { metrics.register( "jvm.classloading", new ClassLoadingGaugeSet() ); } if( config.bool( "jvm.garbagecollection.enabled" ) ) { metrics.register( "jvm.garbagecollection", new GarbageCollectorMetricSet() ); } if( config.bool( "jvm.memory.enabled" ) ) { metrics.register( "jvm.memory", new MemoryUsageGaugeSet() ); } if( config.bool( "jvm.filedescriptors.enabled" ) ) { metrics.register( "jvm.filedescriptors.ratio", new FileDescriptorRatioGauge() ); } // Connection & HTTP Metrics requestTimers = new ConcurrentHashMap<>(); eventRegistration = application.events().registerListener( new EventListener( metrics, requestTimers, config.bool( "http.connections.enabled" ), config.bool( "http.requests.enabled" ), config.bool( "http.success.enabled" ), config.bool( "http.redirections.enabled" ), config.bool( "http.client_errors.enabled" ), config.bool( "http.server_errors.enabled" ), config.bool( "http.unknown.enabled" ) ) ); }