use of com.codahale.metrics.MetricRegistry in project vertx-examples by vert-x3.
the class PrometheusMetricsVerticle method start.
@Override
public void start() throws Exception {
MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate("exported");
CollectorRegistry.defaultRegistry.register(new DropwizardExports(metricRegistry));
// Bind metrics handler to /metrics
Router router = Router.router(vertx);
router.get("/metrics").handler(new MetricsHandler());
// Start httpserver on localhost:8080
vertx.createHttpServer().requestHandler(router::accept).listen(8080);
// Increase counter every second
vertx.setPeriodic(1_000L, e -> metricRegistry.counter("testCounter").inc());
}
use of com.codahale.metrics.MetricRegistry in project cruise-control by linkedin.
the class LoadMonitorTaskRunnerTest method testSimpleFetch.
@Test
public void testSimpleFetch() throws InterruptedException {
KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties());
Metadata metadata = new Metadata(10, 10, false);
MetadataClient metadataClient = new MetadataClient(config, metadata, -1L, TIME);
MockMetricSampleAggregator mockMetricSampleAggregator = new MockMetricSampleAggregator(config, metadata);
List<MetricSampler> samplers = new ArrayList<>();
MetricRegistry dropwizardMetricRegistry = new MetricRegistry();
for (int i = 0; i < NUM_METRIC_FETCHERS; i++) {
samplers.add(new MockSampler(0));
}
MetricFetcherManager fetcherManager = new MetricFetcherManager(config, mockMetricSampleAggregator, metadataClient, METRIC_DEF, TIME, dropwizardMetricRegistry, samplers);
LoadMonitorTaskRunner loadMonitorTaskRunner = new LoadMonitorTaskRunner(config, fetcherManager, mockMetricSampleAggregator, metadataClient, TIME);
while (metadata.fetch().topics().size() < NUM_TOPICS) {
Thread.sleep(10);
metadataClient.refreshMetadata();
}
loadMonitorTaskRunner.start(true);
Set<TopicPartition> partitionsToSample = new HashSet<>();
for (int i = 0; i < NUM_TOPICS; i++) {
for (int j = 0; j < NUM_PARTITIONS; j++) {
partitionsToSample.add(new TopicPartition("topic-" + i, j));
}
}
long startMs = System.currentTimeMillis();
BlockingQueue<PartitionMetricSample> sampleQueue = mockMetricSampleAggregator.metricSampleQueue();
while (!partitionsToSample.isEmpty() && System.currentTimeMillis() < startMs + 10000) {
PartitionMetricSample sample = sampleQueue.poll();
if (sample != null) {
assertTrue("The topic partition should have been sampled and sampled only once.", partitionsToSample.contains(sample.entity().tp()));
partitionsToSample.remove(sample.entity().tp());
}
}
assertTrue("Did not see sample for partitions " + Arrays.toString(partitionsToSample.toArray()), partitionsToSample.isEmpty());
fetcherManager.shutdown();
assertTrue(sampleQueue.isEmpty());
}
use of com.codahale.metrics.MetricRegistry in project cruise-control by linkedin.
the class KafkaCruiseControlServletDataFromTest method test.
@Test
public void test() throws Exception {
AsyncKafkaCruiseControl mockKCC = EasyMock.createMock(AsyncKafkaCruiseControl.class);
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
HttpSession session = EasyMock.createMock(HttpSession.class);
EasyMock.expect(request.getSession()).andReturn(session).anyTimes();
EasyMock.expect(request.getMethod()).andReturn("GET").anyTimes();
EasyMock.expect(request.getRequestURI()).andReturn("/test").anyTimes();
EasyMock.expect(request.getParameterMap()).andReturn(Collections.emptyMap()).anyTimes();
EasyMock.expect(session.getLastAccessedTime()).andReturn(Long.MAX_VALUE);
KafkaCruiseControlState kccState = getState(_numReadyGoals, _totalGoals, _numValidWindows);
OperationFuture<KafkaCruiseControlState> kccStateFuture = new OperationFuture<>("test");
kccStateFuture.complete(kccState);
EasyMock.expect(mockKCC.state()).andReturn(kccStateFuture).anyTimes();
EasyMock.replay(mockKCC, request, response, session);
KafkaCruiseControlServlet servlet = new KafkaCruiseControlServlet(mockKCC, 10, 100, new MetricRegistry());
KafkaCruiseControlServlet.GoalsAndRequirements goalsAndRequirements = servlet.getGoalsAndRequirements(request, response, Collections.emptyList(), _dataFrom, false);
assertEquals(new HashSet<>(goalsAndRequirements.goals()), new HashSet<>(_expectedGoalsToUse));
if (_expectedRequirements != null) {
assertEquals(_expectedRequirements.minRequiredNumWindows(), goalsAndRequirements.requirements().minRequiredNumWindows());
assertEquals(_expectedRequirements.minMonitoredPartitionsPercentage(), goalsAndRequirements.requirements().minMonitoredPartitionsPercentage(), 0.0);
assertEquals(_expectedRequirements.includeAllTopics(), goalsAndRequirements.requirements().includeAllTopics());
} else {
assertNull("The requirement should be null", goalsAndRequirements.requirements());
}
}
use of com.codahale.metrics.MetricRegistry in project cruise-control by linkedin.
the class SessionManagerTest method testCreateAndCloseSession.
@Test
public void testCreateAndCloseSession() {
TestContext context = prepareRequests(true, 1);
SessionManager sessionManager = new SessionManager(1, 1000, context.time(), new MetricRegistry());
sessionManager.getAndCreateSessionIfNotExist(context.request(0), () -> new OperationFuture<>("testCreateSession"), 0);
assertEquals(1, sessionManager.numSessions());
sessionManager.closeSession(context.request(0));
assertEquals(0, sessionManager.numSessions());
}
use of com.codahale.metrics.MetricRegistry in project cruise-control by linkedin.
the class SessionManagerTest method testSessionExpiration.
@Test
public void testSessionExpiration() {
TestContext context = prepareRequests(true, 2);
SessionManager sessionManager = new SessionManager(2, 1000, context.time(), new MetricRegistry());
List<OperationFuture<Integer>> futures = new ArrayList<>();
for (int i = 0; i < 2; i++) {
futures.add(sessionManager.getAndCreateSessionIfNotExist(context.request(i), () -> new OperationFuture<>("testSessionExpiration"), 0));
}
assertEquals(2, sessionManager.numSessions());
// Sleep to 1 ms before expiration.
context.time().sleep(999);
sessionManager.expireOldSessions();
assertEquals(2, sessionManager.numSessions());
for (Future future : futures) {
assertFalse(future.isDone());
assertFalse(future.isCancelled());
}
// Sleep to the exact time to expire
context.time().sleep(1);
sessionManager.expireOldSessions();
assertEquals("All the sessions should have been expired", 0, sessionManager.numSessions());
for (Future future : futures) {
assertTrue(future.isDone());
assertTrue(future.isCancelled());
}
}
Aggregations