Search in sources :

Example 6 with RatisMetricRegistry

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());
}
Also used : RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry) MetricRegistryInfo(org.apache.ratis.metrics.MetricRegistryInfo) Gauge(com.codahale.metrics.Gauge)

Example 7 with RatisMetricRegistry

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);
}
Also used : RatisMetrics(org.apache.ratis.metrics.RatisMetrics) RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry)

Example 8 with RatisMetricRegistry

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));
}
Also used : Timer(com.codahale.metrics.Timer) RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry) ObjectName(javax.management.ObjectName)

Example 9 with RatisMetricRegistry

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());
}
Also used : Timer(com.codahale.metrics.Timer) RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry) ObjectName(javax.management.ObjectName)

Example 10 with RatisMetricRegistry

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);
}
Also used : RatisMetricRegistry(org.apache.ratis.metrics.RatisMetricRegistry) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Aggregations

RatisMetricRegistry (org.apache.ratis.metrics.RatisMetricRegistry)13 Test (org.junit.Test)5 Timer (com.codahale.metrics.Timer)4 IOException (java.io.IOException)4 List (java.util.List)4 Level (org.apache.log4j.Level)4 RaftProperties (org.apache.ratis.conf.RaftProperties)4 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)4 RaftServerConfigKeys (org.apache.ratis.server.RaftServerConfigKeys)4 Log4jUtils (org.apache.ratis.util.Log4jUtils)4 Gauge (com.codahale.metrics.Gauge)3 TimeUnit (java.util.concurrent.TimeUnit)3 RaftServer (org.apache.ratis.server.RaftServer)3 SimpleStateMachine4Testing (org.apache.ratis.statemachine.SimpleStateMachine4Testing)3 StateMachine (org.apache.ratis.statemachine.StateMachine)3 JavaUtils (org.apache.ratis.util.JavaUtils)3 Assert (org.junit.Assert)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 SortedMap (java.util.SortedMap)2