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();
}
}
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);
}
}
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();
}
}
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());
}
}
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));
});
}
Aggregations