Search in sources :

Example 11 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class IoStatisticsSelfTest method physicalReads.

/**
 * @param statType Type of statistics which need to take.
 * @param name name of statistics which need to take, e.g. cache name
 * @param subName subName of statistics which need to take, e.g. index name.
 * @return Number of physical reads since last reset statistics.
 */
public Long physicalReads(GridMetricManager mmgr, IoStatisticsType statType, String name, String subName) {
    String fullName = subName == null ? name : metricName(name, subName);
    MetricRegistry mreg = mmgr.registry(metricName(statType.metricGroupName(), fullName));
    if (mreg == null)
        return null;
    switch(statType) {
        case CACHE_GROUP:
            return mreg.<LongMetric>findMetric(PHYSICAL_READS).value();
        case HASH_INDEX:
        case SORTED_INDEX:
            long leaf = mreg.<LongMetric>findMetric(PHYSICAL_READS_LEAF).value();
            long inner = mreg.<LongMetric>findMetric(PHYSICAL_READS_INNER).value();
            return leaf + inner;
        default:
            return null;
    }
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry)

Example 12 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class MetricsConfigurationTest method testConfigRemovedOnRegistryRemove.

/**
 * Tests metric configuration removed on registry remove.
 */
@Test
public void testConfigRemovedOnRegistryRemove() throws Exception {
    checkOnStartAndRestart((g0, g1) -> {
        MetricRegistry mreg = g0.context().metric().registry(TEST_REG);
        mreg.hitRateMetric(HITRATE_NAME, "test", 10000, 5);
        mreg.histogram(HISTOGRAM_NAME, new long[] { 250, 500 }, "test");
        metricsBean(g0).configureHistogramMetric(metricName(TEST_REG, HISTOGRAM_NAME), BOUNDS);
        metricsBean(g0).configureHitRateMetric(metricName(TEST_REG, HITRATE_NAME), 1000);
    }, (g0, g1) -> {
        MetricRegistry mreg = g0.context().metric().registry(TEST_REG);
        HitRateMetric hitRate = mreg.hitRateMetric(HITRATE_NAME, "test", 10000, 5);
        HistogramMetricImpl histogram = mreg.histogram(HISTOGRAM_NAME, new long[] { 250, 500 }, "test");
        assertEquals(1000, hitRate.rateTimeInterval());
        assertArrayEquals(BOUNDS, histogram.bounds());
        assertEquals((Long) 1000L, g0.context().distributedMetastorage().read(metricName(HITRATE_CFG_PREFIX, TEST_REG, HITRATE_NAME)));
        assertArrayEquals(BOUNDS, g0.context().distributedMetastorage().read(metricName(HISTOGRAM_CFG_PREFIX, TEST_REG, HISTOGRAM_NAME)));
        assertEquals((Long) 1000L, g1.context().distributedMetastorage().read(metricName(HITRATE_CFG_PREFIX, TEST_REG, HITRATE_NAME)));
        assertArrayEquals(BOUNDS, g1.context().distributedMetastorage().read(metricName(HISTOGRAM_CFG_PREFIX, TEST_REG, HISTOGRAM_NAME)));
        g0.context().metric().remove(TEST_REG);
        assertNull(g0.context().distributedMetastorage().read(metricName(HITRATE_CFG_PREFIX, TEST_REG, HITRATE_NAME)));
        assertNull(g0.context().distributedMetastorage().read(metricName(HISTOGRAM_CFG_PREFIX, TEST_REG, HISTOGRAM_NAME)));
        assertNull(g1.context().distributedMetastorage().read(metricName(HITRATE_CFG_PREFIX, TEST_REG, HITRATE_NAME)));
        assertNull(g1.context().distributedMetastorage().read(metricName(HISTOGRAM_CFG_PREFIX, TEST_REG, HISTOGRAM_NAME)));
    });
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 13 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class SystemMetricsTest method testCpuLoadMetric.

/**
 * Checks that the process CPU load metric is positive.
 */
@Test
public void testCpuLoadMetric() {
    MetricRegistry sysReg = grid(0).context().metric().registry(GridMetricManager.SYS_METRICS);
    DoubleMetric cpuLoad = sysReg.doubleMetric(GridMetricManager.CPU_LOAD, GridMetricManager.CPU_LOAD_DESCRIPTION);
    double loadVal = cpuLoad.value();
    assertTrue("CPU Load is negative: " + loadVal, loadVal >= 0);
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 14 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class IgniteKernal method registerMetrics.

/**
 * Registers metrics.
 */
private void registerMetrics() {
    if (!ctx.metric().enabled())
        return;
    MetricRegistry reg = ctx.metric().registry(GridMetricManager.IGNITE_METRICS);
    reg.register("fullVersion", this::fullVersion, String.class, FULL_VER_DESC);
    reg.register("copyright", () -> COPYRIGHT, String.class, COPYRIGHT_DESC);
    reg.register("startTimestampFormatted", this::startTimeFormatted, String.class, START_TIMESTAMP_FORMATTED_DESC);
    reg.register("isRebalanceEnabled", this::isRebalanceEnabled, IS_REBALANCE_ENABLED_DESC);
    reg.register("uptimeFormatted", this::upTimeFormatted, String.class, UPTIME_FORMATTED_DESC);
    reg.register("startTimestamp", this::startTimestamp, START_TIMESTAMP_DESC);
    reg.register("uptime", this::upTime, UPTIME_DESC);
    reg.register("osInformation", this::osInformation, String.class, OS_INFO_DESC);
    reg.register("jdkInformation", this::jdkInformation, String.class, JDK_INFO_DESC);
    reg.register("osUser", this::osUser, String.class, OS_USER_DESC);
    reg.register("vmName", this::vmName, String.class, VM_NAME_DESC);
    reg.register("instanceName", this::name, String.class, INSTANCE_NAME_DESC);
    reg.register("currentCoordinatorFormatted", this::currentCoordinatorFormatted, String.class, CUR_COORDINATOR_FORMATTED_DESC);
    reg.register("isNodeInBaseline", this::nodeInBaseline, IS_NODE_BASELINE_DESC);
    reg.register("longJVMPausesCount", this::longJVMPausesCount, LONG_JVM_PAUSES_CNT_DESC);
    reg.register("longJVMPausesTotalDuration", this::longJVMPausesTotalDuration, LONG_JVM_PAUSES_TOTAL_DURATION_DESC);
    reg.register("longJVMPauseLastEvents", this::longJVMPauseLastEvents, Map.class, LONG_JVM_PAUSE_LAST_EVENTS_DESC);
    reg.register("active", () -> ctx.state().clusterState().state().active(), Boolean.class, ACTIVE_DESC);
    reg.register("clusterState", this::clusterState, String.class, CLUSTER_STATE_DESC);
    reg.register("lastClusterStateChangeTime", this::lastClusterStateChangeTime, LAST_CLUSTER_STATE_CHANGE_TIME_DESC);
    reg.register("userAttributesFormatted", this::userAttributesFormatted, List.class, USER_ATTRS_FORMATTED_DESC);
    reg.register("gridLoggerFormatted", this::gridLoggerFormatted, String.class, GRID_LOG_FORMATTED_DESC);
    reg.register("executorServiceFormatted", this::executorServiceFormatted, String.class, EXECUTOR_SRVC_FORMATTED_DESC);
    reg.register("igniteHome", this::igniteHome, String.class, IGNITE_HOME_DESC);
    reg.register("mBeanServerFormatted", this::mbeanServerFormatted, String.class, MBEAN_SERVER_FORMATTED_DESC);
    reg.register("localNodeId", this::localNodeId, UUID.class, LOC_NODE_ID_DESC);
    reg.register("isPeerClassLoadingEnabled", this::peerClassLoadingEnabled, Boolean.class, IS_PEER_CLS_LOADING_ENABLED_DESC);
    reg.register("lifecycleBeansFormatted", this::lifecycleBeansFormatted, List.class, LIFECYCLE_BEANS_FORMATTED_DESC);
    reg.register("discoverySpiFormatted", this::discoverySpiFormatted, String.class, DISCOVERY_SPI_FORMATTED_DESC);
    reg.register("communicationSpiFormatted", this::communicationSpiFormatted, String.class, COMMUNICATION_SPI_FORMATTED_DESC);
    reg.register("deploymentSpiFormatted", this::deploymentSpiFormatted, String.class, DEPLOYMENT_SPI_FORMATTED_DESC);
    reg.register("checkpointSpiFormatted", this::checkpointSpiFormatted, String.class, CHECKPOINT_SPI_FORMATTED_DESC);
    reg.register("collisionSpiFormatted", this::collisionSpiFormatted, String.class, COLLISION_SPI_FORMATTED_DESC);
    reg.register("eventStorageSpiFormatted", this::eventStorageSpiFormatted, String.class, EVT_STORAGE_SPI_FORMATTED_DESC);
    reg.register("failoverSpiFormatted", this::failoverSpiFormatted, String.class, FAILOVER_SPI_FORMATTED_DESC);
    reg.register("loadBalancingSpiFormatted", this::loadBalancingSpiFormatted, String.class, LOAD_BALANCING_SPI_FORMATTED_DESC);
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry)

Example 15 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry 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)

Aggregations

MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)86 Test (org.junit.Test)52 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)29 IgniteEx (org.apache.ignite.internal.IgniteEx)26 LongMetric (org.apache.ignite.spi.metric.LongMetric)26 List (java.util.List)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 UUID (java.util.UUID)10 Map (java.util.Map)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 ArrayList (java.util.ArrayList)7 IgniteException (org.apache.ignite.IgniteException)7 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 IntMetric (org.apache.ignite.spi.metric.IntMetric)7 IgniteCache (org.apache.ignite.IgniteCache)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 Arrays (java.util.Arrays)5 HashSet (java.util.HashSet)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5