Search in sources :

Example 1 with HistogramMetric

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

the class CacheMetricsAddRemoveTest method checkMetricsNotEmpty.

/**
 */
private void checkMetricsNotEmpty(String cachePrefix) {
    for (int i = 0; i < 2; i++) {
        GridMetricManager mmgr = metricManager(i);
        MetricRegistry mreg = mmgr.registry(cachePrefix);
        assertNotNull(mreg.findMetric(CACHE_GETS));
        assertNotNull(mreg.findMetric(CACHE_PUTS));
        assertNotNull(mreg.findMetric(GET_TIME));
        assertArrayEquals(BOUNDS, mreg.<HistogramMetric>findMetric(GET_TIME).bounds());
        if (nearEnabled) {
            mreg = mmgr.registry(metricName(cachePrefix, "near"));
            assertNotNull(mreg.findMetric(CACHE_GETS));
            assertNotNull(mreg.findMetric(CACHE_PUTS));
            assertNotNull(mreg.findMetric(GET_TIME));
            assertArrayEquals(BOUNDS, mreg.<HistogramMetric>findMetric(GET_TIME).bounds());
        }
    }
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager)

Example 2 with HistogramMetric

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

the class MetricsConfigurationTest method testHistogramConfiguration.

/**
 * Tests configuration of {@link HistogramMetric}.
 */
