Search in sources :

Example 1 with FileDescriptorRatioGauge

use of com.codahale.metrics.jvm.FileDescriptorRatioGauge in project curiostack by curioswitch.

the class MonitoringModule method configureJvmMetrics.

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());
}
Also used : BufferPoolMetricSet(com.codahale.metrics.jvm.BufferPoolMetricSet) FileDescriptorRatioGauge(com.codahale.metrics.jvm.FileDescriptorRatioGauge) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) ClassLoadingGaugeSet(com.codahale.metrics.jvm.ClassLoadingGaugeSet) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) MBeanServer(javax.management.MBeanServer) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

Example 2 with FileDescriptorRatioGauge

use of com.codahale.metrics.jvm.FileDescriptorRatioGauge in project mica2 by obiba.

the class MetricsConfiguration method init.

@PostConstruct
public void init() {
    log.debug("Registering JVM gauges");
    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()));
    if (propertyResolver.getProperty(PROP_JMX_ENABLED, Boolean.class, false)) {
        log.info("Initializing Metrics JMX reporting");
        JmxReporter jmxReporter = JmxReporter.forRegistry(METRIC_REGISTRY).build();
        jmxReporter.start();
    }
}
Also used : BufferPoolMetricSet(com.codahale.metrics.jvm.BufferPoolMetricSet) FileDescriptorRatioGauge(com.codahale.metrics.jvm.FileDescriptorRatioGauge) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) JmxReporter(com.codahale.metrics.JmxReporter) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet) PostConstruct(javax.annotation.PostConstruct)

Example 3 with FileDescriptorRatioGauge

use of com.codahale.metrics.jvm.FileDescriptorRatioGauge in project stdlib by petergeneric.

the class CoreMetricsModule method buildRegistry.

public static MetricRegistry buildRegistry() {
    MetricRegistry registry = new MetricRegistry();
    registry.register(MetricRegistry.name("jvm", "gc"), new GarbageCollectorMetricSet());
    registry.register(MetricRegistry.name("jvm", "memory"), new MemoryUsageGaugeSet());
    registry.register(MetricRegistry.name("jvm", "thread-states"), new ThreadStatesGaugeSet());
    registry.register(MetricRegistry.name("jvm", "fd", "usage"), new FileDescriptorRatioGauge());
    return registry;
}
Also used : FileDescriptorRatioGauge(com.codahale.metrics.jvm.FileDescriptorRatioGauge) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) MetricRegistry(com.codahale.metrics.MetricRegistry) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

Example 4 with FileDescriptorRatioGauge

use of com.codahale.metrics.jvm.FileDescriptorRatioGauge in project cassandra by apache.

the class CassandraDaemon method setup.

/**
 * This is a hook for concrete daemons to initialize themselves suitably.
 *
 * Subclasses should override this to finish the job (listening on ports, etc.)
 */
