Search in sources :

Example 6 with HistogramMetric

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

the class OpenCensusMetricExporterSpi method export.

/**
 * {@inheritDoc}
 */
@Override
public void export() {
    StatsRecorder recorder = Stats.getStatsRecorder();
    try (Scope globalScope = tagScope()) {
        MeasureMap mmap = recorder.newMeasureMap();
        mreg.forEach(mreg -> {
            if (filter != null && !filter.test(mreg))
                return;
            mreg.forEach(metric -> {
                if (metric instanceof LongMetric || metric instanceof IntMetric || metric instanceof BooleanMetric || (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == Date.class) || (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == OffsetDateTime.class)) {
                    long val;
                    if (metric instanceof LongMetric)
                        val = ((LongMetric) metric).value();
                    else if (metric instanceof IntMetric)
                        val = ((IntMetric) metric).value();
                    else if (metric instanceof BooleanMetric)
                        val = ((BooleanMetric) metric).value() ? 1 : 0;
                    else if (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == Date.class)
                        val = ((ObjectMetric<Date>) metric).value().getTime();
                    else
                        val = ((ObjectMetric<OffsetDateTime>) metric).value().toInstant().toEpochMilli();
                    if (val < 0) {
                        if (log.isDebugEnabled())
                            log.debug("OpenCensus doesn't support negative values. Skip record of " + metric.name());
                        return;
                    }
                    MeasureLong msr = (MeasureLong) measures.computeIfAbsent(metric.name(), k -> createMeasure(metric, CREATE_LONG));
                    mmap.put(msr, val);
                } else if (metric instanceof DoubleMetric) {
                    double val = ((DoubleMetric) metric).value();
                    if (val < 0) {
                        if (log.isDebugEnabled())
                            log.debug("OpenCensus doesn't support negative values. Skip record of " + metric.name());
                        return;
                    }
                    MeasureDouble msr = (MeasureDouble) measures.computeIfAbsent(metric.name(), k -> createMeasure(metric, CREATE_DOUBLE));
                    mmap.put(msr, val);
                } else if (metric instanceof HistogramMetric) {
                    String[] names = histogramBucketNames((HistogramMetric) metric);
                    long[] vals = ((HistogramMetric) metric).value();
                    assert names.length == vals.length;
                    for (int i = 0; i < vals.length; i++) {
                        String name = names[i];
                        MeasureLong msr = (MeasureLong) measures.computeIfAbsent(name, k -> createMeasureLong(name, metric.description()));
                        mmap.put(msr, vals[i]);
                    }
                } else if (log.isDebugEnabled()) {
                    log.debug(metric.name() + "[" + metric.getClass() + "] not supported by Opencensus exporter");
                }
            });
        });
        mmap.record();
    }
}
Also used : StatsRecorder(io.opencensus.stats.StatsRecorder) TagContextBuilder(io.opencensus.tags.TagContextBuilder) StatsRecorder(io.opencensus.stats.StatsRecorder) IgniteSpiContext(org.apache.ignite.spi.IgniteSpiContext) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Metric(org.apache.ignite.spi.metric.Metric) Stats(io.opencensus.stats.Stats) Date(java.util.Date) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Function(java.util.function.Function) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) ArrayList(java.util.ArrayList) PushMetricsExporterAdapter(org.apache.ignite.internal.processors.metric.PushMetricsExporterAdapter) Measure(io.opencensus.stats.Measure) MeasureDouble(io.opencensus.stats.Measure.MeasureDouble) MeasureMap(io.opencensus.stats.MeasureMap) Map(java.util.Map) TagMetadata(io.opencensus.tags.TagMetadata) TagValue(io.opencensus.tags.TagValue) View(io.opencensus.stats.View) ReadOnlyMetricManager(org.apache.ignite.spi.metric.ReadOnlyMetricManager) Tags(io.opencensus.tags.Tags) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) Scope(io.opencensus.common.Scope) Name(io.opencensus.stats.View.Name) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LastValue(io.opencensus.stats.Aggregation.LastValue) MeasureLong(io.opencensus.stats.Measure.MeasureLong) T2(org.apache.ignite.internal.util.typedef.T2) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) TagKey(io.opencensus.tags.TagKey) MetricUtils(org.apache.ignite.internal.processors.metric.impl.MetricUtils) UNLIMITED_PROPAGATION(io.opencensus.tags.TagMetadata.TagTtl.UNLIMITED_PROPAGATION) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) LongMetric(org.apache.ignite.spi.metric.LongMetric) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) MeasureDouble(io.opencensus.stats.Measure.MeasureDouble) MeasureMap(io.opencensus.stats.MeasureMap) Scope(io.opencensus.common.Scope) OffsetDateTime(java.time.OffsetDateTime) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) MeasureLong(io.opencensus.stats.Measure.MeasureLong) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric)

