Search in sources :

Example 1 with IntMetric

use of org.apache.ignite.spi.metric.IntMetric in project ignite by apache.

the class MetricsSelfTest method testIntMetric.

/**
 */
@Test
public void testIntMetric() throws Exception {
    final int[] v = new int[] { 42 };
    mreg.register("imtest", () -> v[0], "test");
    IntMetric m = mreg.findMetric("imtest");
    assertEquals(v[0], m.value());
    v[0] = 1;
    assertEquals(v[0], m.value());
}
Also used : IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with IntMetric

use of org.apache.ignite.spi.metric.IntMetric in project ignite by apache.

the class ClusterBaselineNodesMetricsSelfTest method testBaselineNodes.

/**
 * @throws Exception If failed.
 */
@Test
public void testBaselineNodes() throws Exception {
    // Start 2 server nodes.
    IgniteEx ignite0 = startGrid(0);
    ignite0.cluster().baselineAutoAdjustEnabled(false);
    startGrid(1);
    // Cluster metrics.
    ClusterMetricsMXBean mxBeanCluster = mxBean(0, ClusterMetricsMXBeanImpl.class);
    MetricRegistry mreg = ignite0.context().metric().registry(CLUSTER_METRICS);
    ignite0.cluster().active(true);
    // Added 2 server nodes to baseline.
    resetBlt();
    // Add server node outside of the baseline.
    startGrid(2);
    // Start client node.
    startClientGrid(3);
    Collection<BaselineNode> baselineNodes;
    // State #0: 3 server nodes (2 total baseline nodes, 2 active baseline nodes), 1 client node
    log.info(String.format(">>> State #0: topology version = %d", ignite0.cluster().topologyVersion()));
    assertEquals(3, mxBeanCluster.getTotalServerNodes());
    assertEquals(3, mreg.<IntMetric>findMetric(TOTAL_SERVER_NODES).value());
    assertEquals(1, mxBeanCluster.getTotalClientNodes());
    assertEquals(1, mreg.<IntMetric>findMetric(TOTAL_CLIENT_NODES).value());
    assertEquals(2, mxBeanCluster.getTotalBaselineNodes());
    assertEquals(2, mreg.<IntMetric>findMetric(TOTAL_BASELINE_NODES).value());
    assertEquals(2, mxBeanCluster.getActiveBaselineNodes());
    assertEquals(2, mreg.<IntMetric>findMetric(ACTIVE_BASELINE_NODES).value());
    assertEquals(2, (baselineNodes = ignite0.cluster().currentBaselineTopology()) != null ? baselineNodes.size() : 0);
    stopGrid(1, true);
    // State #1: 2 server nodes (2 total baseline nodes, 1 active baseline node), 1 client node
    log.info(String.format(">>> State #1: topology version = %d", ignite0.cluster().topologyVersion()));
    assertEquals(2, mxBeanCluster.getTotalServerNodes());
    assertEquals(2, mreg.<IntMetric>findMetric(TOTAL_SERVER_NODES).value());
    assertEquals(1, mxBeanCluster.getTotalClientNodes());
    assertEquals(1, mreg.<IntMetric>findMetric(TOTAL_CLIENT_NODES).value());
    assertEquals(2, mxBeanCluster.getTotalBaselineNodes());
    assertEquals(2, mreg.<IntMetric>findMetric(TOTAL_BASELINE_NODES).value());
    assertEquals(1, mxBeanCluster.getActiveBaselineNodes());
    assertEquals(1, mreg.<IntMetric>findMetric(ACTIVE_BASELINE_NODES).value());
    assertEquals(2, (baselineNodes = ignite0.cluster().currentBaselineTopology()) != null ? baselineNodes.size() : 0);
    startGrid(1);
    ClusterMetricsMXBean mxBeanLocalNode1 = mxBean(1, ClusterLocalNodeMetricsMXBeanImpl.class);
    // State #2: 3 server nodes (2 total baseline nodes, 2 active baseline nodes), 1 client node
    log.info(String.format(">>> State #2: topology version = %d", ignite0.cluster().topologyVersion()));
    assertEquals(3, mxBeanCluster.getTotalServerNodes());
    assertEquals(3, mreg.<IntMetric>findMetric(TOTAL_SERVER_NODES).value());
    assertEquals(1, mxBeanCluster.getTotalClientNodes());
    assertEquals(1, mreg.<IntMetric>findMetric(TOTAL_CLIENT_NODES).value());
    assertEquals(2, mxBeanCluster.getTotalBaselineNodes());
    assertEquals(2, mreg.<IntMetric>findMetric(TOTAL_BASELINE_NODES).value());
    assertEquals(2, mxBeanCluster.getActiveBaselineNodes());
    assertEquals(2, mreg.<IntMetric>findMetric(ACTIVE_BASELINE_NODES).value());
    assertEquals(1, mxBeanLocalNode1.getTotalBaselineNodes());
    assertEquals(2, (baselineNodes = ignite0.cluster().currentBaselineTopology()) != null ? baselineNodes.size() : 0);
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ClusterMetricsMXBean(org.apache.ignite.mxbean.ClusterMetricsMXBean) IntMetric(org.apache.ignite.spi.metric.IntMetric) BaselineNode(org.apache.ignite.cluster.BaselineNode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest)

Example 3 with IntMetric

use of org.apache.ignite.spi.metric.IntMetric in project ignite by apache.

the class CacheGroupMetricsTest method testCacheGroupMetrics.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheGroupMetrics() throws Exception {
    pds = false;
    startGrid(0);
    startGrid(1);
    startGrid(2);
    awaitPartitionMapExchange(true, false, null);
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp1 = cacheGroupMetrics(0, "group1");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp2 = cacheGroupMetrics(0, "group2");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp3 = cacheGroupMetrics(0, "cache4");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean1Grp1 = cacheGroupMetrics(1, "group1");
    T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean2Grp1 = cacheGroupMetrics(2, "group1");
    assertEquals("group1", mxBean0Grp1.get1().getGroupName());
    assertEquals(null, mxBean0Grp3.get1().getGroupName());
    assertEquals(3, mxBean0Grp1.get1().getBackups());
    assertEquals(10, mxBean0Grp1.get1().getPartitions());
    assertEquals(1, mxBean0Grp1.get2().<IntMetric>findMetric("MinimumNumberOfPartitionCopies").value());
    assertEquals(3, mxBean0Grp1.get2().<IntMetric>findMetric("MaximumNumberOfPartitionCopies").value());
    assertEquals(0, mxBean0Grp1.get1().getClusterMovingPartitionsCount());
    assertEquals(19, mxBean0Grp1.get1().getClusterOwningPartitionsCount());
    assertEquals(7, mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
    assertEquals(6, mxBean1Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
    assertEquals(6, mxBean2Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
    assertEquals(F.asList("cache1"), mxBean0Grp1.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
    assertEquals(F.asList("cache2", "cache3"), mxBean0Grp2.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
    assertEquals(F.asList("cache4"), mxBean0Grp3.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
    assertEquals(arrayToAssignmentMap(assignmentMapArr), mxBean0Grp1.get2().<ObjectMetric<Map<Integer, List<String>>>>findMetric("AffinityPartitionsAssignmentMap").value());
    assertEquals(arrayToAllocationMap(assignmentMapArr), mxBean0Grp1.get2().<ObjectMetric<Map<Integer, List<String>>>>findMetric("OwningPartitionsAllocationMap").value());
    ObjectMetric<Map<Integer, List<String>>> movingPartitionsAllocationMap = mxBean0Grp1.get2().findMetric("MovingPartitionsAllocationMap");
    assertEquals(arrayToAllocationMap(new int[10][]), movingPartitionsAllocationMap.value());
    try (IgniteDataStreamer<Integer, Integer> st = grid(0).dataStreamer("cache1")) {
        for (int i = 0; i < 50_000; i++) st.addData(i, i);
    }
    // Pause rebalance to check instant partitions states.
    grid(0).rebalanceEnabled(false);
    grid(1).rebalanceEnabled(false);
    stopGrid(2);
    // Check moving partitions while rebalancing.
    assertFalse(arrayToAllocationMap(new int[10][]).equals(movingPartitionsAllocationMap.value()));
    int movingCnt = mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeMovingPartitionsCount").value();
    assertTrue(movingCnt > 0);
    assertTrue(mxBean0Grp1.get1().getClusterMovingPartitionsCount() > 0);
    final CountDownLatch evictLatch = new CountDownLatch(1);
    // Block all evicting threads to count total renting partitions.
    grid(0).events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            try {
                evictLatch.await();
            } catch (InterruptedException e) {
                log.error("Interrupted", e);
            }
            return true;
        }
    }, EventType.EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
    grid(0).rebalanceEnabled(true);
    grid(1).rebalanceEnabled(true);
    startGrid(2);
    try {
        assertTrue("Renting partitions count when node returns not equals to moved partitions when node left", GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                IntMetric localNodeRentingPartitionsCount = mxBean0Grp1.get2().findMetric("LocalNodeRentingPartitionsCount");
                log.info("Renting partitions count: " + localNodeRentingPartitionsCount.value());
                log.info("Renting entries count: " + mxBean0Grp1.get2().findMetric("LocalNodeRentingEntriesCount").getAsString());
                return localNodeRentingPartitionsCount.value() == movingCnt;
            }
        }, 10_000L));
        assertTrue("Renting entries count is 0", mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeRentingPartitionsCount").value() > 0);
    } finally {
        evictLatch.countDown();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) Event(org.apache.ignite.events.Event) ArrayList(java.util.ArrayList) List(java.util.List) IntMetric(org.apache.ignite.spi.metric.IntMetric) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with IntMetric

use of org.apache.ignite.spi.metric.IntMetric in project ignite by apache.

the class NodeSslConnectionMetricTest method testDiscovery.

/**
 * Tests SSL discovery metrics produced by node connection.
 */
@Test
public void testDiscovery() throws Exception {
    MetricRegistry reg = mreg(startClusterNode(0), DISCO_METRICS);
    startGrid(nodeConfiguration(1, true, "client", "trustone", CIPHER_SUITE, "TLSv1.2"));
    assertTrue(reg.<BooleanMetric>findMetric("SslEnabled").value());
    assertEquals(0, reg.<IntMetric>findMetric("RejectedSslConnectionsCount").value());
    // Tests untrusted certificate.
    checkNodeJoinFails(2, true, "thinClient", "trusttwo", CIPHER_SUITE, "TLSv1.2");
    checkNodeJoinFails(2, false, "thinClient", "trusttwo", CIPHER_SUITE, "TLSv1.2");
    // Tests untrusted cipher suites.
    checkNodeJoinFails(2, true, "client", "trustone", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2");
    checkNodeJoinFails(2, false, "node01", "trustone", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2");
    // Tests mismatched protocol versions.
    checkNodeJoinFails(2, true, "client", "trustone", null, "TLSv1.1");
    checkNodeJoinFails(2, false, "node01", "trustone", null, "TLSv1.1");
    // In case of an SSL error, the client and server nodes make 2 additional connection attempts.
    assertTrue(waitForCondition(() -> 18 == reg.<IntMetric>findMetric("RejectedSslConnectionsCount").value(), getTestTimeout()));
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with IntMetric

use of org.apache.ignite.spi.metric.IntMetric in project ignite by apache.

the class NodeSslConnectionMetricTest method testSslDisabled.

/**
 * Checks the status of the SSL metric if SSL is not configured on the node.
 */
@Test
public void testSslDisabled() throws Exception {
    IgniteEx srv = startGrid();
    MetricRegistry discoReg = mreg(srv, DISCO_METRICS);
    assertFalse(discoReg.<BooleanMetric>findMetric("SslEnabled").value());
    assertEquals(0, discoReg.<IntMetric>findMetric("RejectedSslConnectionsCount").value());
    MetricRegistry commReg = mreg(srv, COMMUNICATION_METRICS_GROUP_NAME);
    assertFalse(commReg.<BooleanMetric>findMetric(SSL_ENABLED_METRIC_NAME).value());
    assertNull(commReg.<IntMetric>findMetric(SSL_REJECTED_SESSIONS_CNT_METRIC_NAME));
    assertNull(commReg.<HistogramMetric>findMetric(SSL_HANDSHAKE_DURATION_HISTOGRAM_METRIC_NAME));
    assertEquals(0, commReg.<IntMetric>findMetric(SESSIONS_CNT_METRIC_NAME).value());
    MetricRegistry cliConnReg = mreg(srv, CLIENT_CONNECTOR_METRICS);
    assertFalse(cliConnReg.<BooleanMetric>findMetric(SSL_ENABLED_METRIC_NAME).value());
    assertNull(cliConnReg.<IntMetric>findMetric(SSL_REJECTED_SESSIONS_CNT_METRIC_NAME));
    assertNull(cliConnReg.<HistogramMetric>findMetric(SSL_HANDSHAKE_DURATION_HISTOGRAM_METRIC_NAME));
    assertEquals(0, cliConnReg.<IntMetric>findMetric(SESSIONS_CNT_METRIC_NAME).value());
    MetricRegistry restConnReg = mreg(srv, REST_CONNECTOR_METRIC_REGISTRY_NAME);
    assertNull(restConnReg.<BooleanMetric>findMetric(SSL_ENABLED_METRIC_NAME));
    assertNull(restConnReg.<IntMetric>findMetric(SSL_REJECTED_SESSIONS_CNT_METRIC_NAME));
    assertNull(restConnReg.<HistogramMetric>findMetric(SSL_HANDSHAKE_DURATION_HISTOGRAM_METRIC_NAME));
    assertNull(restConnReg.<IntMetric>findMetric(SESSIONS_CNT_METRIC_NAME));
    stopAllGrids();
    srv = startGrid(getConfiguration().setConnectorConfiguration(new ConnectorConfiguration()));
    restConnReg = mreg(srv, REST_CONNECTOR_METRIC_REGISTRY_NAME);
    assertFalse(restConnReg.<BooleanMetric>findMetric(SSL_ENABLED_METRIC_NAME).value());
    assertEquals(0, restConnReg.<IntMetric>findMetric(SESSIONS_CNT_METRIC_NAME).value());
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IntMetric (org.apache.ignite.spi.metric.IntMetric)12 Test (org.junit.Test)10 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 IgniteEx (org.apache.ignite.internal.IgniteEx)6 LongMetric (org.apache.ignite.spi.metric.LongMetric)5 List (java.util.List)3 Map (java.util.Map)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 BooleanMetric (org.apache.ignite.spi.metric.BooleanMetric)3 ObjectMetric (org.apache.ignite.spi.metric.ObjectMetric)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)2 Message (org.apache.ignite.plugin.extensions.communication.Message)2 Scope (io.opencensus.common.Scope)1