All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ratpack.dropwizard.metrics.DropwizardMetricsConfig Maven / Gradle / Ivy

Go to download

Provides integration with the Dropwizard Metrics library - https://dropwizard.github.io/metrics/

There is a newer version: 2.0.0-rc-1
Show newest version
/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ratpack.dropwizard.metrics;

import ratpack.dropwizard.metrics.internal.DefaultRequestTimingHandler;
import ratpack.func.Action;

import java.time.Duration;
import java.util.Map;
import java.util.Optional;

import static ratpack.util.Exceptions.uncheck;

/**
 * The configuration object for {@link DropwizardMetricsModule}.
 * 

* Request timing metrics and blocking execution timing metrics are enabled by default. */ public class DropwizardMetricsConfig { public static final Duration DEFAULT_INTERVAL = Duration.ofSeconds(30); private boolean jvmMetrics; private boolean requestTimingMetrics = true; private boolean blockingTimingMetrics = true; private Map requestMetricGroups; private Optional jmx = Optional.empty(); private Optional console = Optional.empty(); private Optional webSocket = Optional.empty(); private Optional csv = Optional.empty(); private Optional slf4j = Optional.empty(); private Optional graphite = Optional.empty(); /** * The state of jvm metrics collection. * * @return True if jvm metrics collection is enabled. False otherwise */ public boolean isJvmMetrics() { return jvmMetrics; } /** * The state of JVM metrics reporting. * @param jvmMetrics True if JVM metrics are to be reported. False otherwise * @return this */ public DropwizardMetricsConfig jvmMetrics(boolean jvmMetrics) { this.jvmMetrics = jvmMetrics; return this; } /** * The state of request timing metrics. * * @return True if request timing metrics is enabled. False otherwise * @since 1.2 */ public boolean isRequestTimingMetrics() { return requestTimingMetrics; } /** * The state of request timing metrics reporting. * @param requestTimingMetrics True if request timing metrics are to be reported. False otherwise * @return this * @since 1.2 */ public DropwizardMetricsConfig requestTimingMetrics(boolean requestTimingMetrics) { this.requestTimingMetrics = requestTimingMetrics; return this; } /** * The state of blocking timing metrics. * * @return True if blocking timing metrics is enabled. False otherwise * @since 1.2 */ public boolean isBlockingTimingMetrics() { return blockingTimingMetrics; } /** * The state of blocking timing metrics reporting. * @param blockingTimingMetrics True if blocking timing metrics are to be reported. False otherwise * @return this * @since 1.2 */ public DropwizardMetricsConfig blockingTimingMetrics(boolean blockingTimingMetrics) { this.blockingTimingMetrics = blockingTimingMetrics; return this; } /** * A map of regular expressions used to group request metrics. *

* The value is a regular expression to test the current request path against for a match. * If matched, the key is the name to use when recording the metric. Please note that request * paths do not start with a / *

* As soon as a match is made against a regular expression no further matches are attempted. *

* Should no matches be made the default metric grouping will be used. * * @return the request metric group expressions * @see DefaultRequestTimingHandler */ public Map getRequestMetricGroups() { return requestMetricGroups; } /** * Configure the request metric groups. * @param requestMetricGroups the request metric groups * @return this */ public DropwizardMetricsConfig requestMetricGroups(Map requestMetricGroups) { this.requestMetricGroups = requestMetricGroups; return this; } /** * Get the settings for the JMX metrics publisher. * @return the jmx publisher settings */ public Optional getJmx() { return jmx; } /** * @see #jmx(ratpack.func.Action) * @return this */ public DropwizardMetricsConfig jmx() { return jmx(Action.noop()); } /** * Configure the JMX metrics publisher. * * @param configure the configuration for the publisher * @return this */ public DropwizardMetricsConfig jmx(Action configure) { try { configure.execute(jmx.orElseGet(() -> { jmx = Optional.of(new JmxConfig()); return jmx.get(); })); return this; } catch (Exception e) { throw uncheck(e); } } /** * Get the settings for the console metrics publisher. * @return the console publisher settings */ public Optional getConsole() { return console; } /** * @see #console(ratpack.func.Action) * @return this */ public DropwizardMetricsConfig console() { return console(Action.noop()); } /** * Configure the console metrics publisher. * * @param configure the configuration for the publisher * @return this */ public DropwizardMetricsConfig console(Action configure) { try { configure.execute(console.orElseGet(() -> { console = Optional.of(new ConsoleConfig()); return console.get(); })); return this; } catch (Exception e) { throw uncheck(e); } } /** * Get the settings for the Slf4j Logger metrics publisher. * @return the slf4j publisher settings */ public Optional getSlf4j() { return slf4j; } /** * @see #slf4j(ratpack.func.Action) * @return this */ public DropwizardMetricsConfig slf4j() { return slf4j(Action.noop()); } /** * Configure the Slf4j logger metrics publisher. * * @param configure the configuration for the publisher * @return this */ public DropwizardMetricsConfig slf4j(Action configure) { try { configure.execute(slf4j.orElseGet(() -> { slf4j = Optional.of(new Slf4jConfig()); return slf4j.get(); })); return this; } catch (Exception e) { throw uncheck(e); } } /** * Get the settings for the websockets metrics broadcaster. * @return the websockets broadcaster settings */ public Optional getWebSocket() { return webSocket; } /** * @see #webSocket(ratpack.func.Action) * @return this */ public DropwizardMetricsConfig webSocket() { return webSocket(Action.noop()); } /** * Configure the websockets metrics broadcaster. * * @param configure the configuration for the broadcaster * @return this */ public DropwizardMetricsConfig webSocket(Action configure) { try { configure.execute(webSocket.orElseGet(() -> { webSocket = Optional.of(new WebsocketConfig()); return webSocket.get(); })); return this; } catch (Exception e) { throw uncheck(e); } } /** * Get the settings for the csv metrics publisher. * @return the csv publisher settings */ public Optional getCsv() { return csv; } /** * Configure the csv metrics publisher. * * @param configure the configuration for the publisher * @return this */ public DropwizardMetricsConfig csv(Action configure) { try { configure.execute(csv.orElseGet(() -> { csv = Optional.of(new CsvConfig()); return csv.get(); })); return this; } catch (Exception e) { throw uncheck(e); } } /** * Get the settings for the Graphite metrics publisher. * @return the Graphite publisher settings */ public Optional getGraphite() { return graphite; } /** * Configure the Graphite metrics publisher. * * @param configure the configuration for the publisher * @return this */ public DropwizardMetricsConfig graphite(Action configure) { try { configure.execute(graphite.orElseGet(() -> { graphite = Optional.of(new GraphiteConfig()); return graphite.get(); })); return this; } catch (Exception e) { throw uncheck(e); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy