24 | * The remote name of the client is a best effort to provide the name of the 25 | * remote host, i.e if the name is specified at creation time, this name will be 26 | * used otherwise it will be the remote address. 27 | * 28 | * @param remoteAddress the remote address of the client 29 | * @param remoteName the remote name of the client 30 | * @return the socket metric 31 | */ 32 | @Override 33 | public MetricsContext connected(SocketAddress remoteAddress, String remoteName) { 34 | Context vertxContext = Vertx.currentContext(); 35 | MetricsContext metricsContext = MetricsContext.addMetricsContext(vertxContext); 36 | 37 | metricsContext.put(CONNECTED_SOCKET_SAMPLE, 38 | LongTaskTimer.builder(nameConnections).register(registry).start()); 39 | return metricsContext; 40 | } 41 | 42 | /** 43 | * Called when a client has disconnected, which is applicable for TCP 44 | * connections. 45 | * 46 | * @param socketMetric the socket metric 47 | * @param remoteAddress the remote address of the client 48 | */ 49 | @Override 50 | public void disconnected(MetricsContext socketMetric, SocketAddress remoteAddress) { 51 | if (socketMetric != null) { 52 | LongTaskTimer.Sample sample = (LongTaskTimer.Sample) socketMetric.get(CONNECTED_SOCKET_SAMPLE); 53 | if (sample != null) { 54 | sample.stop(); 55 | } 56 | socketMetric.removeMetricsContext(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /runtime/src/main/java/dev/ebullient/micrometer/runtime/config/DatadogConfig.java: -------------------------------------------------------------------------------- 1 | package dev.ebullient.micrometer.runtime.config; 2 | 3 | import java.util.Optional; 4 | 5 | import dev.ebullient.micrometer.runtime.config.MicrometerConfig.CapabilityEnabled; 6 | import io.quarkus.runtime.annotations.ConfigGroup; 7 | import io.quarkus.runtime.annotations.ConfigItem; 8 | 9 | @ConfigGroup 10 | public class DatadogConfig implements CapabilityEnabled { 11 | /** 12 | * Support for export to Datadog 13 | *
14 | * Support for Datadog will be enabled if micrometer
15 | * support is enabled, the DatadogMeterRegistry is on the classpath
16 | * and either this value is true, or this value is unset and
17 | * {@code quarkus.micrometer.registry-enabled-default} is true.
18 | */
19 | @ConfigItem
20 | public Optional
14 | * Support for JMX will be enabled if micrometer
15 | * support is enabled, the JmxMeterRegistry is on the classpath
16 | * and either this value is true, or this value is unset and
17 | * {@code quarkus.micrometer.registry-enabled-default} is true.
18 | */
19 | @ConfigItem
20 | public Optional
19 | * Micrometer metrics support is enabled by default.
20 | */
21 | @ConfigItem(defaultValue = "true")
22 | public boolean enabled;
23 |
24 | /**
25 | * Micrometer MeterRegistry discovery.
26 | *
27 | * Micrometer MeterRegistry implementations discovered on the classpath
28 | * will be enabled automatically by default.
29 | */
30 | @ConfigItem(defaultValue = "true")
31 | public boolean registryEnabledDefault;
32 |
33 | /**
34 | * Micrometer MeterBinder discovery.
35 | *
36 | * Micrometer MeterBinder implementations discovered on the classpath
37 | * will be enabled automatically by default.
38 | */
39 | @ConfigItem(defaultValue = "true")
40 | public boolean binderEnabledDefault;
41 |
42 | /** Build / static runtime config for binders */
43 | public BinderConfig binder;
44 |
45 | /** Build / static runtime config for exporters */
46 | public ExportConfig export;
47 |
48 | /**
49 | * For MeterRegistry configurations with optional 'enabled' attributes,
50 | * determine whether or not the registry is enabled using {@link #registryEnabledDefault}
51 | * as the default value.
52 | */
53 | public boolean checkRegistryEnabledWithDefault(CapabilityEnabled config) {
54 | if (enabled) {
55 | Optional
100 | * Micrometer JVM metrics support is enabled by default.
101 | */
102 | @ConfigItem(defaultValue = "true")
103 | public boolean jvm;
104 |
105 | /**
106 | * Micrometer System metrics support.
107 | *
108 | * Micrometer System metrics support is enabled by default.
109 | */
110 | @ConfigItem(defaultValue = "true")
111 | public boolean system;
112 | }
113 |
114 | /** Build / static runtime config for exporters */
115 | @ConfigGroup
116 | public static class ExportConfig {
117 | public DatadogConfig datadog;
118 | public JmxConfig jmx;
119 | public PrometheusConfig prometheus;
120 | public StackdriverConfig stackdriver;
121 | }
122 |
123 | public static interface CapabilityEnabled {
124 | Optional
16 | * Support for Microprofile metrics will be enabled if micrometer
17 | * support is enabled, and this value is true. You need to also
18 | * include the microprofile api jar to your dependencies:
19 | *
20 | *
14 | * Support for Prometheus will be enabled if micrometer
15 | * support is enabled, the PrometheusMeterRegistry is on the classpath
16 | * and either this value is true, or this value is unset and
17 | * {@code quarkus.micrometer.registry-enabled-default} is true.
18 | */
19 | @ConfigItem
20 | public Optional
14 | * Support for Stackdriver will be enabled if micrometer
15 | * support is enabled, the StackdriverMeterRegistry is on the classpath
16 | * and either this value is true, or this value is unset and
17 | * {@code quarkus.micrometer.registry-enabled-default} is true.
18 | *
19 | * [NOTE]
20 | * ====
21 | * Stackdriver libraries do not yet support running in native mode.
22 | * The Stackdriver MeterRegistry will be automatically disabled
23 | * for native builds.
24 | *
25 | * See https://github.com/grpc/grpc-java/issues/5460
26 | * ====
27 | *
28 | * @asciidoclet
29 | */
30 | @ConfigItem
31 | public Optional
17 | * Support for Vert.x metrics will be enabled if micrometer
18 | * support is enabled, Vert.x MetricsOptions is on the classpath
19 | * and either this value is true, or this value is unset and
20 | * {@code quarkus.micrometer.binder-enabled-default} is true.
21 | */
22 | @ConfigItem
23 | public Optional
12 | *
13 | * [NOTE]
14 | * ====
15 | * Not all the dialects are supported in GraalVM native executables: we currently provide driver extensions for PostgreSQL,
16 | * MariaDB, Microsoft SQL Server and H2.
17 | * ====
18 | *
19 | * @asciidoclet
20 | */
21 | @ConfigRoot(name = "micrometer.export", phase = ConfigPhase.RUN_TIME)
22 | public class ExportConfig {
23 |
24 | // @formatter:off
25 | /**
26 | * Datadog MeterRegistry configuration
27 | *
28 | * A property source for configuration of the Datadog MeterRegistry to push
29 | * metrics using the Datadog API, see https://micrometer.io/docs/registry/datadog.
30 | *
31 | * [cols="1,2", options="header"]
32 | * .Properties
33 | * |===
34 | * | Property=Default
35 | * | Description
36 | *
37 | * | `apiKey=YOUR_KEY`
38 | * | Define the key used to push data using the Datadog API
39 | *
40 | * | `publish=true`
41 | * | By default, gathered metrics will be published to Datadog when the MeterRegistry is enabled.
42 | * Use this attribute to selectively disable publication of metrics in some environments.
43 | *
44 | * | `step=1m`
45 | * | The interval at which metrics are sent to Datadog. The default is 1 minute.
46 | * |===
47 | *
48 | * Other micrometer configuration attributes can also be specified.
49 | *
50 | * @asciidoclet
51 | */
52 | // @formatter:on
53 | @ConfigItem
54 | Map
60 | * A property source for configuration of the JMX MeterRegistry,
61 | * see https://micrometer.io/docs/registry/jmx.
62 | *
63 | * @asciidoclet
64 | */
65 | // @formatter:on
66 | @ConfigItem
67 | Map
73 | * A property source for configuration of the Prometheus MeterRegistry,
74 | * see https://micrometer.io/docs/registry/prometheus
75 | *
76 | * @asciidoclet
77 | */
78 | // @formatter:on
79 | @ConfigItem
80 | Map
86 | * A property source for configuration of the Stackdriver MeterRegistry,
87 | * see https://micrometer.io/docs/registry/stackdriver.
88 | *
89 | * [cols="1,2", options="header"]
90 | * .Properties
91 | * |===
92 | * | Property=Default
93 | * | Description
94 | *
95 | * | `project-id=MY_PROJECT_ID`
96 | * | Define the project id used to push data to Stackdriver Monitoring
97 | *
98 | * | `publish=true`
99 | * | By default, gathered metrics will be published to Datadog when the MeterRegistry is enabled.
100 | * Use this attribute to selectively disable publication of metrics in some environments.
101 | *
102 | * | `step=1m`
103 | * | The interval at which metrics are sent to Stackdriver Monitoring. The default is 1 minute.
104 | * |===
105 | *
106 | * Other micrometer configuration attributes can also be specified.
107 | *
108 | * @asciidoclet
109 | */
110 | // @formatter:on
111 | @ConfigItem
112 | Map
21 | * <dependency>
22 | * <groupId>org.eclipse.microprofile.metrics</groupId>
23 | * <artifactId>microprofile-metrics-api</artifactId>
24 | * </dependency>
25 | *
26 | */
27 | @ConfigItem
28 | public Optional> matchPatterns = Optional.empty();
21 |
22 | /**
23 | * Comma-separated case-sensitive list of regular expressions defining Paths
24 | * that should be ignored / not measured.
25 | */
26 | @ConfigItem
27 | public Optional
> ignorePatterns = Optional.empty();
28 | }
29 |
--------------------------------------------------------------------------------
/runtime/src/main/java/dev/ebullient/micrometer/runtime/export/DatadogMeterRegistryProvider.java:
--------------------------------------------------------------------------------
1 | package dev.ebullient.micrometer.runtime.export;
2 |
3 | import java.util.Map;
4 |
5 | import javax.enterprise.inject.Produces;
6 | import javax.inject.Singleton;
7 |
8 | import org.eclipse.microprofile.config.Config;
9 |
10 | import dev.ebullient.micrometer.runtime.MicrometerRecorder;
11 | import io.micrometer.core.instrument.Clock;
12 | import io.micrometer.datadog.DatadogConfig;
13 | import io.micrometer.datadog.DatadogMeterRegistry;
14 | import io.quarkus.arc.DefaultBean;
15 |
16 | @Singleton
17 | public class DatadogMeterRegistryProvider {
18 | static final String PREFIX = "quarkus.micrometer.export.datadog.";
19 | static final String PUBLISH = "datadog.publish";
20 | static final String ENABLED = "datadog.enabled";
21 |
22 | @Produces
23 | @Singleton
24 | @DefaultBean
25 | public DatadogConfig configure(Config config) {
26 | final Map