Search in sources :

Example 1 with DiscoveryMetricsProvider

use of org.apache.ignite.spi.discovery.DiscoveryMetricsProvider in project ignite by apache.

the class GridDiscoveryManager method createMetricsProvider.

/**
     * @return Metrics provider.
     */
private DiscoveryMetricsProvider createMetricsProvider() {
    return new DiscoveryMetricsProvider() {

        /** */
        private final long startTime = U.currentTimeMillis();

        /** {@inheritDoc} */
        @Override
        public ClusterMetrics metrics() {
            GridJobMetrics jm = ctx.jobMetric().getJobMetrics();
            ClusterMetricsSnapshot nm = new ClusterMetricsSnapshot();
            nm.setLastUpdateTime(U.currentTimeMillis());
            // Job metrics.
            nm.setMaximumActiveJobs(jm.getMaximumActiveJobs());
            nm.setCurrentActiveJobs(jm.getCurrentActiveJobs());
            nm.setAverageActiveJobs(jm.getAverageActiveJobs());
            nm.setMaximumWaitingJobs(jm.getMaximumWaitingJobs());
            nm.setCurrentWaitingJobs(jm.getCurrentWaitingJobs());
            nm.setAverageWaitingJobs(jm.getAverageWaitingJobs());
            nm.setMaximumRejectedJobs(jm.getMaximumRejectedJobs());
            nm.setCurrentRejectedJobs(jm.getCurrentRejectedJobs());
            nm.setAverageRejectedJobs(jm.getAverageRejectedJobs());
            nm.setMaximumCancelledJobs(jm.getMaximumCancelledJobs());
            nm.setCurrentCancelledJobs(jm.getCurrentCancelledJobs());
            nm.setAverageCancelledJobs(jm.getAverageCancelledJobs());
            nm.setTotalRejectedJobs(jm.getTotalRejectedJobs());
            nm.setTotalCancelledJobs(jm.getTotalCancelledJobs());
            nm.setTotalExecutedJobs(jm.getTotalExecutedJobs());
            nm.setMaximumJobWaitTime(jm.getMaximumJobWaitTime());
            nm.setCurrentJobWaitTime(jm.getCurrentJobWaitTime());
            nm.setAverageJobWaitTime(jm.getAverageJobWaitTime());
            nm.setMaximumJobExecuteTime(jm.getMaximumJobExecuteTime());
            nm.setCurrentJobExecuteTime(jm.getCurrentJobExecuteTime());
            nm.setAverageJobExecuteTime(jm.getAverageJobExecuteTime());
            nm.setCurrentIdleTime(jm.getCurrentIdleTime());
            nm.setTotalIdleTime(jm.getTotalIdleTime());
            nm.setAverageCpuLoad(jm.getAverageCpuLoad());
            // Job metrics.
            nm.setTotalExecutedTasks(ctx.task().getTotalExecutedTasks());
            // VM metrics.
            nm.setAvailableProcessors(metrics.getAvailableProcessors());
            nm.setCurrentCpuLoad(metrics.getCurrentCpuLoad());
            nm.setCurrentGcCpuLoad(metrics.getCurrentGcCpuLoad());
            nm.setHeapMemoryInitialized(metrics.getHeapMemoryInitialized());
            nm.setHeapMemoryUsed(metrics.getHeapMemoryUsed());
            nm.setHeapMemoryCommitted(metrics.getHeapMemoryCommitted());
            nm.setHeapMemoryMaximum(metrics.getHeapMemoryMaximum());
            nm.setHeapMemoryTotal(metrics.getHeapMemoryMaximum());
            nm.setNonHeapMemoryInitialized(metrics.getNonHeapMemoryInitialized());
            nonHeapMemoryUsed(nm);
            nm.setNonHeapMemoryCommitted(metrics.getNonHeapMemoryCommitted());
            nm.setNonHeapMemoryMaximum(metrics.getNonHeapMemoryMaximum());
            nm.setNonHeapMemoryTotal(metrics.getNonHeapMemoryMaximum());
            nm.setUpTime(metrics.getUptime());
            nm.setStartTime(metrics.getStartTime());
            nm.setNodeStartTime(startTime);
            nm.setCurrentThreadCount(metrics.getThreadCount());
            nm.setMaximumThreadCount(metrics.getPeakThreadCount());
            nm.setTotalStartedThreadCount(metrics.getTotalStartedThreadCount());
            nm.setCurrentDaemonThreadCount(metrics.getDaemonThreadCount());
            nm.setTotalNodes(1);
            // Data metrics.
            nm.setLastDataVersion(ctx.cache().lastDataVersion());
            GridIoManager io = ctx.io();
            // IO metrics.
            nm.setSentMessagesCount(io.getSentMessagesCount());
            nm.setSentBytesCount(io.getSentBytesCount());
            nm.setReceivedMessagesCount(io.getReceivedMessagesCount());
            nm.setReceivedBytesCount(io.getReceivedBytesCount());
            nm.setOutboundMessagesQueueSize(io.getOutboundMessagesQueueSize());
            return nm;
        }

        /**
             * @param nm Initializing metrics snapshot.
             */
        private void nonHeapMemoryUsed(ClusterMetricsSnapshot nm) {
            long nonHeapUsed = metrics.getNonHeapMemoryUsed();
            Map<Integer, CacheMetrics> nodeCacheMetrics = cacheMetrics();
            if (nodeCacheMetrics != null) {
                for (Map.Entry<Integer, CacheMetrics> entry : nodeCacheMetrics.entrySet()) {
                    CacheMetrics e = entry.getValue();
                    if (e != null)
                        nonHeapUsed += e.getOffHeapAllocatedSize();
                }
            }
            nm.setNonHeapMemoryUsed(nonHeapUsed);
        }

        /** {@inheritDoc} */
        @Override
        public Map<Integer, CacheMetrics> cacheMetrics() {
            Collection<GridCacheAdapter<?, ?>> caches = ctx.cache().internalCaches();
            if (F.isEmpty(caches))
                return Collections.emptyMap();
            Map<Integer, CacheMetrics> metrics = null;
            for (GridCacheAdapter<?, ?> cache : caches) {
                if (cache.configuration().isStatisticsEnabled() && cache.context().started() && cache.context().affinity().affinityTopologyVersion().topologyVersion() > 0) {
                    if (metrics == null)
                        metrics = U.newHashMap(caches.size());
                    metrics.put(cache.context().cacheId(), cache.localMetrics());
                }
            }
            return metrics == null ? Collections.<Integer, CacheMetrics>emptyMap() : metrics;
        }
    };
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) ClusterMetricsSnapshot(org.apache.ignite.internal.ClusterMetricsSnapshot) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) GridJobMetrics(org.apache.ignite.internal.processors.jobmetrics.GridJobMetrics) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) DiscoveryMetricsProvider(org.apache.ignite.spi.discovery.DiscoveryMetricsProvider) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridBoundedConcurrentLinkedHashMap(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IgniteSystemProperties.getInteger (org.apache.ignite.IgniteSystemProperties.getInteger)1 CacheMetrics (org.apache.ignite.cache.CacheMetrics)1 ClusterMetricsSnapshot (org.apache.ignite.internal.ClusterMetricsSnapshot)1 GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)1 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)1 GridJobMetrics (org.apache.ignite.internal.processors.jobmetrics.GridJobMetrics)1 GridBoundedConcurrentLinkedHashMap (org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap)1 DiscoveryMetricsProvider (org.apache.ignite.spi.discovery.DiscoveryMetricsProvider)1