Java Code Examples for com.codahale.metrics.MetricRegistry#registerAll()
The following examples show how to use
com.codahale.metrics.MetricRegistry#registerAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StateTransitionMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void testWithCircuitBreakerMetrics() throws Exception { CircuitBreakerConfig config = CircuitBreakerConfig.custom() .waitDurationInOpenState(Duration.ofMillis(150)) .failureRateThreshold(50) .permittedNumberOfCallsInHalfOpenState(3) .slidingWindowSize(10) .build(); CircuitBreaker circuitBreaker = CircuitBreakerRegistry.ofDefaults() .circuitBreaker("test", config); MetricRegistry metricRegistry = new MetricRegistry(); metricRegistry.registerAll(CircuitBreakerMetrics.ofCircuitBreaker(circuitBreaker)); circuitBreakerMetricsUsesFirstStateObjectInstance(circuitBreaker, metricRegistry); }
Example 2
Source File: Poseidon.java From Poseidon with Apache License 2.0 | 6 votes |
private ServletContextHandler getMetricsHandler() { MetricRegistry registry = Metrics.getRegistry(); HealthCheckRegistry healthCheckRegistry = Metrics.getHealthCheckRegistry(); healthCheckRegistry.register("rotation", new Rotation(configuration.getRotationStatusFilePath())); registry.registerAll(new GarbageCollectorMetricSet()); registry.registerAll(new MemoryUsageGaugeSet()); registry.registerAll(new ThreadStatesGaugeSet()); registry.registerAll(new JvmAttributeGaugeSet()); ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setContextPath("/__metrics"); servletContextHandler.setAttribute(MetricsServlet.class.getCanonicalName() + ".registry", registry); servletContextHandler.setAttribute(HealthCheckServlet.class.getCanonicalName() + ".registry", healthCheckRegistry); servletContextHandler.addServlet(new ServletHolder(new AdminServlet()), "/*"); return servletContextHandler; }
Example 3
Source File: CircuitBreakerMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected CircuitBreaker givenMetricRegistry(MetricRegistry metricRegistry) { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker("testName"); metricRegistry .registerAll(CircuitBreakerMetrics.ofCircuitBreakerRegistry(circuitBreakerRegistry)); return circuitBreaker; }
Example 4
Source File: MetricsReportingTask.java From nifi with Apache License 2.0 | 5 votes |
/** * Register all wanted metrics to {@link #metricRegistry}. * <p> * {@inheritDoc} */ @Override protected void init(ReportingInitializationContext config) { metricRegistry = new MetricRegistry(); currentStatusReference = new AtomicReference<>(); metricRegistry.registerAll(new MemoryUsageGaugeSet()); metricRegistry.registerAll(new FlowMetricSet(currentStatusReference)); }
Example 5
Source File: RetryMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected Retry givenMetricRegistry(MetricRegistry metricRegistry) { RetryRegistry retryRegistry = RetryRegistry .of(RetryConfig.custom().waitDuration(Duration.ofMillis(150)).build()); Retry retry = retryRegistry.retry("testName"); metricRegistry.registerAll(RetryMetrics.ofRetryRegistry(retryRegistry)); return retry; }
Example 6
Source File: RetryMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected Retry givenMetricRegistry(String prefix, MetricRegistry metricRegistry) { RetryRegistry retryRegistry = RetryRegistry .of(RetryConfig.custom().waitDuration(Duration.ofMillis(150)).build()); Retry retry = retryRegistry.retry("testName"); metricRegistry.registerAll(RetryMetrics.ofRetryRegistry(prefix, retryRegistry)); return retry; }
Example 7
Source File: RateLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected RateLimiter givenMetricRegistry(MetricRegistry metricRegistry) { RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.ofDefaults(); RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("testLimit"); metricRegistry.registerAll(RateLimiterMetrics.ofRateLimiterRegistry(rateLimiterRegistry)); return rateLimiter; }
Example 8
Source File: RateLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected RateLimiter givenMetricRegistry(String prefix, MetricRegistry metricRegistry) { RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.ofDefaults(); RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("testLimit"); metricRegistry.registerAll( RateLimiterMetrics.ofIterable(prefix, rateLimiterRegistry.getAllRateLimiters())); return rateLimiter; }
Example 9
Source File: TimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected TimeLimiter given(MetricRegistry metricRegistry) { TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); TimeLimiter timeLimiter = timeLimiterRegistry.timeLimiter("testLimit"); metricRegistry.registerAll(TimeLimiterMetrics.ofTimeLimiterRegistry(timeLimiterRegistry)); return timeLimiter; }
Example 10
Source File: TimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected TimeLimiter given(String prefix, MetricRegistry metricRegistry) { TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults(); TimeLimiter timeLimiter = timeLimiterRegistry.timeLimiter("testLimit"); metricRegistry .registerAll(TimeLimiterMetrics.ofTimeLimiterRegistry(prefix, timeLimiterRegistry)); return timeLimiter; }
Example 11
Source File: DetectorMapperCache.java From adaptive-alerting with Apache License 2.0 | 5 votes |
/** * Instantiates a new Detector mapper cache. * * @param metricRegistry Metric registry. */ public DetectorMapperCache(MetricRegistry metricRegistry) { this.cache = CacheBuilder.newBuilder() .recordStats() .expireAfterAccess(120, TimeUnit.MINUTES) // to delete mappings for stale metrics .build(); metricRegistry.registerAll(metricsFor("cache", cache)); }
Example 12
Source File: CircuitBreakerMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected CircuitBreaker givenMetricRegistry(String prefix, MetricRegistry metricRegistry) { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker("testName"); metricRegistry.registerAll( CircuitBreakerMetrics.ofCircuitBreakerRegistry(prefix, circuitBreakerRegistry)); return circuitBreaker; }
Example 13
Source File: BulkheadMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected Bulkhead givenMetricRegistry(String prefix, MetricRegistry metricRegistry) { BulkheadRegistry bulkheadRegistry = BulkheadRegistry.ofDefaults(); Bulkhead bulkhead = bulkheadRegistry.bulkhead("testBulkhead"); metricRegistry .registerAll(BulkheadMetrics.ofIterable(prefix, bulkheadRegistry.getAllBulkheads())); return bulkhead; }
Example 14
Source File: BulkheadMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected Bulkhead givenMetricRegistry(MetricRegistry metricRegistry) { BulkheadRegistry bulkheadRegistry = BulkheadRegistry.ofDefaults(); Bulkhead bulkhead = bulkheadRegistry.bulkhead("testBulkhead"); metricRegistry.registerAll(BulkheadMetrics.ofBulkhead(bulkhead)); return bulkhead; }
Example 15
Source File: MemoryUsageGaugeSetTest.java From eagle with Apache License 2.0 | 5 votes |
@Test public void testJVMMetrics() throws InterruptedException { LOG.info("Starting testJVMMetrics"); final MetricRegistry metrics = new MetricRegistry(); ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); metrics.registerAll(new MemoryUsageGaugeSet()); metrics.register("sample", (Gauge<Double>) () -> 0.1234); reporter.start(1, TimeUnit.SECONDS); reporter.close(); }
Example 16
Source File: StreamWindowBenchmarkTest.java From eagle with Apache License 2.0 | 5 votes |
@Before public void setUp() { final MetricRegistry metrics = new MetricRegistry(); metrics.registerAll(new MemoryUsageGaugeSet()); metrics.registerAll(new GarbageCollectorMetricSet()); metricReporter = ConsoleReporter.forRegistry(metrics) .filter((name, metric) -> name.matches("(.*heap|total).(usage|used)")) // .withLoggingLevel(Slf4jReporter.LoggingLevel.DEBUG) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); metricReporter.start(60, TimeUnit.SECONDS); performanceReport = new TreeMap<>(); }
Example 17
Source File: StreamSortHandlerTest.java From eagle with Apache License 2.0 | 5 votes |
@Before public void setUp() { final MetricRegistry metrics = new MetricRegistry(); metrics.registerAll(new MemoryUsageGaugeSet()); metrics.registerAll(new GarbageCollectorMetricSet()); metricReporter = Slf4jReporter.forRegistry(metrics) .filter((name, metric) -> name.matches("(.*heap|pools.PS.*).usage")) .withLoggingLevel(Slf4jReporter.LoggingLevel.DEBUG) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); metricReporter.start(60, TimeUnit.SECONDS); }
Example 18
Source File: MetricsConsoleAppenderTest.java From lambda-monitoring with Apache License 2.0 | 5 votes |
@Test public void testMetricLogger() { PrintStream original = System.out; try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); System.setOut(new PrintStream(outputStream, true)); MDC.put("AWSRequestId", "AWS-REQUEST-ID"); Logger logger = LoggerFactory.getLogger("TEST-LOGGER"); MetricRegistry registry = new MetricRegistry(); registry.registerAll(new TestMetricSet()); Slf4jReporter reporter = Slf4jReporter.forRegistry(registry) .markWith(MarkerFactory.getMarker("METRIC")) .outputTo(logger) .build(); reporter.report(); assertThat(outputStream.toString(), matchesPattern("^\\[[0-9\\-:\\. ]{23}\\] AWS-REQUEST-ID METRIC TEST-LOGGER type COUNTER name " + TestMetricSet.class.getCanonicalName() + "/testCounter count 0\\n$")); } finally { System.setOut(original); } }
Example 19
Source File: CassandraFactory.java From dropwizard-cassandra with Apache License 2.0 | 4 votes |
/** * Builds a {@link Cluster} instance. * <p/> * The {@link MetricRegistry} will be used to register client metrics, and the {@link * HealthCheckRegistry} to register client health-checks. * * @param metrics the registry to register client metrics. * @param healthChecks the registry to register client health-checks. * @return a fully configured {@link Cluster}. */ public Cluster build(MetricRegistry metrics, HealthCheckRegistry healthChecks) { final Cluster.Builder builder = Cluster.builder(); for (String contactPoint : contactPoints) { builder.addContactPoints(contactPoint); } builder.withPort(port); builder.withCompression(compression); protocolVersion.ifPresent(builder::withProtocolVersion); ssl.map(SSLOptionsFactory::build).ifPresent(builder::withSSL); maxSchemaAgreementWait.map(Duration::toSeconds).map(Long::intValue).ifPresent(builder::withMaxSchemaAgreementWaitSeconds); authProvider.map(AuthProviderFactory::build).ifPresent(builder::withAuthProvider); reconnectionPolicy.map(ReconnectionPolicyFactory::build).ifPresent(builder::withReconnectionPolicy); retryPolicy.map(RetryPolicyFactory::build).ifPresent(builder::withRetryPolicy); loadBalancingPolicy.map(LoadBalancingPolicyFactory::build).ifPresent(builder::withLoadBalancingPolicy); speculativeExecutionPolicy.map(SpeculativeExecutionPolicyFactory::build).ifPresent(builder::withSpeculativeExecutionPolicy); queryOptions.ifPresent(builder::withQueryOptions); socketOptions.ifPresent(builder::withSocketOptions); poolingOptions.map(PoolingOptionsFactory::build).ifPresent(builder::withPoolingOptions); addressTranslator.map(AddressTranslatorFactory::build).ifPresent(builder::withAddressTranslator); if (!metricsEnabled) { builder.withoutMetrics(); } if (!jmxEnabled) { builder.withoutJMXReporting(); } if (!Strings.isNullOrEmpty(clusterName)) { builder.withClusterName(clusterName); } Cluster cluster = builder.build(); LOG.debug("Registering {} Cassandra health check", cluster.getClusterName()); CassandraHealthCheck healthCheck = new CassandraHealthCheck(cluster, validationQuery, healthCheckTimeout); healthChecks.register(name("cassandra", cluster.getClusterName()), healthCheck); if (isMetricsEnabled()) { LOG.debug("Registering {} Cassandra metrics", cluster.getClusterName()); metrics.registerAll(new CassandraMetricSet(cluster)); } return cluster; }
Example 20
Source File: CloudwatchMetricFilterTest.java From lambda-monitoring with Apache License 2.0 | 4 votes |
@Ignore @Test public void testMetricFilters() { List<String> lines; PrintStream original = System.out; try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); System.setOut(new PrintStream(outputStream, true)); Logger logger = LoggerFactory.getLogger("TEST-LOGGER"); logger.info("TEST-MESSAGE"); TestMetricSet metricSet = new TestMetricSet(); MetricRegistry registry = new MetricRegistry(); registry.registerAll(metricSet); metricSet.testCounter.inc(); metricSet.testMeter.mark(1L); metricSet.testHistogram.update(1L); metricSet.testTimer.update(1L, TimeUnit.MINUTES); Slf4jReporter reporter = Slf4jReporter.forRegistry(registry) .markWith(MarkerFactory.getMarker("METRIC")) .outputTo(logger) .build(); reporter.report(); lines = Arrays.asList(outputStream.toString().split("\\n")); } finally { System.setOut(original); } assertNotNull(lines); AWSLogsClient client = new AWSLogsClient(); // TODO: Loop for each kind of metric String metricFilterPattern = String.format(COMPLETE_FILTER_PATTERN_MAP.get("COUNTER"), "test.namespace/testCounter"); TestMetricFilterRequest request = new TestMetricFilterRequest() .withFilterPattern(metricFilterPattern) .withLogEventMessages(lines); TestMetricFilterResult result = client.testMetricFilter(request); MetricFilterMatchRecord matchRecord = result.getMatches().get(0); assertEquals("test.namespace/testCounter", matchRecord.getExtractedValues().get("$name")); assertEquals("1", matchRecord.getExtractedValues().get("$count")); MetricFilterMatchRecord matchRecord2 = result.getMatches().get(1); assertEquals("test.namespace/testGauge", matchRecord2.getExtractedValues().get("$name")); assertEquals("42", matchRecord2.getExtractedValues().get("$value")); }