com.codahale.metrics.jvm.GarbageCollectorMetricSet Java Examples

The following examples show how to use com.codahale.metrics.jvm.GarbageCollectorMetricSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetStarted.java    From metrics-zabbix with Apache License 2.0 6 votes vote down vote up
public static void main(String args[]) throws IOException, InterruptedException {
	ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS)
			.convertDurationsTo(TimeUnit.MILLISECONDS).build();
	metrics.register("jvm.mem", new MemoryUsageGaugeSet());
	metrics.register("jvm.gc", new GarbageCollectorMetricSet());
	reporter.start(5, TimeUnit.SECONDS);

	String hostName = "192.168.66.29";
	ZabbixSender zabbixSender = new ZabbixSender("192.168.90.102", 10051);
	ZabbixReporter zabbixReporter = ZabbixReporter.forRegistry(metrics).hostName(hostName).prefix("test.")
			.build(zabbixSender);

	zabbixReporter.start(1, TimeUnit.SECONDS);

	TimeUnit.SECONDS.sleep(500);
}
 
Example #2
Source File: Poseidon.java    From Poseidon with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: MetricsHelper.java    From lemon with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    /*
     * consoleReporter = ConsoleReporter.forRegistry(metricRegistry) .convertRatesTo(TimeUnit.SECONDS)
     * .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); consoleReporter.start(1, TimeUnit.SECONDS);
     */
    GarbageCollectorMetricSet gc = new GarbageCollectorMetricSet();

    // FileDescriptorRatioGauge fd = new FileDescriptorRatioGauge();
    MemoryUsageGaugeSet mu = new MemoryUsageGaugeSet();

    // ThreadDeadlockDetector td = new ThreadDeadlockDetector();

    // ThreadDump t = new ThreadDump();
    ThreadStatesGaugeSet ts = new ThreadStatesGaugeSet();

    metricRegistry.register("GarbageCollector", gc);
    // registry.register(FileDescriptorRatioGauge.class.getName(), fd);
    metricRegistry.register("MemoryUsage", mu);
    // registry.register(ThreadDeadlockDetector.class.getName(), td);
    // registry.registerAll(t);
    metricRegistry.register("ThreadStates", ts);
    healthCheckRegistry.register("threadDeadlock",
            new ThreadDeadlockHealthCheck());
}
 
Example #4
Source File: SolrDispatchFilter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void setupJvmMetrics(CoreContainer coresInit)  {
  metricManager = coresInit.getMetricManager();
  registryName = SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm);
  final Set<String> hiddenSysProps = coresInit.getConfig().getMetricsConfig().getHiddenSysProps();
  try {
    metricManager.registerAll(registryName, new AltBufferPoolMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "buffers");
    metricManager.registerAll(registryName, new ClassLoadingGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "classes");
    metricManager.registerAll(registryName, new OperatingSystemMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "os");
    metricManager.registerAll(registryName, new GarbageCollectorMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "gc");
    metricManager.registerAll(registryName, new MemoryUsageGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "memory");
    metricManager.registerAll(registryName, new ThreadStatesGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "threads"); // todo should we use CachedThreadStatesGaugeSet instead?
    MetricsMap sysprops = new MetricsMap((detailed, map) -> {
      System.getProperties().forEach((k, v) -> {
        if (!hiddenSysProps.contains(k)) {
          map.put(String.valueOf(k), v);
        }
      });
    });
    metricManager.registerGauge(null, registryName, sysprops, metricTag, true, "properties", "system");
  } catch (Exception e) {
    log.warn("Error registering JVM metrics", e);
  }
}
 
Example #5
Source File: CloudWatchReporter.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 6 votes vote down vote up
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 = cwMeterUnit.orElse(toStandardUnit(rateUnit));
            cwDurationUnit = toStandardUnit(durationUnit);

            return new CloudWatchReporter(this);
        }
 