Example 7 with HistogramMetric

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

the class GridMetricManager method remove.

/**
 * Removes metric registry.
 *
 * @param regName Metric registry name.
 * @param removeCfg {@code True} if remove metric configurations.
 */
public void remove(String regName, boolean removeCfg) {
    GridCompoundFuture opsFut = new GridCompoundFuture<>();
    registries.computeIfPresent(regName, (key, mreg) -> {
        notifyListeners(mreg, metricRegRemoveLsnrs, log);
        if (!removeCfg)
            return null;
        DistributedMetaStorage metastorage0 = metastorage;
        if (metastorage0 == null)
            return null;
        try {
            for (Metric m : mreg) {
                if (m instanceof HitRateMetric)
                    opsFut.add(metastorage0.removeAsync(metricName(HITRATE_CFG_PREFIX, m.name())));
                else if (m instanceof HistogramMetric)
                    opsFut.add(metastorage0.removeAsync(metricName(HISTOGRAM_CFG_PREFIX, m.name())));
            }
        } catch (IgniteCheckedException e) {
            throw new IgniteException(e);
        }
        return null;
    });
    try {
        opsFut.markInitialized();
        opsFut.get();
    } catch (NodeStoppingException ignored) {
    // No-op.
    } catch (IgniteCheckedException e) {
        log.error("Failed to remove metrics configuration.", e);
    }
}
Also used : DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteException(org.apache.ignite.IgniteException) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) Metric(org.apache.ignite.spi.metric.Metric) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture)

Example 8 with HistogramMetric

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

the class IgniteDataStorageMetricsSelfTest method testCheckpointMetrics.

/**
 * @throws Exception if failed.
 */