@Test
public void testHistogramConfiguration() throws Exception {
    try (IgniteEx g = startGrid(0)) {
        MetricsMxBean bean = metricsBean(g);
        // Empty name.
        assertThrowsWithCause(() -> bean.configureHistogramMetric(null, BOUNDS), NullPointerException.class);
        // Wrong bounds value.
        assertThrowsWithCause(() -> bean.configureHistogramMetric(metricName(TX_METRICS, METRIC_SYSTEM_TIME_HISTOGRAM), null), NullPointerException.class);
        assertThrowsWithCause(() -> bean.configureHistogramMetric(metricName(TX_METRICS, METRIC_SYSTEM_TIME_HISTOGRAM), new long[0]), IllegalArgumentException.class);
        bean.configureHistogramMetric(metricName(TX_METRICS, METRIC_SYSTEM_TIME_HISTOGRAM), BOUNDS);
        HistogramMetric systemTime = g.context().metric().registry(TX_METRICS).findMetric(METRIC_SYSTEM_TIME_HISTOGRAM);
        assertArrayEquals(BOUNDS, systemTime.bounds());
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) MetricsMxBean(org.apache.ignite.mxbean.MetricsMxBean) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with HistogramMetric

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

the class MetricsConfigurationTest method testConfigRemovedOnCacheRemove.

/**
 * Tests metric configuration removed on registry remove.
 */
@Test
public void testConfigRemovedOnCacheRemove() throws Exception {
    String cacheRegName = cacheMetricsRegistryName("test", false);
    checkOnStartAndRestart((g0, g1) -> {
        g0.createCache("test");
        awaitPartitionMapExchange();
        HistogramMetricImpl getTime = g0.context().metric().registry(cacheRegName).findMetric("GetTime");
        assertNotEquals(BOUNDS.length, getTime.bounds().length);
        metricsBean(g0).configureHistogramMetric(metricName(cacheRegName, "GetTime"), BOUNDS);
        assertArrayEquals(BOUNDS, g0.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
        assertArrayEquals(BOUNDS, g1.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
    }, (g0, g1) -> {
        assertArrayEquals(BOUNDS, g0.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
        assertArrayEquals(BOUNDS, g1.context().metric().registry(cacheRegName).<HistogramMetric>findMetric("GetTime").bounds());
        g0.destroyCache("test");
        awaitPartitionMapExchange();
        assertNull(g0.context().distributedMetastorage().read(metricName(cacheRegName, "GetTime")));
        assertNull(g1.context().distributedMetastorage().read(metricName(cacheRegName, "GetTime")));
    });
}
Also used : HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with HistogramMetric

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

the class MetricRegistryMBean method getMBeanInfo.

/**
 * {@inheritDoc}
 */
@Override
public MBeanInfo getMBeanInfo() {
    Iterator<Metric> iter = mreg.iterator();
    List<MBeanAttributeInfo> attributes = new ArrayList<>();
    iter.forEachRemaining(metric -> {
        if (metric instanceof HistogramMetric) {
            String[] names = histogramBucketNames((HistogramMetric) metric);
            assert names.length == ((HistogramMetric) metric).value().length;
            for (String name : names) {
                String n = name.substring(mreg.name().length() + 1);
                attributes.add(new MBeanAttributeInfo(n, Long.class.getName(), metric.description() != null ? metric.description() : n, true, false, false));
            }
        } else {
            attributes.add(new MBeanAttributeInfo(metric.name().substring(mreg.name().length() + 1), metricClass(metric), metric.description() != null ? metric.description() : metric.name(), true, false, false));
        }
    });
    return new MBeanInfo(ReadOnlyMetricManager.class.getName(), mreg.name(), attributes.toArray(new MBeanAttributeInfo[attributes.size()]), null, null, null);
}
Also used : MBeanInfo(javax.management.MBeanInfo) ReadOnlyMetricManager(org.apache.ignite.spi.metric.ReadOnlyMetricManager) ArrayList(java.util.ArrayList) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) Metric(org.apache.ignite.spi.metric.Metric) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 5 with HistogramMetric

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

the class GridServiceMetricsTest method testServiceMetrics.

/**
 * Invokes service in various ways: from clients, servers, etc. Checks these calls reflect in the metrics.
 *
 * @param serverCnt Number of server nodes.
 * @param clientCnt Number of client nodes.
 * @param perClusterCnt Number of service instances per cluster.
 * @param perNodeCnt Number of service instances per node.
 */
private void testServiceMetrics(int serverCnt, int clientCnt, int perClusterCnt, int perNodeCnt) throws Throwable {
    List<IgniteEx> servers = startGrids(serverCnt, false);
    List<IgniteEx> clients = startGrids(clientCnt, true);
    servers.get(0).services().deploy(serviceCfg(MyServiceFactory.create(), perClusterCnt, perNodeCnt));
    awaitPartitionMapExchange();
    List<MyService> serverStickyProxies = servers.stream().map(ignite -> (MyService) ignite.services().serviceProxy(SRVC_NAME, MyService.class, true)).collect(Collectors.toList());
    List<MyService> clientStickyProxies = clients.stream().map(ignite -> (MyService) ignite.services().serviceProxy(SRVC_NAME, MyService.class, true)).collect(Collectors.toList());
    long invokeCollector = 0;
    // Call service through the server proxies.
    for (int i = 0; i < INVOKE_CNT; ++i) {
        // Call from server.
        IgniteEx ignite = servers.get(i % servers.size());
        callService4Times(ignite, serverStickyProxies.get(i % serverStickyProxies.size()));
        // Call from client.
        ignite = clients.get(i % clients.size());
        callService4Times(ignite, clientStickyProxies.get(i % clientStickyProxies.size()));
        invokeCollector += 8;
    }
    long invokesInMetrics = 0;
    // Calculate and check invocations within the metrics.
    for (IgniteEx ignite : servers) {
        ReadOnlyMetricRegistry metrics = findMetricRegistry(ignite.context().metric(), SRVC_NAME);
        // Metrics may not be deployed on this server node.
        if (metrics == null)
            continue;
        for (Metric metric : metrics) {
            if (metric instanceof HistogramMetric)
                invokesInMetrics += sumHistogramEntries((HistogramMetric) metric);
        }
    }
    // Compare calls number and metrics number.
    assertEquals("Calculated wrong service invocation number.", invokesInMetrics, invokeCollector);
}
Also used : G(org.apache.ignite.internal.util.typedef.G) Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) JmxMetricExporterSpi(org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Metric(org.apache.ignite.spi.metric.Metric) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) MyServiceFactory(org.apache.ignite.internal.processors.service.inner.MyServiceFactory) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Service(org.apache.ignite.services.Service) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteServiceProcessor.serviceMetricRegistryName(org.apache.ignite.internal.processors.service.IgniteServiceProcessor.serviceMetricRegistryName) Method(java.lang.reflect.Method) MyService(org.apache.ignite.internal.processors.service.inner.MyService) ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) MyService(org.apache.ignite.internal.processors.service.inner.MyService) IgniteEx(org.apache.ignite.internal.IgniteEx) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) Metric(org.apache.ignite.spi.metric.Metric)

Aggregations

HistogramMetric (org.apache.ignite.spi.metric.HistogramMetric)11 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 IgniteEx (org.apache.ignite.internal.IgniteEx)5 Metric (org.apache.ignite.spi.metric.Metric)5 ArrayList (java.util.ArrayList)3 GridMetricManager (org.apache.ignite.internal.processors.metric.GridMetricManager)3 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)3 BooleanMetric (org.apache.ignite.spi.metric.BooleanMetric)3 DoubleMetric (org.apache.ignite.spi.metric.DoubleMetric)3 IntMetric (org.apache.ignite.spi.metric.IntMetric)3 LongMetric (org.apache.ignite.spi.metric.LongMetric)3 ObjectMetric (org.apache.ignite.spi.metric.ObjectMetric)3 List (java.util.List)2 AtomicLongMetric (org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric)2 ReadOnlyMetricManager (org.apache.ignite.spi.metric.ReadOnlyMetricManager)2 Iterables (com.google.common.collect.Iterables)1 Scope (io.opencensus.common.Scope)1 LastValue (io.opencensus.stats.Aggregation.LastValue)1 Measure (io.opencensus.stats.Measure)1