Example #6
Source File: TajoSystemMetrics.java    From tajo with Apache License 2.0 6 votes vote down vote up
public void start() {
  setMetricsReporter(metricsGroupName);

  final String jvmMetricsName = metricsGroupName + "-JVM";
  setMetricsReporter(jvmMetricsName);

  if(!inited) {
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "MEMORY"), new MemoryUsageGaugeSet());
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "FILE"), new FileDescriptorRatioGauge());
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "GC"), new GarbageCollectorMetricSet());
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "THREAD"), new ThreadStatesGaugeSet());
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "LOG"), new LogEventGaugeSet());
    jmxReporter = JmxReporter.forRegistry(metricRegistry).inDomain("Tajo")
            .createsObjectNamesWith(new TajoJMXObjectNameFactory()).build();
    jmxReporter.start();
  }
  inited = true;
}
 
Example #7
Source File: DefaultMetricsService.java    From knox with Apache License 2.0 5 votes vote down vote up
private void registerJvmMetricSets() {
  metrics.registerAll(new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
  metrics.registerAll(new CachedThreadStatesGaugeSet(5, TimeUnit.MINUTES));
  metrics.registerAll(new ClassLoadingGaugeSet());
  metrics.registerAll(new GarbageCollectorMetricSet());
  metrics.registerAll(new JvmAttributeGaugeSet());
  metrics.registerAll(new MemoryUsageGaugeSet());
}
 
Example #8
Source File: StreamSortHandlerTest.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    final MetricRegistry metrics = new MetricRegistry();
    metrics.registerAll(new MemoryUsageGaugeSet());
    metrics.registerAll(new GarbageCollectorMetricSet());
    metricReporter = Slf4jReporter.forRegistry(metrics)
        .filter((name, metric) -> name.matches("(.*heap|pools.PS.*).usage"))
        .withLoggingLevel(Slf4jReporter.LoggingLevel.DEBUG)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .build();
    metricReporter.start(60, TimeUnit.SECONDS);
}
 
Example #9
Source File: StreamWindowBenchmarkTest.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Before
    public void setUp() {
        final MetricRegistry metrics = new MetricRegistry();
        metrics.registerAll(new MemoryUsageGaugeSet());
        metrics.registerAll(new GarbageCollectorMetricSet());
        metricReporter = ConsoleReporter.forRegistry(metrics)
            .filter((name, metric) -> name.matches("(.*heap|total).(usage|used)"))
//                .withLoggingLevel(Slf4jReporter.LoggingLevel.DEBUG)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
        metricReporter.start(60, TimeUnit.SECONDS);
        performanceReport = new TreeMap<>();
    }
 
Example #10
Source File: MetricsModule.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton MetricRegistry provideMetrics() {
  MetricRegistry metrics = new MetricRegistry();
  metrics.register("jvm.memory", new MemoryUsageGaugeSet());
  metrics.register("jvm.garbage", new GarbageCollectorMetricSet());
  metrics.register("jvm.threads", new ThreadStatesGaugeSet());
  metrics.register("jvm.files", new FileDescriptorRatioGauge());
  metrics.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
  return metrics;
}
 
Example #11
Source File: StreamingMetrics.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * ThreadStatesGaugeSet & ClassLoadingGaugeSet are currently not registered.
 * metricRegistry.register("threads", new ThreadStatesGaugeSet());
 */
private StreamingMetrics() {
    if (METRICS_OPTION != null && !METRICS_OPTION.isEmpty()) {
        metricRegistry.register("gc", new GarbageCollectorMetricSet());
        metricRegistry.register("threads", new CachedThreadStatesGaugeSet(10, TimeUnit.SECONDS));
        metricRegistry.register("memory", new MemoryUsageGaugeSet());
    }
}
 
Example #12
Source File: DropWizardJVMMetrics.java    From james-project with Apache License 2.0 5 votes vote down vote up
public void start() {
    metricRegistry.register("jvm.file.descriptor", new FileDescriptorRatioGauge());
    metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet());
    metricRegistry.register("jvm.threads", new ThreadStatesGaugeSet());
    metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet());
    metricRegistry.register("jvm.class.loading", new ClassLoadingGaugeSet());
}
 
