Search in sources :

Example 21 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project graylog2-server by Graylog2.

the class KafkaJournalTest method segmentCommittedCleanup.

@Test
public void segmentCommittedCleanup() throws Exception {
    final Size segmentSize = Size.kilobytes(1L);
    final KafkaJournal journal = new KafkaJournal(journalDirectory, scheduler, segmentSize, Duration.standardHours(1), // never clean by size in this test
    Size.petabytes(1L), Duration.standardDays(1), 1_000_000, Duration.standardMinutes(1), 100, new MetricRegistry(), serverStatus);
    final File messageJournalDir = new File(journalDirectory, "messagejournal-0");
    assertTrue(messageJournalDir.exists());
    final int bulkSize = createBulkChunks(journal, segmentSize, 3);
    // make sure everything is on disk
    journal.flushDirtyLogs();
    assertEquals(countSegmentsInDir(messageJournalDir), 3);
    // we haven't committed any offsets, this should not touch anything.
    final int cleanedLogs = journal.cleanupLogs();
    assertEquals(cleanedLogs, 0);
    final int numberOfSegments = countSegmentsInDir(messageJournalDir);
    assertEquals(numberOfSegments, 3);
    // mark first half of first segment committed, should not clean anything
    journal.markJournalOffsetCommitted(bulkSize / 2);
    assertEquals("should not touch segments", journal.cleanupLogs(), 0);
    assertEquals(countSegmentsInDir(messageJournalDir), 3);
    journal.markJournalOffsetCommitted(bulkSize + 1);
    assertEquals("first segment should've been purged", journal.cleanupLogs(), 1);
    assertEquals(countSegmentsInDir(messageJournalDir), 2);
    journal.markJournalOffsetCommitted(bulkSize * 4);
    assertEquals("only purge one segment, not the active one", journal.cleanupLogs(), 1);
    assertEquals(countSegmentsInDir(messageJournalDir), 1);
}
Also used : Size(com.github.joschi.jadconfig.util.Size) MetricRegistry(com.codahale.metrics.MetricRegistry) File(java.io.File) Test(org.junit.Test)

Example 22 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project alluxio by Alluxio.

the class AlluxioMasterRestServiceHandler method getMetricsInternal.

private Map<String, Long> getMetricsInternal() {
    MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY;
    // Get all counters.
    Map<String, Counter> counters = metricRegistry.getCounters();
    // Only the gauge for pinned files is retrieved here, other gauges are statistics of
    // free/used
    // spaces, those statistics can be gotten via other REST apis.
    String filesPinnedProperty = MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.FILES_PINNED);
    @SuppressWarnings("unchecked") Gauge<Integer> filesPinned = (Gauge<Integer>) MetricsSystem.METRIC_REGISTRY.getGauges().get(filesPinnedProperty);
    // Get values of the counters and gauges and put them into a metrics map.
    SortedMap<String, Long> metrics = new TreeMap<>();
    for (Map.Entry<String, Counter> counter : counters.entrySet()) {
        metrics.put(counter.getKey(), counter.getValue().getCount());
    }
    metrics.put(filesPinnedProperty, filesPinned.getValue().longValue());
    return metrics;
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) TreeMap(java.util.TreeMap) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 23 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method getMetricRegistry_delegates_to_metricsCollector.

@Test
public void getMetricRegistry_delegates_to_metricsCollector() {
    // given
    MetricRegistry mrMock = mock(MetricRegistry.class);
    doReturn(mrMock).when(cmcMock).getMetricRegistry();
    // when
    MetricRegistry result = listener.getMetricRegistry();
    // then
    assertThat(result).isSameAs(mrMock);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 24 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project opennms by OpenNMS.

the class StressCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    // Create the client
    final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.getClient(EchoRpcModule.INSTANCE);
    // Create metrics to capture the results
    final MetricRegistry metrics = new MetricRegistry();
    final Histogram responseTimes = metrics.histogram("response-times");
    final Counter successes = metrics.counter("successes");
    final Counter failures = metrics.counter("failures");
    // Build and issue the requests
    System.out.printf("Executing %d requests.\n", count);
    final String message = Strings.repeat("*", messageSize);
    final CountDownLatch doneSignal = new CountDownLatch(count);
    long beforeExec = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        client.execute(buildRequest(message)).whenComplete((r, e) -> {
            if (e != null) {
                failures.inc();
            } else {
                responseTimes.update(System.currentTimeMillis() - r.getId());
                successes.inc();
            }
            doneSignal.countDown();
        });
    }
    long afterExec = System.currentTimeMillis();
    // Wait for the responses...
    System.out.printf("Waiting for responses.\n");
    while (true) {
        try {
            if (doneSignal.await(1, TimeUnit.SECONDS)) {
                // Done!
                System.out.printf("\nDone!\n");
                break;
            }
        } catch (InterruptedException e) {
            System.out.println("\nInterrupted!");
            break;
        }
        System.out.print(".");
        System.out.flush();
    }
    long afterResponse = System.currentTimeMillis();
    System.out.println();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.MILLISECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.report();
    reporter.close();
    System.out.printf("Total miliseconds elapsed: %d\n", afterResponse - beforeExec);
    System.out.printf("Miliseconds spent generating requests: %d\n", afterExec - beforeExec);
    System.out.printf("Miliseconds spent waiting for responses: %d\n", afterResponse - afterExec);
    return null;
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) MetricRegistry(com.codahale.metrics.MetricRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 25 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project riposte by Nike-Inc.

the class ReporterFactoryInstanceTest method test.

@Test
public void test() {
    MetricRegistry registry = new MetricRegistry();
    Reporter r = new DefaultConsoleReporterFactory().getReporter(registry);
    assertNotNull(r);
    r = new DefaultJMXReporterFactory().getReporter(registry);
    assertNotNull(r);
    r = new DefaultSLF4jReporterFactory().getReporter(registry);
    assertNotNull(r);
    r = new DefaultGraphiteReporterFactory("test", "fakeurl.com", 4242).getReporter(registry);
    assertNotNull(r);
    r = new RiposteGraphiteReporterFactory("test", "fakeurl.com", 4242).getReporter(registry);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Reporter(com.codahale.metrics.Reporter) Test(org.junit.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)505 Test (org.junit.Test)177 Before (org.junit.Before)61 Test (org.junit.jupiter.api.Test)45 VerifiableProperties (com.github.ambry.config.VerifiableProperties)42 ArrayList (java.util.ArrayList)33 Counter (com.codahale.metrics.Counter)30 File (java.io.File)29 Properties (java.util.Properties)28 List (java.util.List)23 Metric (com.codahale.metrics.Metric)22 Map (java.util.Map)22 IOException (java.io.IOException)21 HashMap (java.util.HashMap)20 Size (com.github.joschi.jadconfig.util.Size)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 TimeUnit (java.util.concurrent.TimeUnit)17 Timer (com.codahale.metrics.Timer)15 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)15