/** * Returns the named registry * * @param name the registry name * @param onf An optional ObjectNameFactory for this registry * @return the registry */ public MetricRegistry getRegistry(final String name, final ObjectNameFactory onf) { if (name == null || name.trim().isEmpty()) throw new IllegalArgumentException("Metric registry name was null"); final String mname = name.trim(); MetricRegistry m = subRegistries.get(mname); if (m == null) { synchronized (subRegistries) { m = subRegistries.get(mname); if (m == null) { m = new MetricRegistry(); subRegistries.put(mname, m); final Builder builder = JmxReporter.forRegistry(m) .inDomain("org.helios.nash.metrics") .registerWith(JMXHelper.getHeliosMBeanServer()); if (onf != null) { builder.createsObjectNamesWith(onf); } final JmxReporter reporter = builder.build(); subReporters.put(mname, reporter); reporter.start(); } } } return m; }
@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(); } }
@Override public void run() { final Level logLevel = setupLogger(); final PluginBindings pluginBindings = installPluginConfigAndBindings(getPluginPath(configFile)); if (isDumpDefaultConfig()) { dumpDefaultConfigAndExit(); } final NamedConfigParametersModule configModule = readConfiguration(configFile); if (isDumpConfig()) { dumpCurrentConfigAndExit(); } if (!validateConfiguration()) { LOG.error("Validating configuration file failed - exiting."); System.exit(1); } final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments)); injector = setupInjector(configModule, pluginBindings); if (injector == null) { LOG.error( "Injector could not be created, exiting! (Please include the previous error messages in bug reports.)"); System.exit(1); } // This is holding all our metrics. final MetricRegistry metrics = injector.getInstance(MetricRegistry.class); addInstrumentedAppender(metrics, logLevel); // Report metrics via JMX. final JmxReporter reporter = JmxReporter.forRegistry(metrics).build(); reporter.start(); startCommand(); }
static { Configuration config = Configuration.getInstance(); // register jvm metrics MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); if (!System.getProperty("java.version").split("\\.")[1].equals("6")) { // if not running 1.6 registry.registerAll( new PrefixedMetricSet(new BufferPoolMetricSet(mbs), JVM_PREFIX, "buffer-pool")); } registry.registerAll(new PrefixedMetricSet(new GarbageCollectorMetricSet(), JVM_PREFIX, "gc")); registry.registerAll(new PrefixedMetricSet(new MemoryUsageGaugeSet(), JVM_PREFIX, "memory")); registry.registerAll( new PrefixedMetricSet(new ThreadStatesGaugeSet(), JVM_PREFIX, "thread-states")); // instrument log4j InstrumentedAppender appender = new InstrumentedAppender(registry); appender.activateOptions(); LogManager.getRootLogger().addAppender(appender); if (!config.getStringProperty(CoreConfig.RIEMANN_HOST).equals("")) { RiemannReporter tmpreporter; try { Riemann riemann = new Riemann( config.getStringProperty(CoreConfig.RIEMANN_HOST), config.getIntegerProperty(CoreConfig.RIEMANN_PORT)); RiemannReporter.Builder builder = RiemannReporter.forRegistry(registry) .convertDurationsTo(TimeUnit.MILLISECONDS) .convertRatesTo(TimeUnit.SECONDS); if (!config.getStringProperty(CoreConfig.RIEMANN_SEPARATOR).isEmpty()) { builder.useSeparator(config.getStringProperty(CoreConfig.RIEMANN_SEPARATOR)); } if (!config.getStringProperty(CoreConfig.RIEMANN_TTL).isEmpty()) { builder.withTtl(config.getFloatProperty(CoreConfig.RIEMANN_TTL)); } if (!config.getStringProperty(CoreConfig.RIEMANN_LOCALHOST).isEmpty()) { builder.localHost(config.getStringProperty(CoreConfig.RIEMANN_LOCALHOST)); } if (!config.getStringProperty(CoreConfig.RIEMANN_PREFIX).isEmpty()) { builder.prefixedWith(config.getStringProperty(CoreConfig.RIEMANN_PREFIX)); } if (!config.getStringProperty(CoreConfig.RIEMANN_TAGS).isEmpty()) { builder.tags(config.getListProperty(CoreConfig.RIEMANN_TAGS)); } tmpreporter = builder.build(riemann); tmpreporter.start(30l, TimeUnit.SECONDS); } catch (IOException e) { tmpreporter = null; } reporter1 = tmpreporter; } else { reporter1 = null; } if (!config.getStringProperty(CoreConfig.GRAPHITE_HOST).equals("")) { Graphite graphite = new Graphite( new InetSocketAddress( config.getStringProperty(CoreConfig.GRAPHITE_HOST), config.getIntegerProperty(CoreConfig.GRAPHITE_PORT))); reporter = GraphiteReporter.forRegistry(registry) .convertDurationsTo(TimeUnit.MILLISECONDS) .convertRatesTo(TimeUnit.SECONDS) .prefixedWith(config.getStringProperty(CoreConfig.GRAPHITE_PREFIX)) .build(graphite); reporter.start(30l, TimeUnit.SECONDS); } else { reporter = null; } reporter2 = JmxReporter.forRegistry(registry) .convertDurationsTo(TimeUnit.MILLISECONDS) .convertRatesTo(TimeUnit.SECONDS) .build(); reporter2.start(); }
static { reporter = JmxReporter.forRegistry(metrics).build(); reporter.start(); }
/** * @param queueSize * @param maxBatchSize */ public CassandraBatchedStagedWriter(CassandraConnection connection, int batchSize) { super(Math.min(100000, batchSize * 100), batchSize); this.connection = requireNonNull(connection); final JmxReporter reporter = JmxReporter.forRegistry(metrics).inDomain("fooo.erer.er").build(); reporter.start(); }
private void reportToJMX(MetricRegistry metricRegistry, MetricFilter filter) { final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).filter(filter).build(); reporter.start(); reporters.add(reporter); }