Example #13
Source File: MetricsServlet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@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());

  // Export to Prometheus
  new DropwizardExports(registry).register();
}
 
Example #14
Source File: TajoSystemMetrics.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
public void start() {
  setMetricsReporter(metricsGroupName);

  String jvmMetricsName = metricsGroupName + "-jvm";
  setMetricsReporter(jvmMetricsName);

  if(!inited) {
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "Heap"), new MemoryUsageGaugeSet());
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "File"), new FileDescriptorRatioGauge());
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "GC"), new GarbageCollectorMetricSet());
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "Thread"), new ThreadStatesGaugeSet());
    metricRegistry.register(MetricRegistry.name(jvmMetricsName, "Log"), new LogEventGaugeSet());
  }
  inited = true;
}
 
Example #15
Source File: JMXReportingService.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private void registerJvmMetrics() {
  registerMetricSetWithPrefix("jvm.gc", new GarbageCollectorMetricSet());
  registerMetricSetWithPrefix("jvm.memory", new MemoryUsageGaugeSet());
  registerMetricSetWithPrefix("jvm.threads", new ThreadStatesGaugeSet());
  this.metricRegistry.register("jvm.fileDescriptorRatio", new FileDescriptorRatioGauge());
  for (Map.Entry<String, MetricSet> metricSet : this.additionalMetricSets.entrySet()) {
    registerMetricSetWithPrefix(metricSet.getKey(), metricSet.getValue());
  }
}
 
Example #16
Source File: MetricsConfiguration.java    From chassis with Apache License 2.0 5 votes vote down vote up
/***
    * Initializes the metrics registry
    *
    * @return metric registry bean
    */
@Bean
public MetricRegistry metricRegistry() {
	final MetricRegistry bean = new MetricRegistry();

       // add JVM metrics
	bean.register("jvm.gc", new GarbageCollectorMetricSet());
	bean.register("jvm.memory", new MemoryUsageGaugeSet());
	bean.register("jvm.thread-states", new ThreadStatesGaugeSet());
	bean.register("jvm.fd", new FileDescriptorRatioGauge());

	return bean;
}
 
Example #17
Source File: ChassisConfiguration.java    From chassis with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the metrics registry
 *
 * @return metric registry bean
 */
@Bean
public MetricRegistry metricRegistry() {
    final MetricRegistry bean = new MetricRegistry();

    // add JVM metrics
    bean.register("jvm.gc", new GarbageCollectorMetricSet());
    bean.register("jvm.memory", new MemoryUsageGaugeSet());
    bean.register("jvm.thread-states", new ThreadStatesGaugeSet());
    bean.register("jvm.fd", new FileDescriptorRatioGauge());
    bean.register("jvm.load-average", new Gauge<Double>() {
        private OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();

        public Double getValue() {
            try {
                return mxBean.getSystemLoadAverage();
            } catch (Exception e) {
                // not supported
                return -1d;
            }
        }
    });

    // add Logback metrics
    final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
    final InstrumentedAppender appender = new InstrumentedAppender(bean);
    appender.setContext(root.getLoggerContext());
    appender.start();
    root.addAppender(appender);

    return bean;
}
 
Example #18
Source File: CollectorMetric.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example #19
Source File: JmxJvmMetrics.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static JmxJvmMetrics getInstance() {
    if (metricRegistry.get() == null) {
        metricRegistry.set(new MetricRegistry());
        metricRegistry.get().register(REGISTRY_METRICSET_JVM_ATTRIBUTES, new JvmAttributeGaugeSet());
        metricRegistry.get().register(REGISTRY_METRICSET_MEMORY, new MemoryUsageGaugeSet());
        metricRegistry.get().register(REGISTRY_METRICSET_THREADS, new ThreadStatesGaugeSet());
        metricRegistry.get().register(REGISTRY_METRICSET_GARBAGE_COLLECTORS, new GarbageCollectorMetricSet());
        metricRegistry.get().register(OS_FILEDESCRIPTOR_USAGE, new FileDescriptorRatioGauge());

    }
    return new JmxJvmMetrics();
}
 
