Search in sources :

Example 11 with ClusterMetrics

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);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics)

Example 12 with ClusterMetrics

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;
}
Also used : GridClientNodeBean(org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean) HashMap(java.util.HashMap) GridClientCacheBean(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheBean) ArrayList(java.util.ArrayList) GridClientNodeMetricsBean(org.apache.ignite.internal.processors.rest.client.message.GridClientNodeMetricsBean) ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) InetAddress(java.net.InetAddress) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 13 with ClusterMetrics

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());
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 14 with ClusterMetrics

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;
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics)

Example 15 with ClusterMetrics

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);
    }
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) Ignite(org.apache.ignite.Ignite) GridTestTask(org.apache.ignite.GridTestTask)

Aggregations

ClusterMetrics (org.apache.ignite.cluster.ClusterMetrics)22 Ignite (org.apache.ignite.Ignite)8 Test (org.junit.Test)8 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 GridCommonTest (org.apache.ignite.testframework.junits.common.GridCommonTest)6 Map (java.util.Map)5 HashMap (java.util.HashMap)4 UUID (java.util.UUID)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 GridTestTask (org.apache.ignite.GridTestTask)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2 IgniteException (org.apache.ignite.IgniteException)2 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 InetAddress (java.net.InetAddress)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 List (java.util.List)1