Search in sources :

Example 1 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class AddStatListenerResponse method create.

/**
   * Returns a <code>AddStatListenerResponse</code> that will be returned to the specified
   * recipient. The message will contains a copy of the local manager's system config.
   */
public static AddStatListenerResponse create(DistributionManager dm, InternalDistributedMember recipient, long resourceId, String statName) {
    AddStatListenerResponse m = new AddStatListenerResponse();
    m.setRecipient(recipient);
    GemFireStatSampler sampler = null;
    sampler = dm.getSystem().getStatSampler();
    if (sampler != null) {
        m.listenerId = sampler.addListener(recipient, resourceId, statName);
    }
    return m;
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler)

Example 2 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class AdminConsoleDisconnectMessage method process.

@Override
public void process(DistributionManager dm) {
    InternalDistributedSystem sys = dm.getSystem();
    // DistributionConfig config = sys.getConfig();
    if (alertListenerExpected) {
        if (!AlertAppender.getInstance().removeAlertListener(this.getSender()) && !this.ignoreAlertListenerRemovalFailure) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.ManagerLogWriter_UNABLE_TO_REMOVE_CONSOLE_WITH_ID_0_FROM_ALERT_LISTENERS, this.getSender()));
        }
    }
    GemFireStatSampler sampler = sys.getStatSampler();
    if (sampler != null) {
        sampler.removeListenersByRecipient(this.getSender());
    }
    dm.handleConsoleShutdown(this.getSender(), crashed, LocalizedStrings.AdminConsoleDisconnectMessage_AUTOMATIC_ADMIN_DISCONNECT_0.toLocalizedString(reason));
// AppCacheSnapshotMessage.flushSnapshots(this.getSender());
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 3 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class MemberMBeanBridge method addSystemStats.

public void addSystemStats() {
    GemFireStatSampler sampler = system.getStatSampler();
    ProcessStats processStats = sampler.getProcessStats();
    StatSamplerStats samplerStats = sampler.getStatSamplerStats();
    if (processStats != null) {
        systemStatsMonitor.addStatisticsToMonitor(processStats.getStatistics());
    }
    if (samplerStats != null) {
        systemStatsMonitor.addStatisticsToMonitor(samplerStats.getStats());
    }
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) StatSamplerStats(org.apache.geode.internal.statistics.StatSamplerStats) ProcessStats(org.apache.geode.internal.statistics.platform.ProcessStats)

Example 4 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class HeapMemoryMonitor method startCacheStatListener.

/**
   * Start a listener on the cache stats to monitor memory usage.
   * 
   * @return True of the listener was correctly started, false otherwise.
   */
private boolean startCacheStatListener() {
    final GemFireStatSampler sampler = this.cache.getInternalDistributedSystem().getStatSampler();
    if (sampler == null) {
        return false;
    }
    try {
        sampler.waitForInitialization();
        String tenuredPoolName = getTenuredMemoryPoolMXBean().getName();
        List list = this.cache.getInternalDistributedSystem().getStatsList();
        for (Object o : list) {
            if (o instanceof StatisticsImpl) {
                StatisticsImpl si = (StatisticsImpl) o;
                if (si.getTextId().contains(tenuredPoolName) && si.getType().getName().contains("PoolStats")) {
                    sampler.addLocalStatListener(this.statListener, si, "currentUsedMemory");
                    if (this.cache.getLoggerI18n().fineEnabled()) {
                        this.cache.getLoggerI18n().fine("Registered stat listener for " + si.getTextId());
                    }
                    return true;
                }
            }
        }
    } catch (InterruptedException iex) {
        Thread.currentThread().interrupt();
        this.cache.getCancelCriterion().checkCancelInProgress(iex);
    }
    return false;
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) StatisticsImpl(org.apache.geode.internal.statistics.StatisticsImpl) List(java.util.List)

Example 5 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class InternalDistributedSystem method initialize.

/**
   * Initializes this connection to a distributed system with the current configuration state.
   */