Example #20
Source File: SentryMetrics.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private SentryMetrics() {
  registerMetricSet("gc", new GarbageCollectorMetricSet(), SentryMetricsServletContextListener.METRIC_REGISTRY);
  registerMetricSet("buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()),
      SentryMetricsServletContextListener.METRIC_REGISTRY);
  registerMetricSet("memory", new MemoryUsageGaugeSet(), SentryMetricsServletContextListener.METRIC_REGISTRY);
  registerMetricSet("threads", new ThreadStatesGaugeSet(), SentryMetricsServletContextListener.METRIC_REGISTRY);
}
 
Example #21
Source File: RegisterJVMMetricsBuilder.java    From kite with Apache License 2.0 5 votes vote down vote up
public RegisterJVMMetrics(CommandBuilder builder, Config config, Command parent, 
                                   Command child, final MorphlineContext context) {
  
  super(builder, config, parent, child, context);      
  validateArguments();
  
  MetricRegistry registry = context.getMetricRegistry();
  BufferPoolMetricSet bufferPoolMetrics = new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer());
  registerAll("jvm.buffers", bufferPoolMetrics, registry);
  registerAll("jvm.gc", new GarbageCollectorMetricSet(), registry);
  registerAll("jvm.memory", new MemoryUsageGaugeSet(), registry);
  registerAll("jvm.threads", new ThreadStatesGaugeSet(), registry);
  register("jvm.fileDescriptorCountRatio", new FileDescriptorRatioGauge(), registry);
  context.getHealthCheckRegistry().register("deadlocks", new ThreadDeadlockHealthCheck());
}
 
Example #22
Source File: BookKeeperServer.java    From rubix with Apache License 2.0 5 votes vote down vote up
/**
 * Register desired metrics.
 */
protected void registerMetrics(Configuration conf)
{
  metrics.register(BookKeeperMetrics.BookKeeperJvmMetric.BOOKKEEPER_JVM_GC_PREFIX.getMetricName(), new GarbageCollectorMetricSet());
  metrics.register(BookKeeperMetrics.BookKeeperJvmMetric.BOOKKEEPER_JVM_THREADS_PREFIX.getMetricName(), new CachedThreadStatesGaugeSet(CacheConfig.getMetricsReportingInterval(conf), TimeUnit.MILLISECONDS));
  metrics.register(BookKeeperMetrics.BookKeeperJvmMetric.BOOKKEEPER_JVM_MEMORY_PREFIX.getMetricName(), new MemoryUsageGaugeSet());
}
 
Example #23
Source File: MetricsManager.java    From emissary with Apache License 2.0 5 votes vote down vote up
protected void initMetrics() {
    if (this.conf.findBooleanEntry("JVM_METRICS_ENABLED", false)) {
        logger.debug("JVM Metrics are enabled");
        this.metrics.registerAll(new MemoryUsageGaugeSet());
        this.metrics.registerAll(new GarbageCollectorMetricSet());
        this.metrics.registerAll(new ThreadStatesGaugeSet());
        this.metrics.register("file.descriptor.info", new FileDescriptorRatioGauge());
    } else {
        logger.debug("JVM Metrics are disabled");
    }
}
 
Example #24
Source File: JVMMetrics.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static void addJvmMetrics(MetricRegistries registries) {
  MetricRegistryInfo info = new MetricRegistryInfo("jvm", "ratis_jvm", "jvm", "jvm metrics");

  RatisMetricRegistry registry = registries.create(info);

  registry.registerAll("gc", new GarbageCollectorMetricSet());
  registry.registerAll("memory", new MemoryUsageGaugeSet());
  registry.registerAll("threads", new ThreadStatesGaugeSet());
  registry.registerAll("classLoading", new ClassLoadingGaugeSet());
}
 
