com.codahale.metrics.jvm.ThreadStatesGaugeSet Java Examples

The following examples show how to use com.codahale.metrics.jvm.ThreadStatesGaugeSet. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: MetricsConfiguration.java    From flair-engine with Apache License 2.0 5 votes vote down vote up
@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 (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");
        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);
    }
}
 
Example #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #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: 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 #16
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 #17
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 #18
Source File: MeterConfiguration.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void configureReporters(MetricRegistry metricRegistry) {
    metricRegistry.addListener(metricsListener);

    metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet());
    metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet());
    metricRegistry.register("jvm.thread-states", new ThreadStatesGaugeSet());
    metricRegistry.register("jvm.fd.usage", new FileDescriptorRatioGauge());


    if(environment.acceptsProfiles(AmqpUtils.PROFILE)) {
        final String applicationId = AppInfo.getApplicationName();
        AmqpUtils.ExchangeFactory exchangeFactory = new AmqpUtils.ExchangeFactory();
        exchangeFactory.setExchangeName(exchange);
        AmqpReporter amqpReporter = AmqpReporter.forRegistry(metricRegistry)
          .connectionFactoryProvider(connectionFactoryProvider)
          .exchangeName(exchange)
          .routingKey(applicationId)
          .exchangeFactory(exchangeFactory)
          .build();
        amqpReporter.start(reportPeriod, TimeUnit.SECONDS);
        LOG.info("AmqpReporter enabled: applicationId: {} reportPeriod: {} seconds, exchange: {}",
                applicationId, reportPeriod, exchange);
    } else {
        //sample configuration for metrics reported
        // https://dropwizard.github.io/metrics/3.1.0/manual/core/#man-core-reporters-console
        final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry)
                .outputTo(LoggerFactory.getLogger("com.codeabovelab.dm.metrics"))
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .build();
        reporter.start(reportPeriod, TimeUnit.SECONDS);
    }
}
 
Example #19
Source File: CodahaleMetricsEngine.java    From riposte with Apache License 2.0 5 votes vote down vote up
/**
 * Adds JVM MetricSets to this engine.  By default JVM metrics are not placed in the Registry
 */
public CodahaleMetricsEngine reportJvmMetrics() {
    // add JVM metrics
    if (!jvmMetricsAdded) {
        metricsCollector.registerAll("JVM-gc", new GarbageCollectorMetricSet());
        metricsCollector
            .registerAll("JVM-buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
        metricsCollector.registerAll("JVM-memory", new MemoryUsageGaugeSet());
        metricsCollector.registerAll("JVM-threads", new ThreadStatesGaugeSet());
        jvmMetricsAdded = true;
    }
    return this;
}
 
Example #20
Source File: GraphiteMetrics.java    From replicator with Apache License 2.0 5 votes vote down vote up
@Override
protected ScheduledReporter getReporter(Map<String, Object> configuration, MetricRegistry registry) {
    Object namespace = configuration.get(Configuration.GRAPHITE_NAMESPACE);
    Object hostname = configuration.get(Configuration.GRAPHITE_HOSTNAME);
    Object port = configuration.get(Configuration.GRAPHITE_PORT);

    Objects.requireNonNull(namespace, String.format("Configuration required: %s", Configuration.GRAPHITE_NAMESPACE));
    Objects.requireNonNull(hostname, String.format("Configuration required: %s", Configuration.GRAPHITE_HOSTNAME));
    Objects.requireNonNull(port, String.format("Configuration required: %s", Configuration.GRAPHITE_PORT));

    registry.register(MetricRegistry.name("jvm", "gc"), new GarbageCollectorMetricSet());
    registry.register(MetricRegistry.name("jvm", "threads"), new ThreadStatesGaugeSet());
    registry.register(MetricRegistry.name("jvm", "classes"), new ClassLoadingGaugeSet());
    registry.register(MetricRegistry.name("jvm", "fd"), new FileDescriptorRatioGauge());
    registry.register(MetricRegistry.name("jvm", "memory"), new MemoryUsageGaugeSet());

    ScheduledReporter reporter = GraphiteReporter
            .forRegistry(registry)
            .prefixedWith(namespace.toString())
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.SECONDS)
            .build(new Graphite(new InetSocketAddress(hostname.toString(), Integer.parseInt(port.toString()))));

    reporter.start(1L, TimeUnit.MINUTES);

    return reporter;
}
 
