use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class RaftBasicTests method getStatemachineGaugeWithName.
private static Gauge getStatemachineGaugeWithName(RaftServer.Division server, String gaugeName) {
MetricRegistryInfo info = new MetricRegistryInfo(server.getMemberId().toString(), RATIS_APPLICATION_NAME_METRICS, RATIS_STATEMACHINE_METRICS, RATIS_STATEMACHINE_METRICS_DESC);
Optional<RatisMetricRegistry> metricRegistry = MetricRegistries.global().get(info);
Assert.assertTrue(metricRegistry.isPresent());
RatisMetricRegistry ratisStateMachineMetricRegistry = metricRegistry.get();
SortedMap<String, Gauge> gaugeMap = ratisStateMachineMetricRegistry.getGauges((s, metric) -> s.contains(gaugeName));
return gaugeMap.get(gaugeMap.firstKey());
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class TestRaftLogMetrics method assertCommitCount.
static void assertCommitCount(RaftServer.Division server, int expectedMsgs) {
final RatisMetricRegistry rlm = ((RatisMetrics) server.getRaftLog().getRaftLogMetrics()).getRegistry();
long stmCount = rlm.counter(STATE_MACHINE_LOG_ENTRY_COUNT).getCount();
Assert.assertEquals(expectedMsgs, stmCount);
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class TestRaftLogMetrics method assertRaftLogWritePathMetrics.
static void assertRaftLogWritePathMetrics(RaftServer.Division server) throws Exception {
final String syncTimeMetric = RaftStorageTestUtils.getRaftLogFullMetric(server.getMemberId().toString(), RAFT_LOG_SYNC_TIME);
final RatisMetricRegistry ratisMetricRegistry = RaftLogMetricsBase.getLogWorkerMetricRegistry(server.getMemberId());
// Test sync count
Timer tm = (Timer) ratisMetricRegistry.get(RAFT_LOG_SYNC_TIME);
Assert.assertNotNull(tm);
final MetricsStateMachine stateMachine = MetricsStateMachine.get(server);
final int expectedFlush = stateMachine.getFlushCount();
// Ideally, flushCount should be same as syncCount.
Assert.assertEquals(expectedFlush, tm.getCount());
Assert.assertTrue(tm.getMeanRate() > 0);
// Test jmx. Just testing one metric's JMX is good enough.
ObjectName oname = new ObjectName(RATIS_APPLICATION_NAME_METRICS, "name", syncTimeMetric);
Assert.assertEquals(expectedFlush, ((Long) ManagementFactory.getPlatformMBeanServer().getAttribute(oname, "Count")).intValue());
long cacheMissCount = ratisMetricRegistry.counter(RAFT_LOG_CACHE_MISS_COUNT).getCount();
Assert.assertEquals(0, cacheMissCount);
long cacheHitsCount = ratisMetricRegistry.counter(RAFT_LOG_CACHE_HIT_COUNT).getCount();
Assert.assertTrue(cacheHitsCount > 0);
Assert.assertTrue(ratisMetricRegistry.counter(RAFT_LOG_FLUSH_COUNT).getCount() > 0);
Assert.assertTrue(ratisMetricRegistry.counter(RAFT_LOG_APPEND_ENTRY_COUNT).getCount() > 0);
Timer appendLatencyTimer = ratisMetricRegistry.timer(RAFT_LOG_APPEND_ENTRY_LATENCY);
Assert.assertTrue(appendLatencyTimer.getMeanRate() > 0);
Timer enqueuedTimer = ratisMetricRegistry.timer(RAFT_LOG_TASK_QUEUE_TIME);
Assert.assertTrue(enqueuedTimer.getMeanRate() > 0);
Timer queueingDelayTimer = ratisMetricRegistry.timer(RAFT_LOG_TASK_ENQUEUE_DELAY);
Assert.assertTrue(queueingDelayTimer.getMeanRate() > 0);
Timer executionTimer = ratisMetricRegistry.timer(String.format(RAFT_LOG_TASK_EXECUTION_TIME, "writelog"));
Assert.assertTrue(executionTimer.getMeanRate() > 0);
Assert.assertNotNull(ratisMetricRegistry.get(RAFT_LOG_DATA_QUEUE_SIZE));
Assert.assertNotNull(ratisMetricRegistry.get(RAFT_LOG_WORKER_QUEUE_SIZE));
Assert.assertNotNull(ratisMetricRegistry.get(RAFT_LOG_SYNC_BATCH_SIZE));
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class TestRaftLogMetrics method assertFlushCount.
static void assertFlushCount(RaftServer.Division server) throws Exception {
final String flushTimeMetric = RaftStorageTestUtils.getLogFlushTimeMetric(server.getMemberId().toString());
final RatisMetricRegistry ratisMetricRegistry = RaftLogMetricsBase.getLogWorkerMetricRegistry(server.getMemberId());
Timer tm = (Timer) ratisMetricRegistry.get(RAFT_LOG_FLUSH_TIME);
Assert.assertNotNull(tm);
final MetricsStateMachine stateMachine = MetricsStateMachine.get(server);
final int expectedFlush = stateMachine.getFlushCount();
JavaUtils.attemptRepeatedly(() -> {
Assert.assertEquals(expectedFlush, tm.getCount());
return null;
}, 50, HUNDRED_MILLIS, "expectedFlush == tm.getCount()", null);
Assert.assertTrue(tm.getMeanRate() > 0);
// Test jmx
ObjectName oname = new ObjectName(RATIS_APPLICATION_NAME_METRICS, "name", flushTimeMetric);
Assert.assertEquals(expectedFlush, ((Long) ManagementFactory.getPlatformMBeanServer().getAttribute(oname, "Count")).intValue());
}
use of org.apache.ratis.metrics.RatisMetricRegistry in project incubator-ratis by apache.
the class TestSegmentedRaftLog method testPurgeLogMetric.
@Test
public void testPurgeLogMetric() throws Exception {
int startTerm = 0;
int endTerm = 5;
int segmentSize = 200;
long endIndexOfClosedSegment = segmentSize * (endTerm - startTerm - 1) - 1;
long expectedIndex = segmentSize * (endTerm - startTerm - 1);
final RatisMetricRegistry metricRegistryForLogWorker = RaftLogMetricsBase.getLogWorkerMetricRegistry(memberId);
purgeAndVerify(startTerm, endTerm, segmentSize, 1, endIndexOfClosedSegment, expectedIndex);
assertTrue(metricRegistryForLogWorker.timer("purgeLog").getCount() > 0);
}
Aggregations