Example #25
Source File: OneOpsMetrics.java    From oneops with Apache License 2.0 5 votes vote down vote up
/**
 * Add metrics JVM gauges.
 */
private void addJvmMetrics() {
  if (getB("jvm.gcstats", false)) {
    ooMetricsRegistry.registerAll(new GarbageCollectorMetricSet());
  }
  if (getB("jvm.memory", false)) {
    ooMetricsRegistry.registerAll(new MemoryUsageGaugeSet());
  }
  if (getB("jvm.threadstate", false)) {
    ooMetricsRegistry.registerAll(new ThreadStatesGaugeSet());
  }
  if (getB("jvm.filedescriptor", false)) {
    ooMetricsRegistry.register("openfd.ratio", new FileDescriptorRatioGauge());
  }
}
 
Example #26
Source File: CoreMetrics.java    From styx with Apache License 2.0 5 votes vote down vote up
private static void registerJvmMetrics(MetricRegistry metricRegistry) {
    RuntimeMXBean runtimeMxBean = getRuntimeMXBean();

    MetricRegistry scoped = metricRegistry.scope("jvm");
    scoped.register("bufferpool", new BufferPoolMetricSet(getPlatformMBeanServer()));
    scoped.register("memory", new MemoryUsageGaugeSet());
    scoped.register("thread", new ThreadStatesGaugeSet());
    scoped.register("gc", new GarbageCollectorMetricSet());
    scoped.register("uptime", (Gauge<Long>) runtimeMxBean::getUptime);
    scoped.register("uptime.formatted", (Gauge<String>) () -> formatTime(runtimeMxBean.getUptime()));
    scoped.register("netty", new NettyAllocatorMetricSet("pooled-allocator", PooledByteBufAllocator.DEFAULT.metric()));
    scoped.register("netty", new NettyAllocatorMetricSet("unpooled-allocator", UnpooledByteBufAllocator.DEFAULT.metric()));
}
 
Example #27
Source File: MonitoringModule.java    From curiostack with MIT License 5 votes vote down vote up
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());
}
 
Example #28
Source File: DrillMetrics.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static void registerSystemMetrics() {
  REGISTRY.registerAll(new GarbageCollectorMetricSet());
  REGISTRY.registerAll(new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
  REGISTRY.registerAll(new MemoryUsageGaugeSet());
  REGISTRY.registerAll(new ThreadStatesGaugeSet());
  REGISTRY.registerAll(new CpuGaugeSet());
  register("fd.usage", new FileDescriptorRatioGauge());
}
 
Example #29
Source File: LocalDataTransferServer.java    From rubix with Apache License 2.0 5 votes vote down vote up
/**
 * Register desired metrics.
 *
 * @param conf The current Hadoop configuration.
 */
private static void registerMetrics(Configuration conf)
{
  bookKeeperMetrics = new BookKeeperMetrics(conf, metrics);

  metrics.register(BookKeeperMetrics.LDTSJvmMetric.LDTS_JVM_GC_PREFIX.getMetricName(), new GarbageCollectorMetricSet());
  metrics.register(BookKeeperMetrics.LDTSJvmMetric.LDTS_JVM_THREADS_PREFIX.getMetricName(), new CachedThreadStatesGaugeSet(CacheConfig.getMetricsReportingInterval(conf), TimeUnit.MILLISECONDS));
  metrics.register(BookKeeperMetrics.LDTSJvmMetric.LDTS_JVM_MEMORY_PREFIX.getMetricName(), new MemoryUsageGaugeSet());
}
 
Example #30
Source File: MetricSystem.java    From Microservices-Deployment-Cookbook with MIT License 5 votes vote down vote up
@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;
			}
		});
	}