protected void setup() {
    FileUtils.setFSErrorHandler(new DefaultFSErrorHandler());
    // snapshots and upgrading system tables.
    try {
        migrateSystemDataIfNeeded();
    } catch (IOException e) {
        exitOrFail(StartupException.ERR_WRONG_DISK_STATE, e.getMessage(), e);
    }
    maybeInitJmx();
    Mx4jTool.maybeLoad();
    ThreadAwareSecurityManager.install();
    logSystemInfo();
    NativeLibrary.tryMlockall();
    CommitLog.instance.start();
    runStartupChecks();
    try {
        SystemKeyspace.snapshotOnVersionChange();
    } catch (IOException e) {
        exitOrFail(StartupException.ERR_WRONG_DISK_STATE, e.getMessage(), e.getCause());
    }
    // We need to persist this as soon as possible after startup checks.
    // This should be the first write to SystemKeyspace (CASSANDRA-11742)
    SystemKeyspace.persistLocalMetadata();
    Thread.setDefaultUncaughtExceptionHandler(JVMStabilityInspector::uncaughtException);
    SystemKeyspaceMigrator40.migrate();
    // Populate token metadata before flushing, for token-aware sstable partitioning (#6696)
    StorageService.instance.populateTokenMetadata();
    try {
        // load schema from disk
        Schema.instance.loadFromDisk();
    } catch (Exception e) {
        logger.error("Error while loading schema: ", e);
        throw e;
    }
    setupVirtualKeyspaces();
    SSTableHeaderFix.fixNonFrozenUDTIfUpgradeFrom30();
    // clean up debris in the rest of the keyspaces
    for (String keyspaceName : Schema.instance.getKeyspaces()) {
        // Skip system as we've already cleaned it
        if (keyspaceName.equals(SchemaConstants.SYSTEM_KEYSPACE_NAME))
            continue;
        for (TableMetadata cfm : Schema.instance.getTablesAndViews(keyspaceName)) {
            try {
                ColumnFamilyStore.scrubDataDirectories(cfm);
            } catch (StartupException e) {
                exitOrFail(e.returnCode, e.getMessage(), e.getCause());
            }
        }
    }
    Keyspace.setInitialized();
    // initialize keyspaces
    for (String keyspaceName : Schema.instance.getKeyspaces()) {
        if (logger.isDebugEnabled())
            logger.debug("opening keyspace {}", keyspaceName);
        // disable auto compaction until gossip settles since disk boundaries may be affected by ring layout
        for (ColumnFamilyStore cfs : Keyspace.open(keyspaceName).getColumnFamilyStores()) {
            for (ColumnFamilyStore store : cfs.concatWithIndexes()) {
                store.disableAutoCompaction();
            }
        }
    }
    try {
        loadRowAndKeyCacheAsync().get();
    } catch (Throwable t) {
        JVMStabilityInspector.inspectThrowable(t);
        logger.warn("Error loading key or row cache", t);
    }
    try {
        GCInspector.register();
    } catch (Throwable t) {
        JVMStabilityInspector.inspectThrowable(t);
        logger.warn("Unable to start GCInspector (currently only supported on the Sun JVM)");
    }
    // Replay any CommitLogSegments found on disk
    try {
        CommitLog.instance.recoverSegmentsOnDisk();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    // Re-populate token metadata after commit log recover (new peers might be loaded onto system keyspace #10293)
    StorageService.instance.populateTokenMetadata();
    SystemKeyspace.finishStartup();
    // Clean up system.size_estimates entries left lying around from missed keyspace drops (CASSANDRA-14905)
    StorageService.instance.cleanupSizeEstimates();
    // schedule periodic dumps of table size estimates into SystemKeyspace.SIZE_ESTIMATES_CF
    // set cassandra.size_recorder_interval to 0 to disable
    int sizeRecorderInterval = Integer.getInteger("cassandra.size_recorder_interval", 5 * 60);
    if (sizeRecorderInterval > 0)
        ScheduledExecutors.optionalTasks.scheduleWithFixedDelay(SizeEstimatesRecorder.instance, 30, sizeRecorderInterval, TimeUnit.SECONDS);
    ActiveRepairService.instance.start();
    // Prepared statements
    QueryProcessor.instance.preloadPreparedStatements();
    // Metrics
    String metricsReporterConfigFile = System.getProperty("cassandra.metricsReporterConfigFile");
    if (metricsReporterConfigFile != null) {
        logger.info("Trying to load metrics-reporter-config from file: {}", metricsReporterConfigFile);
        try {
            // enable metrics provided by metrics-jvm.jar
            CassandraMetricsRegistry.Metrics.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
            CassandraMetricsRegistry.Metrics.register("jvm.gc", new GarbageCollectorMetricSet());
            CassandraMetricsRegistry.Metrics.register("jvm.memory", new MemoryUsageGaugeSet());
            CassandraMetricsRegistry.Metrics.register("jvm.fd.usage", new FileDescriptorRatioGauge());
            // initialize metrics-reporter-config from yaml file
            URL resource = CassandraDaemon.class.getClassLoader().getResource(metricsReporterConfigFile);
            if (resource == null) {
                logger.warn("Failed to load metrics-reporter-config, file does not exist: {}", metricsReporterConfigFile);
            } else {
                String reportFileLocation = resource.getFile();
                ReporterConfig.loadFromFile(reportFileLocation).enableAll(CassandraMetricsRegistry.Metrics);
            }
        } catch (Exception e) {
            logger.warn("Failed to load metrics-reporter-config, metric sinks will not be activated", e);
        }
    }
    // start server internals
    StorageService.instance.registerDaemon(this);
    try {
        StorageService.instance.initServer();
    } catch (ConfigurationException e) {
        System.err.println(e.getMessage() + "\nFatal configuration error; unable to start server.  See log for stacktrace.");
        exitOrFail(1, "Fatal configuration error", e);
    }
    // Because we are writing to the system_distributed keyspace, this should happen after that is created, which
    // happens in StorageService.instance.initServer()
    Runnable viewRebuild = () -> {
        for (Keyspace keyspace : Keyspace.all()) {
            keyspace.viewManager.buildAllViews();
        }
        logger.debug("Completed submission of build tasks for any materialized views defined at startup");
    };
    ScheduledExecutors.optionalTasks.schedule(viewRebuild, StorageService.RING_DELAY, TimeUnit.MILLISECONDS);
    if (!FBUtilities.getBroadcastAddressAndPort().equals(InetAddressAndPort.getLoopbackAddress()))
        Gossiper.waitToSettle();
    StorageService.instance.doAuthSetup(false);
    // re-enable auto-compaction after gossip is settled, so correct disk boundaries are used
    for (Keyspace keyspace : Keyspace.all()) {
        for (ColumnFamilyStore cfs : keyspace.getColumnFamilyStores()) {
            for (final ColumnFamilyStore store : cfs.concatWithIndexes()) {
                // reload CFs in case there was a change of disk boundaries
                store.reload();
                if (store.getCompactionStrategyManager().shouldBeEnabled()) {
                    if (DatabaseDescriptor.getAutocompactionOnStartupEnabled()) {
                        store.enableAutoCompaction();
                    } else {
                        logger.info("Not enabling compaction for {}.{}; autocompaction_on_startup_enabled is set to false", store.keyspace.getName(), store.name);
                    }
                }
            }
        }
    }
    AuditLogManager.instance.initialize();
    // schedule periodic background compaction task submission. this is simply a backstop against compactions stalling
    // due to scheduling errors or race conditions
    ScheduledExecutors.optionalTasks.scheduleWithFixedDelay(ColumnFamilyStore.getBackgroundCompactionTaskSubmitter(), 5, 1, TimeUnit.MINUTES);
    // schedule periodic recomputation of speculative retry thresholds
    ScheduledExecutors.optionalTasks.scheduleWithFixedDelay(SPECULATION_THRESHOLD_UPDATER, DatabaseDescriptor.getReadRpcTimeout(NANOSECONDS), DatabaseDescriptor.getReadRpcTimeout(NANOSECONDS), NANOSECONDS);
    initializeClientTransports();
    // init below this mark before completeSetup().
    if (DatabaseDescriptor.getAuthCacheWarmingEnabled())
        AuthCacheService.instance.warmCaches();
    else
        logger.info("Prewarming of auth caches is disabled");
    completeSetup();
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) BufferPoolMetricSet(com.codahale.metrics.jvm.BufferPoolMetricSet) FileDescriptorRatioGauge(com.codahale.metrics.jvm.FileDescriptorRatioGauge) IOException(java.io.IOException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StartupException(org.apache.cassandra.exceptions.StartupException) URL(java.net.URL) JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) StartupException(org.apache.cassandra.exceptions.StartupException) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) SystemViewsKeyspace(org.apache.cassandra.db.virtual.SystemViewsKeyspace) Keyspace(org.apache.cassandra.db.Keyspace) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) VirtualSchemaKeyspace(org.apache.cassandra.db.virtual.VirtualSchemaKeyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

Example 5 with FileDescriptorRatioGauge

use of com.codahale.metrics.jvm.FileDescriptorRatioGauge in project dropwizard by dropwizard.

the class Bootstrap method registerMetrics.

/**
 * Registers the JVM metrics to the metric registry and start to report
 * the registry metrics via JMX.
 */
public void registerMetrics() {
    if (metricsAreRegistered) {
        return;
    }
    getMetricRegistry().register("jvm.attribute", new JvmAttributeGaugeSet());
    getMetricRegistry().register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
    getMetricRegistry().register("jvm.classloader", new ClassLoadingGaugeSet());
    getMetricRegistry().register("jvm.filedescriptor", new FileDescriptorRatioGauge());
    getMetricRegistry().register("jvm.gc", new GarbageCollectorMetricSet());
    getMetricRegistry().register("jvm.memory", new MemoryUsageGaugeSet());
    getMetricRegistry().register("jvm.threads", new ThreadStatesGaugeSet());
    jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
    jmxReporter.start();
    metricsAreRegistered = true;
}
Also used : BufferPoolMetricSet(com.codahale.metrics.jvm.BufferPoolMetricSet) JvmAttributeGaugeSet(com.codahale.metrics.jvm.JvmAttributeGaugeSet) FileDescriptorRatioGauge(com.codahale.metrics.jvm.FileDescriptorRatioGauge) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) ClassLoadingGaugeSet(com.codahale.metrics.jvm.ClassLoadingGaugeSet) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