Example #21
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 #22
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 #23
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 #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: 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 #26
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 #27
Source File: MetricsFactory.java    From baleen with Apache License 2.0 4 votes vote down vote up
/** Configure the instance. */
@Override
public void configure(Configuration configuration) throws BaleenException {
  LOGGER.debug("Configuring metrics");

  stop();
  reporters.clear();

  List<Map<String, Object>> reportersConfigs = configuration.getAsListOfMaps("metrics.reporters");
  for (Map<String, Object> config : reportersConfigs) {
    String type = (String) config.getOrDefault("type", "none");

    ScheduledReporter reporter;
    switch (type.toLowerCase()) {
      case "log":
        reporter = ReporterUtils.createSlf4jReporter(metricRegistry, config);
        break;
      case "csv":
        reporter = ReporterUtils.createCsvReporter(metricRegistry, config);
        break;
      case "console":
        reporter = ReporterUtils.createConsoleReporter(metricRegistry, config);
        break;
      case "none":
        continue;
      default:
        throw new InvalidParameterException("Unknown reporter of type " + type);
    }

    Integer period = (Integer) config.getOrDefault("period", 60);
    reporters.add(new ConfiguredReporter(reporter, period * 1000));
  }

  // Install the logging listener (probably a configuration item)
  metricRegistry.addListener(new LoggingMetricListener());

  // Install JVM metrics
  LOGGER.debug("Installing JVM metrics");
  metricRegistry.registerAll(new GarbageCollectorMetricSet());
  metricRegistry.registerAll(new MemoryUsageGaugeSet());
  metricRegistry.registerAll(new ThreadStatesGaugeSet());

  LOGGER.info("Metrics have been configured");
}
 
Example #28
Source File: SimCloudManager.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
SimCloudManager(TimeSource timeSource, SimDistribStateManager distribStateManager) throws Exception {
  this.loader = new SolrResourceLoader();
  if (distribStateManager == null) {
    this.stateManager =  new SimDistribStateManager(SimDistribStateManager.createNewRootNode());
    // init common paths
    stateManager.makePath(ZkStateReader.CLUSTER_PROPS);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_CONF_PATH);
    stateManager.makePath(ZkStateReader.LIVE_NODES_ZKNODE);
    stateManager.makePath(ZkStateReader.ROLES);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_EVENTS_PATH);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_TRIGGER_STATE_PATH);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_NODE_LOST_PATH);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_NODE_ADDED_PATH);
    stateManager.makePath(Overseer.OVERSEER_ELECT);
  } else {
    this.stateManager = distribStateManager;
  }

  // register common metrics
  metricTag = Integer.toHexString(hashCode());
  String registryName = SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm);
  metricManager.registerAll(registryName, new AltBufferPoolMetricSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "buffers");
  metricManager.registerAll(registryName, new ClassLoadingGaugeSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "classes");
  metricManager.registerAll(registryName, new OperatingSystemMetricSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "os");
  metricManager.registerAll(registryName, new GarbageCollectorMetricSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "gc");
  metricManager.registerAll(registryName, new MemoryUsageGaugeSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "memory");
  metricManager.registerAll(registryName, new ThreadStatesGaugeSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "threads"); // todo should we use CachedThreadStatesGaugeSet instead?
  MetricsMap sysprops = new MetricsMap((detailed, map) -> {
    System.getProperties().forEach((k, v) -> {
      map.put(String.valueOf(k), v);
    });
  });
  metricManager.registerGauge(null, registryName, sysprops, metricTag, true, "properties", "system");

  registryName = SolrMetricManager.getRegistryName(SolrInfoBean.Group.node);
  metricManager.registerGauge(null, registryName, () -> new File("/").getUsableSpace(),
      metricTag, true, "usableSpace", SolrInfoBean.Category.CONTAINER.toString(), "fs", "coreRoot");

  solrClient = new MockSearchableSolrClient() {
    @Override
    @SuppressWarnings({"rawtypes"})
    public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException {
      if (collection != null) {
        if (request instanceof AbstractUpdateRequest) {
          ((AbstractUpdateRequest)request).setParam("collection", collection);
        } else if (request instanceof QueryRequest) {
          if (request.getPath() != null && (
              request.getPath().startsWith("/admin/autoscaling") ||
              request.getPath().startsWith("/cluster/autoscaling") ||
          request.getPath().startsWith("/admin/metrics/history") ||
              request.getPath().startsWith("/cluster/metrics/history")
          )) {
            // forward it
            ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
            params.set("collection", collection);
            request = new QueryRequest(params);
          } else {
            // search request
            if (collection.equals(CollectionAdminParams.SYSTEM_COLL)) {
              return super.request(request, collection);
            } else {
              // forward it
              ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
              params.set("collection", collection);
              request = new QueryRequest(params);
            }
          }
        } else {
          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "when collection != null only UpdateRequest and QueryRequest are supported: request=" + request + ", collection=" + collection);
        }
      }
      try {
        SolrResponse rsp = SimCloudManager.this.request(request);
        return rsp.getResponse();
      } catch (UnsupportedOperationException e) {
        throw new SolrServerException(e);
      }
    }
  };


  this.timeSource = timeSource != null ? timeSource : TimeSource.NANO_TIME;
  this.clusterStateProvider = new SimClusterStateProvider(liveNodesSet, this);
  this.nodeStateProvider = new SimNodeStateProvider(liveNodesSet, this.stateManager, this.clusterStateProvider, null);
  this.queueFactory = new GenericDistributedQueueFactory(stateManager);
  this.simCloudManagerPool = ExecutorUtil.newMDCAwareFixedThreadPool(200, new SolrNamedThreadFactory("simCloudManagerPool"));

  this.autoScalingHandler = new AutoScalingHandler(this, loader);


  triggerThreadGroup = new ThreadGroup("Simulated Overseer autoscaling triggers");
  OverseerTriggerThread trigger = new OverseerTriggerThread(loader, this);
  triggerThread = new Overseer.OverseerThread(triggerThreadGroup, trigger, "Simulated OverseerAutoScalingTriggerThread");
  triggerThread.start();
}
 
