use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.
the class IgniteUtils method heapSize.
/**
* Gets total heap size in GB rounded to specified precision.
*
* @param nodes Nodes.
* @param precision Precision.
* @return Total heap size in GB.
*/
public static double heapSize(Iterable<ClusterNode> nodes, int precision) {
// In bytes.
double heap = 0.0;
for (ClusterNode n : nodesPerJvm(nodes)) {
ClusterMetrics m = n.metrics();
heap += Math.max(m.getHeapMemoryInitialized(), m.getHeapMemoryMaximum());
}
return roundedHeapSize(heap, precision);
}
use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.
the class GridTopologyCommandHandler method createNodeBean.
/**
* Creates node bean out of cluster node. Notice that cache attribute is handled separately.
*
* @param node Cluster node.
* @param mtr Whether to include node metrics.
* @param attr Whether to include node attributes.
* @param caches Whether to include node caches.
* @return Grid Node bean.
*/
private GridClientNodeBean createNodeBean(ClusterNode node, boolean mtr, boolean attr, boolean caches) {
assert node != null;
GridClientNodeBean nodeBean = new GridClientNodeBean();
nodeBean.setNodeId(node.id());
nodeBean.setConsistentId(node.consistentId());
nodeBean.setTcpPort(attribute(node, ATTR_REST_TCP_PORT, 0));
nodeBean.setOrder(node.order());
nodeBean.setTcpAddresses(nonEmptyList(node.<Collection<String>>attribute(ATTR_REST_TCP_ADDRS)));
nodeBean.setTcpHostNames(nonEmptyList(node.<Collection<String>>attribute(ATTR_REST_TCP_HOST_NAMES)));
if (caches) {
Map<String, CacheConfiguration> nodeCaches = ctx.discovery().nodePublicCaches(node);
Collection<GridClientCacheBean> cacheBeans = new ArrayList<>(nodeCaches.size());
for (CacheConfiguration ccfg : nodeCaches.values()) cacheBeans.add(createCacheBean(ccfg));
nodeBean.setCaches(cacheBeans);
}
if (mtr) {
ClusterMetrics metrics = node.metrics();
GridClientNodeMetricsBean metricsBean = new GridClientNodeMetricsBean();
metricsBean.setStartTime(metrics.getStartTime());
metricsBean.setAverageActiveJobs(metrics.getAverageActiveJobs());
metricsBean.setAverageCancelledJobs(metrics.getAverageCancelledJobs());
metricsBean.setAverageCpuLoad(metrics.getAverageCpuLoad());
metricsBean.setAverageJobExecuteTime(metrics.getAverageJobExecuteTime());
metricsBean.setAverageJobWaitTime(metrics.getAverageJobWaitTime());
metricsBean.setAverageRejectedJobs(metrics.getAverageRejectedJobs());
metricsBean.setAverageWaitingJobs(metrics.getAverageWaitingJobs());
metricsBean.setCurrentActiveJobs(metrics.getCurrentActiveJobs());
metricsBean.setCurrentCancelledJobs(metrics.getCurrentCancelledJobs());
metricsBean.setCurrentCpuLoad(metrics.getCurrentCpuLoad());
metricsBean.setCurrentGcCpuLoad(metrics.getCurrentGcCpuLoad());
metricsBean.setCurrentDaemonThreadCount(metrics.getCurrentDaemonThreadCount());
metricsBean.setCurrentIdleTime(metrics.getCurrentIdleTime());
metricsBean.setCurrentJobExecuteTime(metrics.getCurrentJobExecuteTime());
metricsBean.setCurrentJobWaitTime(metrics.getCurrentJobWaitTime());
metricsBean.setCurrentRejectedJobs(metrics.getCurrentRejectedJobs());
metricsBean.setCurrentThreadCount(metrics.getCurrentThreadCount());
metricsBean.setCurrentWaitingJobs(metrics.getCurrentWaitingJobs());
metricsBean.setHeapMemoryCommitted(metrics.getHeapMemoryCommitted());
metricsBean.setHeapMemoryInitialized(metrics.getHeapMemoryInitialized());
metricsBean.setHeapMemoryMaximum(metrics.getHeapMemoryMaximum());
metricsBean.setHeapMemoryUsed(metrics.getHeapMemoryUsed());
metricsBean.setLastDataVersion(metrics.getLastDataVersion());
metricsBean.setLastUpdateTime(metrics.getLastUpdateTime());
metricsBean.setMaximumActiveJobs(metrics.getMaximumActiveJobs());
metricsBean.setMaximumCancelledJobs(metrics.getMaximumCancelledJobs());
metricsBean.setMaximumJobExecuteTime(metrics.getMaximumJobExecuteTime());
metricsBean.setMaximumJobWaitTime(metrics.getMaximumJobWaitTime());
metricsBean.setMaximumRejectedJobs(metrics.getMaximumRejectedJobs());
metricsBean.setMaximumThreadCount(metrics.getMaximumThreadCount());
metricsBean.setMaximumWaitingJobs(metrics.getMaximumWaitingJobs());
metricsBean.setNodeStartTime(metrics.getNodeStartTime());
metricsBean.setNonHeapMemoryCommitted(metrics.getNonHeapMemoryCommitted());
metricsBean.setNonHeapMemoryInitialized(metrics.getNonHeapMemoryInitialized());
metricsBean.setNonHeapMemoryMaximum(metrics.getNonHeapMemoryMaximum());
metricsBean.setNonHeapMemoryUsed(metrics.getNonHeapMemoryUsed());
metricsBean.setStartTime(metrics.getStartTime());
metricsBean.setTotalCancelledJobs(metrics.getTotalCancelledJobs());
metricsBean.setTotalCpus(metrics.getTotalCpus());
metricsBean.setTotalExecutedJobs(metrics.getTotalExecutedJobs());
metricsBean.setTotalIdleTime(metrics.getTotalIdleTime());
metricsBean.setTotalRejectedJobs(metrics.getTotalRejectedJobs());
metricsBean.setTotalStartedThreadCount(metrics.getTotalStartedThreadCount());
metricsBean.setTotalExecutedTasks(metrics.getTotalExecutedTasks());
metricsBean.setSentMessagesCount(metrics.getSentMessagesCount());
metricsBean.setSentBytesCount(metrics.getSentBytesCount());
metricsBean.setReceivedMessagesCount(metrics.getReceivedMessagesCount());
metricsBean.setReceivedBytesCount(metrics.getReceivedBytesCount());
metricsBean.setUpTime(metrics.getUpTime());
nodeBean.setMetrics(metricsBean);
}
if (attr) {
Map<String, Object> attrs = new HashMap<>(node.attributes());
attrs.remove(ATTR_CACHE);
attrs.remove(ATTR_TX_CONFIG);
attrs.remove(ATTR_SECURITY_SUBJECT_V2);
attrs.remove(ATTR_SECURITY_CREDENTIALS);
attrs.remove(ATTR_BINARY_CONFIGURATION);
attrs.remove(ATTR_NODE_CONSISTENT_ID);
for (Iterator<Map.Entry<String, Object>> i = attrs.entrySet().iterator(); i.hasNext(); ) {
Map.Entry<String, Object> e = i.next();
if (!e.getKey().startsWith("org.apache.ignite.") && !e.getKey().startsWith("plugins.") && System.getProperty(e.getKey()) == null) {
i.remove();
continue;
}
if (e.getValue() != null) {
if (e.getValue().getClass().isEnum() || e.getValue() instanceof InetAddress)
e.setValue(e.getValue().toString());
else if (e.getValue().getClass().isArray() && !ATTR_IGNITE_FEATURES.equals(e.getKey()))
i.remove();
}
}
nodeBean.setAttributes(attrs);
}
return nodeBean;
}
use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.
the class GridNonHistoryMetricsSelfTest method testSingleTaskMetrics.
/**
* @throws Exception If failed.
*/
@Test
public void testSingleTaskMetrics() throws Exception {
final Ignite ignite = grid();
ignite.compute().execute(new TestTask(), "testArg");
// Let metrics update twice.
awaitMetricsUpdate(2);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
ClusterMetrics metrics = ignite.cluster().localNode().metrics();
return metrics.getTotalExecutedJobs() == 5;
}
}, 5000);
ClusterMetrics metrics = ignite.cluster().localNode().metrics();
info("Node metrics: " + metrics);
assertEquals(5, metrics.getTotalExecutedJobs());
assertEquals(0, metrics.getTotalCancelledJobs());
assertEquals(0, metrics.getTotalRejectedJobs());
}
use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.
the class AdaptiveCpuLoadProbe method getLoad.
/**
* {@inheritDoc}
*/
@Override
public double getLoad(ClusterNode node, int jobsSentSinceLastUpdate) {
ClusterMetrics metrics = node.metrics();
double k = 1.0d;
if (useProcs) {
int procs = metrics.getTotalCpus();
if (procs > 1)
k = procs * procCoefficient;
}
double load = (useAvg ? metrics.getAverageCpuLoad() : metrics.getCurrentCpuLoad()) / k;
return load < 0 ? 0 : load;
}
use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.
the class ClusterMetricsSelfTest method performTaskExecutionTest.
/**
* @throws Exception In case of error.
*/
private void performTaskExecutionTest() throws Exception {
Ignite g = grid(0);
JobFinishLock jobFinishLock = new JobFinishLock();
MetricsUpdateLock metricsUpdLock = new MetricsUpdateLock();
try {
for (Ignite g0 : G.allGrids()) g0.events().localListen(jobFinishLock, EVT_JOB_FINISHED);
g.compute().execute(new GridTestTask(), "testArg");
// Wait until all nodes fire JOB FINISH event.
jobFinishLock.await();
g.events().localListen(metricsUpdLock, EVT_NODE_METRICS_UPDATED);
// Wait until local node will have updated metrics.
metricsUpdLock.await();
ClusterMetrics m = g.cluster().metrics();
checkMetrics(m);
} finally {
for (Ignite g0 : G.allGrids()) g0.events().stopLocalListen(jobFinishLock);
g.events().stopLocalListen(metricsUpdLock);
}
}
Aggregations