@Test
public void testCheckpointMetrics() throws Exception {
    Pattern cpPtrn = Pattern.compile("^Checkpoint started .*" + "checkpointBeforeLockTime=(\\d+)ms, " + "checkpointLockWait=(\\d+)ms, " + "checkpointListenersExecuteTime=(\\d+)ms, " + "checkpointLockHoldTime=(\\d+)ms, " + "walCpRecordFsyncDuration=(\\d+)ms, " + "writeCheckpointEntryDuration=(\\d+)ms, " + "splitAndSortCpPagesDuration=(\\d+)ms");
    AtomicLong expLastCpBeforeLockDuration = new AtomicLong();
    AtomicLong expLastCpLockWaitDuration = new AtomicLong();
    AtomicLong expLastCpListenersExecuteDuration = new AtomicLong();
    AtomicLong expLastCpLockHoldDuration = new AtomicLong();
    AtomicLong expLastCpWalRecordFsyncDuration = new AtomicLong();
    AtomicLong expLastCpWriteEntryDuration = new AtomicLong();
    AtomicLong expLastCpSplitAndSortPagesDuration = new AtomicLong();
    AtomicInteger cpCnt = new AtomicInteger();
    listeningLog.registerListener(s -> {
        Matcher matcher = cpPtrn.matcher(s);
        if (!matcher.find())
            return;
        expLastCpBeforeLockDuration.set(Long.parseLong(matcher.group(1)));
        expLastCpLockWaitDuration.set(Long.parseLong(matcher.group(2)));
        expLastCpListenersExecuteDuration.set(Long.parseLong(matcher.group(3)));
        expLastCpLockHoldDuration.set(Long.parseLong(matcher.group(4)));
        expLastCpWalRecordFsyncDuration.set(Long.parseLong(matcher.group(5)));
        expLastCpWriteEntryDuration.set(Long.parseLong(matcher.group(6)));
        expLastCpSplitAndSortPagesDuration.set(Long.parseLong(matcher.group(7)));
        cpCnt.incrementAndGet();
    });
    IgniteEx node = startGrid(0);
    node.cluster().state(ACTIVE);
    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) node.context().cache().context().database();
    db.checkpointReadLock();
    try {
        waitForCondition(() -> cpCnt.get() > 0, getTestTimeout());
        MetricRegistry mreg = node.context().metric().registry(DATASTORAGE_METRIC_PREFIX);
        AtomicLongMetric lastCpBeforeLockDuration = mreg.findMetric("LastCheckpointBeforeLockDuration");
        AtomicLongMetric lastCpLockWaitDuration = mreg.findMetric("LastCheckpointLockWaitDuration");
        AtomicLongMetric lastCpListenersExecuteDuration = mreg.findMetric("LastCheckpointListenersExecuteDuration");
        AtomicLongMetric lastCpLockHoldDuration = mreg.findMetric("LastCheckpointLockHoldDuration");
        AtomicLongMetric lastCpWalRecordFsyncDuration = mreg.findMetric("LastCheckpointWalRecordFsyncDuration");
        AtomicLongMetric lastCpWriteEntryDuration = mreg.findMetric("LastCheckpointWriteEntryDuration");
        AtomicLongMetric lastCpSplitAndSortPagesDuration = mreg.findMetric("LastCheckpointSplitAndSortPagesDuration");
        HistogramMetric cpBeforeLockHistogram = mreg.findMetric("CheckpointBeforeLockHistogram");
        HistogramMetric cpLockWaitHistogram = mreg.findMetric("CheckpointLockWaitHistogram");
        HistogramMetric cpListenersExecuteHistogram = mreg.findMetric("CheckpointListenersExecuteHistogram");
        HistogramMetric cpMarkHistogram = mreg.findMetric("CheckpointMarkHistogram");
        HistogramMetric cpLockHoldHistogram = mreg.findMetric("CheckpointLockHoldHistogram");
        HistogramMetric cpPagesWriteHistogram = mreg.findMetric("CheckpointPagesWriteHistogram");
        HistogramMetric cpFsyncHistogram = mreg.findMetric("CheckpointFsyncHistogram");
        HistogramMetric cpWalRecordFsyncHistogram = mreg.findMetric("CheckpointWalRecordFsyncHistogram");
        HistogramMetric cpWriteEntryHistogram = mreg.findMetric("CheckpointWriteEntryHistogram");
        HistogramMetric cpSplitAndSortPagesHistogram = mreg.findMetric("CheckpointSplitAndSortPagesHistogram");
        HistogramMetric cpHistogram = mreg.findMetric("CheckpointHistogram");
        waitForCondition(() -> cpCnt.get() == Arrays.stream(cpHistogram.value()).sum(), getTestTimeout());
        assertEquals(cpCnt.get(), Arrays.stream(cpBeforeLockHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpLockWaitHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpListenersExecuteHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpMarkHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpLockHoldHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpPagesWriteHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpFsyncHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpWalRecordFsyncHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpWriteEntryHistogram.value()).sum());
        assertEquals(cpCnt.get(), Arrays.stream(cpSplitAndSortPagesHistogram.value()).sum());
        assertEquals(expLastCpBeforeLockDuration.get(), lastCpBeforeLockDuration.value());
        assertEquals(expLastCpLockWaitDuration.get(), lastCpLockWaitDuration.value());
        assertEquals(expLastCpListenersExecuteDuration.get(), lastCpListenersExecuteDuration.value());
        assertEquals(expLastCpLockHoldDuration.get(), lastCpLockHoldDuration.value());
        assertEquals(expLastCpWalRecordFsyncDuration.get(), lastCpWalRecordFsyncDuration.value());
        assertEquals(expLastCpWriteEntryDuration.get(), lastCpWriteEntryDuration.value());
        assertEquals(expLastCpSplitAndSortPagesDuration.get(), lastCpSplitAndSortPagesDuration.value());
    } finally {
        db.checkpointReadUnlock();
    }
}
Also used : Pattern(java.util.regex.Pattern) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Matcher(java.util.regex.Matcher) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with HistogramMetric

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

the class MetricsConfigurationTest method testConfigurationSeveralNodes.

/**
 * Tests metric configuration applied on all nodes.
 */
@Test
public void testConfigurationSeveralNodes() throws Exception {
    try (IgniteEx g0 = startGrid(0);
        IgniteEx g1 = startGrid(1)) {
        assertNotEquals(BOUNDS.length, g0.context().metric().registry(TX_METRICS).<HistogramMetric>findMetric(METRIC_SYSTEM_TIME_HISTOGRAM).bounds().length);
        assertNotEquals(BOUNDS.length, g1.context().metric().registry(TX_METRICS).<HistogramMetric>findMetric(METRIC_SYSTEM_TIME_HISTOGRAM).bounds().length);
        metricsBean(g0).configureHistogramMetric(metricName(TX_METRICS, METRIC_SYSTEM_TIME_HISTOGRAM), BOUNDS);
        assertArrayEquals(BOUNDS, g0.context().metric().registry(TX_METRICS).<HistogramMetric>findMetric(METRIC_SYSTEM_TIME_HISTOGRAM).bounds());
        assertArrayEquals(BOUNDS, g1.context().metric().registry(TX_METRICS).<HistogramMetric>findMetric(METRIC_SYSTEM_TIME_HISTOGRAM).bounds());
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 10 with HistogramMetric

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

the class MetricsConfigurationTest method testConfigRemovedOnCacheGroupRemove.

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

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