Example #29
Source File: Metrics.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private static void registerSysStats(){
  REGISTRY.registerAll(scoped("gc", new GarbageCollectorMetricSet()));
  REGISTRY.registerAll(scoped("buffer-pool", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())));
  REGISTRY.registerAll(scoped("memory", new MemoryUsageGaugeSet()));
  REGISTRY.registerAll(scoped("threads", new ThreadStatesGaugeSet()));
}
 
Example #30
Source File: DashboardExtension.java    From wisdom with Apache License 2.0 4 votes vote down vote up
/**
 * Starts the dashboard.
 */
@Validate
public void start() {
    logger().info("Registering JVM metrics");
    registry.register("jvm.memory", new MemoryUsageGaugeSet());
    registry.register("jvm.garbage", new GarbageCollectorMetricSet());
    registry.register("jvm.threads", new ThreadStatesGaugeSet());
    registry.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
    registry.register("jvm.cpu", new CpuGaugeSet());
    registry.register("jvm.runtime", new RuntimeGaugeSet());

    if (configuration.getBooleanWithDefault("monitor.http.enabled", true)) {
        logger().info("Registering HTTP metrics");
        this.httpMetricFilter = new HttpMetricFilter(bc, configuration, registry);
        httpMetricFilter.start();
    }

    if (configuration.getBooleanWithDefault("monitor.jmx.enabled", true)) {
        logger().info("Initializing Metrics JMX reporting");
        final JmxReporter jmxReporter = JmxReporter.forRegistry(registry).build();
        jmxReporter.start();
    }

    if (configuration.getBooleanWithDefault("monitor.graphite.enabled", false)) {
        logger().info("Initializing Metrics Graphite reporting");
        String graphiteHost = configuration.getOrDie("monitor.graphite.host");
        int graphitePort = configuration.getIntegerOrDie("monitor.graphite.port");
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(registry)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
    }

    logger().info("Registering the metric registry as service");
    reg = bc.registerService(MetricRegistry.class, registry, null);

    task = scheduler.scheduleAtFixedRate(new Runnable() {
        /**
         * Sends updated data to the websocket.
         */
        public void run() {
            publisher.publish("/monitor/update", json.toJson(getData()));
        }
    }, 0, 10, TimeUnit.SECONDS);
}