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;
}
};
}
Aggregations