Aggregations

FileDescriptorRatioGauge (com.codahale.metrics.jvm.FileDescriptorRatioGauge)11 GarbageCollectorMetricSet (com.codahale.metrics.jvm.GarbageCollectorMetricSet)11 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)11 ThreadStatesGaugeSet (com.codahale.metrics.jvm.ThreadStatesGaugeSet)9 BufferPoolMetricSet (com.codahale.metrics.jvm.BufferPoolMetricSet)6 MetricRegistry (com.codahale.metrics.MetricRegistry)4 ClassLoadingGaugeSet (com.codahale.metrics.jvm.ClassLoadingGaugeSet)3 Bean (org.springframework.context.annotation.Bean)3 PostConstruct (javax.annotation.PostConstruct)2 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JmxReporter (com.codahale.metrics.JmxReporter)1 MetricSet (com.codahale.metrics.MetricSet)1 CachedThreadStatesGaugeSet (com.codahale.metrics.jvm.CachedThreadStatesGaugeSet)1 JvmAttributeGaugeSet (com.codahale.metrics.jvm.JvmAttributeGaugeSet)1 ThreadDeadlockDetector (com.codahale.metrics.jvm.ThreadDeadlockDetector)1 InstrumentedAppender (com.codahale.metrics.logback.InstrumentedAppender)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1