private void initialize() {
    if (this.originalConfig.getLocators().equals("")) {
        if (this.originalConfig.getMcastPort() != 0) {
            throw new GemFireConfigException("The " + LOCATORS + " attribute can not be empty when the " + MCAST_PORT + " attribute is non-zero.");
        } else {
            // no distribution
            this.isLoner = true;
        }
    }
    this.config = new RuntimeDistributionConfigImpl(this);
    if (!this.isLoner) {
        this.attemptingToReconnect = (reconnectAttemptCounter > 0);
    }
    try {
        SocketCreatorFactory.setDistributionConfig(config);
        AlertAppender.getInstance().onConnect(this);
        // LOG: create LogWriterAppender(s) if log-file or security-log-file is specified
        final boolean hasLogFile = this.config.getLogFile() != null && !this.config.getLogFile().equals(new File(""));
        final boolean hasSecurityLogFile = this.config.getSecurityLogFile() != null && !this.config.getSecurityLogFile().equals(new File(""));
        LogService.configureLoggers(hasLogFile, hasSecurityLogFile);
        if (hasLogFile || hasSecurityLogFile) {
            // main log file
            if (hasLogFile) {
                // if log-file then create logWriterAppender
                this.logWriterAppender = LogWriterAppenders.getOrCreateAppender(LogWriterAppenders.Identifier.MAIN, this.isLoner, this.config, true);
            }
            // security log file
            if (hasSecurityLogFile) {
                // if security-log-file then create securityLogWriterAppender
                this.securityLogWriterAppender = LogWriterAppenders.getOrCreateAppender(LogWriterAppenders.Identifier.SECURITY, this.isLoner, this.config, false);
            } else {
            // let security route to regular log-file or stdout
            }
        }
        // getSecurityLogWriter
        if (this.logWriter == null) {
            this.logWriter = LogWriterFactory.createLogWriterLogger(this.isLoner, false, this.config, true);
            this.logWriter.fine("LogWriter is created.");
        }
        if (this.securityLogWriter == null) {
            // LOG: whole new LogWriterLogger instance for security
            this.securityLogWriter = LogWriterFactory.createLogWriterLogger(this.isLoner, true, this.config, false);
            this.securityLogWriter.fine("SecurityLogWriter is created.");
        }
        Services.setLogWriter(this.logWriter);
        Services.setSecurityLogWriter(this.securityLogWriter);
        this.clock = new DSClock(this.isLoner);
        if (this.attemptingToReconnect && logger.isDebugEnabled()) {
            logger.debug("This thread is initializing a new DistributedSystem in order to reconnect to other members");
        }
        // bridge server and will need to enforce the member limit
        if (Boolean.getBoolean(InternalLocator.FORCE_LOCATOR_DM_TYPE)) {
            this.locatorDMTypeForced = true;
        }
        // Initialize the Diffie-Hellman and public/private keys
        try {
            HandShake.initCertsMap(this.config.getSecurityProps());
            HandShake.initPrivateKey(this.config.getSecurityProps());
            HandShake.initDHKeys(this.config);
        } catch (Exception ex) {
            throw new GemFireSecurityException(LocalizedStrings.InternalDistributedSystem_PROBLEM_IN_INITIALIZING_KEYS_FOR_CLIENT_AUTHENTICATION.toLocalizedString(), ex);
        }
        final long offHeapMemorySize = OffHeapStorage.parseOffHeapMemorySize(getConfig().getOffHeapMemorySize());
        this.offHeapStore = OffHeapStorage.createOffHeapStorage(this, offHeapMemorySize, this);
        // Note: this can only happen on a linux system
        if (getConfig().getLockMemory()) {
            // This calculation is not exact, but seems fairly close. So far we have
            // not loaded much into the heap and the current RSS usage is already
            // included the available memory calculation.
            long avail = LinuxProcFsStatistics.getAvailableMemory(logger);
            long size = offHeapMemorySize + Runtime.getRuntime().totalMemory();
            if (avail < size) {
                if (ALLOW_MEMORY_LOCK_WHEN_OVERCOMMITTED) {
                    logger.warn(LocalizedMessage.create(LocalizedStrings.InternalDistributedSystem_MEMORY_OVERCOMMIT_WARN, size - avail));
                } else {
                    throw new IllegalStateException(LocalizedStrings.InternalDistributedSystem_MEMORY_OVERCOMMIT.toLocalizedString(avail, size));
                }
            }
            logger.info("Locking memory. This may take a while...");
            GemFireCacheImpl.lockMemory();
            logger.info("Finished locking memory.");
        }
        try {
            startInitLocator();
        } catch (InterruptedException e) {
            throw new SystemConnectException("Startup has been interrupted", e);
        }
        synchronized (this.isConnectedMutex) {
            this.isConnected = true;
        }
        if (!this.isLoner) {
            try {
                if (this.quorumChecker != null) {
                    this.quorumChecker.suspend();
                }
                this.dm = DistributionManager.create(this);
                // fix bug #46324
                if (InternalLocator.hasLocator()) {
                    InternalLocator locator = InternalLocator.getLocator();
                    getDistributionManager().addHostedLocators(getDistributedMember(), InternalLocator.getLocatorStrings(), locator.isSharedConfigurationEnabled());
                }
            } finally {
                if (this.dm == null && this.quorumChecker != null) {
                    this.quorumChecker.resume();
                }
                setDisconnected();
            }
        } else {
            this.dm = new LonerDistributionManager(this, this.logWriter);
        }
        Assert.assertTrue(this.dm != null);
        Assert.assertTrue(this.dm.getSystem() == this);
        try {
            this.id = this.dm.getChannelId();
        } catch (DistributedSystemDisconnectedException e) {
            // but during startup we should instead throw a SystemConnectException
            throw new SystemConnectException(LocalizedStrings.InternalDistributedSystem_DISTRIBUTED_SYSTEM_HAS_DISCONNECTED.toLocalizedString(), e);
        }
        synchronized (this.isConnectedMutex) {
            this.isConnected = true;
        }
        if (attemptingToReconnect && (this.startedLocator == null)) {
            try {
                startInitLocator();
            } catch (InterruptedException e) {
                throw new SystemConnectException("Startup has been interrupted", e);
            }
        }
        try {
            endInitLocator();
        } catch (IOException e) {
            throw new GemFireIOException("Problem finishing a locator service start", e);
        }
        if (!statsDisabled) {
            // to fix bug 42527 we need a sampler
            // even if sampling is not enabled.
            this.sampler = new GemFireStatSampler(this);
            this.sampler.start();
        }
        if (this.logWriterAppender != null) {
            LogWriterAppenders.startupComplete(LogWriterAppenders.Identifier.MAIN);
        }
        if (this.securityLogWriterAppender != null) {
            LogWriterAppenders.startupComplete(LogWriterAppenders.Identifier.SECURITY);
        }
        // this.logger.info("ds created", new RuntimeException("DEBUG: STACK"));
        // Log any instantiators that were registered before the log writer
        // was created
        InternalInstantiator.logInstantiators();
    } catch (RuntimeException ex) {
        this.config.close();
        throw ex;
    }
    resourceListeners = new CopyOnWriteArrayList<ResourceEventsListener>();
    this.reconnected = this.attemptingToReconnect;
    this.attemptingToReconnect = false;
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheXmlException(org.apache.geode.cache.CacheXmlException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) ManagementException(org.apache.geode.management.ManagementException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireConfigException(org.apache.geode.GemFireConfigException) GemFireIOException(org.apache.geode.GemFireIOException) File(java.io.File) SystemConnectException(org.apache.geode.SystemConnectException)

Aggregations

GemFireStatSampler (org.apache.geode.internal.statistics.GemFireStatSampler)9 List (java.util.List)3 ArrayList (java.util.ArrayList)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 StatisticsImpl (org.apache.geode.internal.statistics.StatisticsImpl)2 ProcessStats (org.apache.geode.internal.statistics.platform.ProcessStats)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 NotificationEmitter (javax.management.NotificationEmitter)1 CancelException (org.apache.geode.CancelException)1 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)1 GemFireConfigException (org.apache.geode.GemFireConfigException)1 GemFireIOException (org.apache.geode.GemFireIOException)1 SystemConnectException (org.apache.geode.SystemConnectException)1 GemFireHealthConfig (org.apache.geode.admin.GemFireHealthConfig)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 Cache (org.apache.geode.cache.Cache)1