Search in sources :

Example 16 with ClusterMetrics

use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.

the class ClusterNodeMetricsUpdateTest method checkMetrics0.

/**
 * @param expNodes Expected nodes.
 * @param expJobs Expected jobs number per node.
 */
private void checkMetrics0(int expNodes, Map<UUID, Integer> expJobs) {
    List<Ignite> nodes = Ignition.allGrids();
    assertEquals(expNodes, nodes.size());
    assertEquals(expNodes, expJobs.size());
    int totalJobs = 0;
    for (Integer c : expJobs.values()) totalJobs += c;
    for (final Ignite ignite : nodes) {
        ClusterMetrics m = ignite.cluster().metrics();
        assertEquals(expNodes, m.getTotalNodes());
        assertEquals(totalJobs, m.getTotalExecutedJobs());
        for (Map.Entry<UUID, Integer> e : expJobs.entrySet()) {
            UUID nodeId = e.getKey();
            ClusterGroup g = ignite.cluster().forNodeId(nodeId);
            ClusterMetrics nodeM = g.metrics();
            assertEquals(e.getValue(), (Integer) nodeM.getTotalExecutedJobs());
        }
    }
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with ClusterMetrics

use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.

the class ClusterNodeMetricsSelfTest method testInternalTaskMetrics.

/**
 * @throws Exception If failed.
 */
@Test
public void testInternalTaskMetrics() throws Exception {
    Ignite ignite = grid();
    // Visor task is internal and should not affect metrics.
    ignite.compute().withName("visor-test-task").execute(new TestInternalTask(), "testArg");
    // Let metrics update twice.
    awaitMetricsUpdate(2);
    ClusterMetrics metrics = ignite.cluster().localNode().metrics();
    info("Node metrics: " + metrics);
    assert metrics.getAverageActiveJobs() == 0;
    assert metrics.getAverageCancelledJobs() == 0;
    assert metrics.getAverageJobExecuteTime() == 0;
    assert metrics.getAverageJobWaitTime() == 0;
    assert metrics.getAverageRejectedJobs() == 0;
    assert metrics.getAverageWaitingJobs() == 0;
    assert metrics.getCurrentActiveJobs() == 0;
    assert metrics.getCurrentCancelledJobs() == 0;
    assert metrics.getCurrentJobExecuteTime() == 0;
    assert metrics.getCurrentJobWaitTime() == 0;
    assert metrics.getCurrentWaitingJobs() == 0;
    assert metrics.getMaximumActiveJobs() == 0;
    assert metrics.getMaximumCancelledJobs() == 0;
    assert metrics.getMaximumJobExecuteTime() == 0;
    assert metrics.getMaximumJobWaitTime() == 0;
    assert metrics.getMaximumRejectedJobs() == 0;
    assert metrics.getMaximumWaitingJobs() == 0;
    assert metrics.getTotalCancelledJobs() == 0;
    assert metrics.getTotalExecutedJobs() == 0;
    assert metrics.getTotalRejectedJobs() == 0;
    assert metrics.getTotalExecutedTasks() == 0;
    assert metrics.getTotalJobsExecutionTime() == 0;
    assertTrue("MaximumJobExecuteTime=" + metrics.getMaximumJobExecuteTime() + " is less than AverageJobExecuteTime=" + metrics.getAverageJobExecuteTime(), metrics.getMaximumJobExecuteTime() >= metrics.getAverageJobExecuteTime());
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) Ignite(org.apache.ignite.Ignite) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 18 with ClusterMetrics

use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.

the class ClusterNodeMetricsSelfTest method testIoMetrics.

/**
 * @throws Exception If failed.
 */
@Test
public void testIoMetrics() throws Exception {
    Ignite ignite0 = grid();
    Ignite ignite1 = startGrid(1);
    Object msg = new TestMessage();
    int size = ignite0.configuration().getMarshaller().marshal(msg).length;
    assert size > MSG_SIZE;
    final CountDownLatch latch = new CountDownLatch(MSG_CNT);
    ignite0.message().localListen(null, new MessagingListenActor<TestMessage>() {

        @Override
        protected void receive(UUID nodeId, TestMessage rcvMsg) throws Throwable {
            latch.countDown();
        }
    });
    ignite1.message().localListen(null, new MessagingListenActor<TestMessage>() {

        @Override
        protected void receive(UUID nodeId, TestMessage rcvMsg) throws Throwable {
            respond(rcvMsg);
        }
    });
    for (int i = 0; i < MSG_CNT; i++) message(ignite0.cluster().forRemotes()).send(null, msg);
    latch.await();
    ClusterMetrics metrics = ignite0.cluster().localNode().metrics();
    info("Node 0 metrics: " + metrics);
    // Time sync messages are being sent.
    assert metrics.getSentMessagesCount() >= MSG_CNT;
    assert metrics.getSentBytesCount() > size * MSG_CNT;
    assert metrics.getReceivedMessagesCount() >= MSG_CNT;
    assert metrics.getReceivedBytesCount() > size * MSG_CNT;
    metrics = ignite1.cluster().localNode().metrics();
    info("Node 1 metrics: " + metrics);
    // Time sync messages are being sent.
    assert metrics.getSentMessagesCount() >= MSG_CNT;
    assert metrics.getSentBytesCount() > size * MSG_CNT;
    assert metrics.getReceivedMessagesCount() >= MSG_CNT;
    assert metrics.getReceivedBytesCount() > size * MSG_CNT;
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 19 with ClusterMetrics

use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.

the class ClusterNodeMetricsSelfTest method testSingleTaskMetrics.

/**
 * @throws Exception If failed.
 */
@Test
public void testSingleTaskMetrics() throws Exception {
    Ignite ignite = grid();
    final CountDownLatch taskLatch = new CountDownLatch(1);
    ignite.compute().executeAsync(new GridTestTask(taskLatch), "testArg");
    // Let metrics update twice.
    awaitMetricsUpdate(2);
    taskLatch.countDown();
    awaitMetricsUpdate(1);
    ClusterMetrics metrics = ignite.cluster().localNode().metrics();
    info("Node metrics: " + metrics);
    assert metrics.getAverageActiveJobs() > 0;
    assert metrics.getAverageCancelledJobs() == 0;
    assert metrics.getAverageJobExecuteTime() >= 0;
    assert metrics.getAverageJobWaitTime() >= 0;
    assert metrics.getAverageRejectedJobs() == 0;
    assert metrics.getAverageWaitingJobs() == 0;
    assert metrics.getCurrentActiveJobs() == 0;
    assert metrics.getCurrentCancelledJobs() == 0;
    assert metrics.getCurrentJobExecuteTime() > 0;
    assert metrics.getCurrentJobWaitTime() == 0;
    assert metrics.getCurrentWaitingJobs() == 0;
    assert metrics.getMaximumActiveJobs() == 1;
    assert metrics.getMaximumCancelledJobs() == 0;
    assert metrics.getMaximumJobExecuteTime() >= 0;
    assert metrics.getMaximumJobWaitTime() >= 0;
    assert metrics.getMaximumRejectedJobs() == 0;
    assert metrics.getMaximumWaitingJobs() == 0;
    assert metrics.getTotalCancelledJobs() == 0;
    assert metrics.getTotalExecutedJobs() == 1;
    assert metrics.getTotalRejectedJobs() == 0;
    assert metrics.getTotalExecutedTasks() == 1;
    assert metrics.getTotalJobsExecutionTime() > 0;
    assertTrue("MaximumJobExecuteTime=" + metrics.getMaximumJobExecuteTime() + " is less than AverageJobExecuteTime=" + metrics.getAverageJobExecuteTime(), metrics.getMaximumJobExecuteTime() >= metrics.getAverageJobExecuteTime());
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) Ignite(org.apache.ignite.Ignite) GridTestTask(org.apache.ignite.GridTestTask) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 20 with ClusterMetrics

use of org.apache.ignite.cluster.ClusterMetrics in project ignite by apache.

the class ZookeeperClusterNode method writeExternal.

/**
 * {@inheritDoc}
 */
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    U.writeUuid(out, id);
    out.writeObject(consistentId);
    out.writeLong(internalId);
    out.writeLong(order);
    out.writeObject(ver);
    U.writeMap(out, attrs);
    U.writeCollection(out, addrs);
    U.writeCollection(out, hostNames);
    out.writeLong(sesTimeout);
    out.writeByte(flags);
    // Cluster metrics
    byte[] mtr = null;
    ClusterMetrics metrics = this.metrics;
    if (metrics != null)
        mtr = ClusterMetricsSnapshot.serialize(metrics);
    U.writeByteArray(out, mtr);
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics)

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