use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class UserQueriesTestBase method longMetricValue.
/**
* Finds LongMetric from sql user queries registry by specified metric name and returns it's value.
*
* @param gridIdx index of a grid which metric value to find.
* @param metricName short name of the metric from the "sql memory" metric registry.
*/
protected long longMetricValue(int gridIdx, String metricName) {
MetricRegistry sqlMemReg = grid(gridIdx).context().metric().registry(SQL_USER_QUERIES_REG_NAME);
Metric metric = sqlMemReg.findMetric(metricName);
Assert.assertNotNull("Didn't find metric " + metricName, metric);
Assert.assertTrue("Expected long metric, but got " + metric.getClass(), metric instanceof LongMetric);
return ((LongMetric) metric).value();
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class GridJobMetricsSelfTest method testGridJobWaitingRejectedMetrics.
/**
* Test correct calculation of rejected and waiting metrics of the {@link GridJobProcessor}.
*/
@Test
public void testGridJobWaitingRejectedMetrics() throws Exception {
latch = new CountDownLatch(1);
GridTestCollision collisioinSpi = new GridTestCollision();
IgniteConfiguration cfg = getConfiguration().setCollisionSpi(collisioinSpi);
try (IgniteEx g = startGrid(cfg)) {
MetricRegistry mreg = g.context().metric().registry(JOBS_METRICS);
LongMetric started = mreg.findMetric(STARTED);
LongMetric active = mreg.findMetric(ACTIVE);
LongMetric waiting = mreg.findMetric(WAITING);
LongMetric canceled = mreg.findMetric(CANCELED);
LongMetric rejected = mreg.findMetric(REJECTED);
LongMetric finished = mreg.findMetric(FINISHED);
LongMetric totalExecutionTime = mreg.findMetric(EXECUTION_TIME);
LongMetric totalWaitingTime = mreg.findMetric(WAITING_TIME);
assertNotNull(started);
assertNotNull(active);
assertNotNull(waiting);
assertNotNull(canceled);
assertNotNull(rejected);
assertNotNull(finished);
assertNotNull(totalExecutionTime);
assertNotNull(totalWaitingTime);
assertEquals(0, started.value());
assertEquals(0, active.value());
assertEquals(0, waiting.value());
assertEquals(0, canceled.value());
assertEquals(0, rejected.value());
assertEquals(0, finished.value());
assertEquals(0, totalExecutionTime.value());
assertEquals(0, totalWaitingTime.value());
SimplestTask task1 = new SimplestTask();
SimplestTask task2 = new SimplestTask();
SimplestTask task3 = new SimplestTask();
task1.block = true;
task2.block = true;
task3.block = true;
// Task will become "waiting", because of CollisionSpi implementation.
ComputeTaskFuture<?> fut1 = g.compute().executeAsync(task1, 1);
ComputeTaskFuture<?> fut2 = g.compute().executeAsync(task2, 1);
ComputeTaskFuture<?> fut3 = g.compute().executeAsync(task3, 1);
assertEquals(0, started.value());
assertEquals(0, active.value());
assertEquals(3, waiting.value());
assertEquals(0, canceled.value());
assertEquals(0, rejected.value());
assertEquals(0, finished.value());
// Activating 2 of 3 jobs. Rejecting 1 of them.
Iterator<CollisionJobContext> iter = collisioinSpi.jobs.values().iterator();
iter.next().cancel();
assertEquals(1, rejected.value());
// Sleeping to make sure totalWaitingTime will become more the zero.
Thread.sleep(100);
iter.next().activate();
iter.next().activate();
boolean res = waitForCondition(() -> active.value() > 0, TIMEOUT);
assertTrue(res);
assertTrue("Waiting time should be greater then zero.", totalWaitingTime.value() > 0);
// Sleeping to make sure totalExecutionTime will become more the zero.
Thread.sleep(100);
latch.countDown();
res = waitForCondition(() -> fut1.isDone() && fut2.isDone() && fut3.isDone(), TIMEOUT);
assertTrue(res);
res = waitForCondition(() -> finished.value() == 3, TIMEOUT);
assertTrue(res);
assertTrue("Execution time should be greater then zero.", totalExecutionTime.value() > 0);
}
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class CacheGroupMetricsWithIndexTest method testIndexRebuildCountPartitionsLeft.
/**
* Test number of partitions need to finished indexes rebuilding.
*/
@Test
public void testIndexRebuildCountPartitionsLeft() throws Exception {
pds = true;
Ignite ignite = startGrid(0);
ignite.cluster().active(true);
IgniteCache<Object, Object> cache1 = ignite.cache(CACHE_NAME);
for (int i = 0; i < 100_000; i++) {
Long id = (long) i;
BinaryObjectBuilder o = ignite.binary().builder(OBJECT_NAME).setField(KEY_NAME, id).setField(COLUMN1_NAME, i / 2).setField(COLUMN2_NAME, "str" + Integer.toHexString(i));
cache1.put(id, o.build());
}
ignite.cluster().active(false);
File dir = U.resolveWorkDirectory(U.defaultWorkDirectory(), DFLT_STORE_DIR, false);
IOFileFilter filter = FileFilterUtils.nameFileFilter("index.bin");
Collection<File> idxBinFiles = FileUtils.listFiles(dir, filter, TrueFileFilter.TRUE);
for (File indexBin : idxBinFiles) U.delete(indexBin);
ignite.cluster().active(true);
MetricRegistry metrics = cacheGroupMetrics(0, GROUP_NAME).get2();
LongMetric idxBuildCntPartitionsLeft = metrics.findMetric("IndexBuildCountPartitionsLeft");
assertTrue("Timeout wait start rebuild index", waitForCondition(() -> idxBuildCntPartitionsLeft.value() > 0, 30_000));
assertTrue("Timeout wait finished rebuild index", GridTestUtils.waitForCondition(() -> idxBuildCntPartitionsLeft.value() == 0, 30_000));
}
use of org.apache.ignite.spi.metric.LongMetric 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.LongMetric in project ignite by apache.
the class TcpDiscoverySpiMBeanTest method testMBean.
/**
* Tests TcpDiscoverySpiMBean#getCurrentTopologyVersion() and TcpDiscoverySpiMBean#dumpRingStructure().
*
* @throws Exception if fails.
*/
@Test
public void testMBean() throws Exception {
int cnt = 3;
int cliIdx = cnt - 1;
startGrids(cnt - 1);
startClientGrid(cliIdx);
ClusterNode crd = U.oldest(grid(0).context().discovery().aliveServerNodes(), null);
assertNotNull(crd);
try {
for (int i = 0; i < cnt; i++) {
IgniteEx grid = grid(i);
MetricRegistry discoReg = grid.context().metric().registry(DISCO_METRICS);
TcpDiscoverySpiMBean bean = getMxBean(grid.context().igniteInstanceName(), "SPIs", TcpDiscoverySpi.class, TcpDiscoverySpiMBean.class);
assertNotNull(bean);
assertEquals(grid.cluster().topologyVersion(), bean.getCurrentTopologyVersion());
assertEquals(grid.cluster().topologyVersion(), discoReg.<LongMetric>findMetric("CurrentTopologyVersion").value());
if (i != cliIdx) {
assertEquals(crd.id(), bean.getCoordinator());
assertEquals(crd.id(), discoReg.<ObjectMetric<UUID>>findMetric("Coordinator").value());
} else {
assertNull(bean.getCoordinator());
assertNull(discoReg.findMetric("Coordinator"));
}
if (grid.localNode().id().equals(bean.getCoordinator())) {
assertTrue(bean.getCoordinatorSinceTimestamp() > 0);
assertTrue(discoReg.<LongMetric>findMetric("CoordinatorSince").value() > 0);
} else {
assertEquals(0, bean.getCoordinatorSinceTimestamp());
if (i == cliIdx)
assertNull(discoReg.findMetric("CoordinatorSince"));
else
assertEquals(0L, discoReg.<LongMetric>findMetric("CoordinatorSince").value());
}
// `getNodesJoined` returns count of joined nodes since local node startup.
assertEquals((cnt - 1) - i, bean.getNodesJoined());
assertEquals((cnt - 1) - i, discoReg.<IntMetric>findMetric("JoinedNodes").value());
assertEquals(0L, bean.getNodesFailed());
assertEquals(0, discoReg.<IntMetric>findMetric("FailedNodes").value());
assertEquals(0L, bean.getNodesLeft());
assertEquals(0, discoReg.<IntMetric>findMetric("LeftNodes").value());
assertTrue(bean.getTotalReceivedMessages() > 0);
assertTrue(discoReg.<IntMetric>findMetric("TotalReceivedMessages").value() > 0);
assertTrue(bean.getTotalProcessedMessages() > 0);
assertTrue(discoReg.<IntMetric>findMetric("TotalProcessedMessages").value() > 0);
if (i != cliIdx) {
assertTrue(bean.getPendingMessagesRegistered() > 0);
assertTrue(discoReg.<IntMetric>findMetric("PendingMessagesRegistered").value() > 0);
} else {
assertEquals(0, bean.getPendingMessagesRegistered());
assertEquals(0, discoReg.<IntMetric>findMetric("PendingMessagesRegistered").value());
}
assertEquals(0, bean.getPendingMessagesDiscarded());
bean.dumpRingStructure();
assertTrue(strLog.toString().contains("TcpDiscoveryNodesRing"));
assertFalse(bean.getProcessedMessages().isEmpty());
assertFalse(bean.getReceivedMessages().isEmpty());
assertTrue(bean.getMaxMessageProcessingTime() >= 0);
assertEquals(i == cliIdx, bean.isClientMode());
}
stopGrid(0);
crd = U.oldest(grid(1).context().discovery().aliveServerNodes(), null);
for (int i = 1; i < cnt; i++) {
IgniteEx grid = grid(i);
MetricRegistry discoReg = grid.context().metric().registry(DISCO_METRICS);
TcpDiscoverySpiMBean bean = getMxBean(grid.context().igniteInstanceName(), "SPIs", TcpDiscoverySpi.class, TcpDiscoverySpiMBean.class);
assertNotNull(bean);
assertEquals(grid.cluster().topologyVersion(), bean.getCurrentTopologyVersion());
assertEquals(grid.cluster().topologyVersion(), discoReg.<LongMetric>findMetric("CurrentTopologyVersion").value());
if (i != cliIdx) {
assertEquals(crd.id(), bean.getCoordinator());
assertEquals(crd.id(), discoReg.<ObjectMetric<UUID>>findMetric("Coordinator").value());
}
if (grid.localNode().id().equals(crd.id())) {
assertTrue(bean.getCoordinatorSinceTimestamp() > 0);
assertTrue(discoReg.<LongMetric>findMetric("CoordinatorSince").value() > 0);
}
assertTrue(waitForCondition(() -> bean.getNodesLeft() == 1 && discoReg.<IntMetric>findMetric("LeftNodes").value() == 1, getTestTimeout()));
}
} finally {
stopAllGrids();
}
}
Aggregations