This project is an implementation of the Vert.x Metrics Service Provider Interface (SPI). It uses Micrometer for managing metrics and reporting to several backends.
Vert.x core tools monitoring: TCP/HTTP client and servers, DatagramSocket
, EventBus
and pools
User defined metrics through Micrometer
Reporting to any backend supported by Micrometer
Built-in options for InfluxDB, Prometheus and JMX reporting.
Follow the instructions to get InfluxDb up and running.
The modules vertx-micrometer-metrics and micrometer-registry-influx must be present in the classpath.
Maven users should add this to their project POM file:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-micrometer-metrics</artifactId>
<version>3.6.2</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-influx</artifactId>
<version>${micrometer.version}</version>
</dependency>
And Gradle users, to their build file:
compile 'io.vertx:vertx-micrometer-metrics:3.6.2'
compile 'io.micrometer:micrometer-registry-influx:${micrometer.version}'
Vert.x does not enable SPI implementations by default. You must enable metric collection in the Vert.x options.
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"influxDbOptions" : {
"enabled" : true
},
"enabled" : true
}
});
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"influxDbOptions" : {
"enabled" : true,
"uri" : "http://influxdb.example.com:8888",
"db" : "sales-department"
},
"enabled" : true
}
});
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"influxDbOptions" : {
"enabled" : true,
"userName" : "username",
"password" : "password"
},
"enabled" : true
}
});
Follow the instructions to get Prometheus up and running.
The modules vertx-micrometer-metrics and micrometer-registry-prometheus must be present in the classpath. You may also probably need vertx-web, to expose the metrics.
Maven users should add this to their project POM file:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-micrometer-metrics</artifactId>
<version>3.6.2</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>
And Gradle users, to their build file:
compile 'io.vertx:vertx-micrometer-metrics:3.6.2'
compile 'io.micrometer:micrometer-registry-prometheus:${micrometer.version}'
Vert.x does not enable SPI implementations by default. You must enable metric collection in the Vert.x options
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"prometheusOptions" : {
"enabled" : true
},
"enabled" : true
}
});
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"prometheusOptions" : {
"enabled" : true,
"startEmbeddedServer" : true,
"embeddedServerOptions" : {
"port" : 8080
},
"embeddedServerEndpoint" : "/metrics/vertx"
},
"enabled" : true
}
});
If the embedded server endpoint is not specified, it defaults to /metrics.
var Vertx = require("vertx-js/vertx");
var Router = require("vertx-web-js/router");
var PrometheusScrapingHandler = require("vertx-micrometer-metrics-js/prometheus_scraping_handler");
var vertx = Vertx.vertx({
"metricsOptions" : {
"prometheusOptions" : {
"enabled" : true
},
"enabled" : true
}
});
// Later on, creating a router
var router = Router.router(vertx);
router.route("/metrics").handler(PrometheusScrapingHandler.create());
vertx.createHttpServer().requestHandler(router.handle).listen(8080);
The modules vertx-micrometer-metrics and micrometer-registry-jmx must be present in the classpath.
Maven users should add this to their project POM file:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-micrometer-metrics</artifactId>
<version>3.6.2</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-jmx</artifactId>
<version>${micrometer.version}</version>
</dependency>
And Gradle users, to their build file:
compile 'io.vertx:vertx-micrometer-metrics:3.6.2'
compile 'io.micrometer:micrometer-registry-jmx:${micrometer.version}'
Vert.x does not enable SPI implementations by default. You must enable metric collection in the Vert.x options
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"jmxMetricsOptions" : {
"enabled" : true
},
"enabled" : true
}
});
In Micrometer, step
refers to the reporting period, in seconds. domain
is the JMX domain under which
MBeans are registered.
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"jmxMetricsOptions" : {
"enabled" : true,
"step" : 5,
"domain" : "my.metrics.domain"
},
"enabled" : true
}
});
Even if not all backends supported by Micrometer are implemented in Vert.x options, it is still possible to create any Micrometer registry and pass it to Vert.x.
The list of available backends includes Graphite, Ganglia, Atlas, etc. It also enables the Micrometer Composite Registry in order to report the same metrics to multiple backends.
In this example, metrics are reported both for JMX and Graphite:
var Vertx = require("vertx-js/vertx");
var myRegistry = new (Java.type("io.micrometer.core.instrument.composite.CompositeMeterRegistry"))();
myRegistry.add(new (Java.type("io.micrometer.jmx.JmxMeterRegistry"))(function (s) {
null;
}, Java.type("io.micrometer.core.instrument.Clock").SYSTEM));
myRegistry.add(new (Java.type("io.micrometer.graphite.GraphiteMeterRegistry"))(function (s) {
null;
}, Java.type("io.micrometer.core.instrument.Clock").SYSTEM));
var vertx = Vertx.vertx({
"metricsOptions" : {
"micrometerRegistry" : myRegistry,
"enabled" : true
}
});
Please refer to MicrometerMetricsOptions
for an exhaustive list of options.
By default, when using the Prometheus registry, histogram-kind metrics will not contain averages or quantile stats.
Averages don’t come out of the box but they are typically computed at query time,
with promql
. Example, for HTTP client response time average during the last 5 minutes:
rate(vertx_http_client_responseTime_seconds_sum[5m])
/
rate(vertx_http_client_responseTime_seconds_count[5m])
To compute quantiles, there are two options available. The first is to activate quantile stats globally
and make them usable for Prometheus function histogram_quantile
:
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"prometheusOptions" : {
"enabled" : true,
"publishQuantiles" : true
},
"enabled" : true
}
});
And then, for example the promql
query for the HTTP client response time, 99th percentile over the last 5 minutes:
histogram_quantile(0.99, sum(rate(vertx_http_client_responseTime_seconds_bucket[5m])) by (le))
The advantage of this option is that it can be leveraged in promql
, aggregable across dimensions.
The downside is that it creates a lot of timeseries for stats under the hood.
The second option is to create limited stats, non-aggregable across dimensions. It requires to access directly the Micrometer / Prometheus registry:
var registry = Java.type("io.vertx.micrometer.backends.BackendRegistries").getDefaultNow();
registry.config().meterFilter(new (Java.type("io.micrometer.core.instrument.config.MeterFilter"))());
See also, more on histograms and percentiles:
from Micrometer doc
from Prometheus doc
Furthermore, you can check some full working examples. They come along with few instructions to setup with Prometheus and view dashboards in Grafana.
Restricting the Vert.x modules being monitored can be done using
disabledMetricsCategories
.
For a full list of domains, see MetricsDomain
The Micrometer registries are accessible, in order to create new metrics or fetch the existing ones. By default, an unique registry is used and will be shared across the Vert.x instances of the JVM:
var registry = Java.type("io.vertx.micrometer.backends.BackendRegistries").getDefaultNow();
It is also possible to have separate registries per Vertx instance, by giving a registry name in metrics options. Then it can be retrieved specifically:
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"influxDbOptions" : {
"enabled" : true
},
"registryName" : "my registry",
"enabled" : true
}
});
// Later on:
var registry = Java.type("io.vertx.micrometer.backends.BackendRegistries").getNow("my registry");
As an example, here is a custom timer that will track the execution time of a piece of code that is regularly called:
var registry = Java.type("io.vertx.micrometer.backends.BackendRegistries").getDefaultNow();
var timer = Java.type("io.micrometer.core.instrument.Timer").builder("my.timer").description("a description of what this timer does").register(registry);
vertx.setPeriodic(1000, function (l) {
timer.record(function () {
// Running here some operation to monitor
});
});
For more examples, documentation about the Micrometer registry and how to create metrics, check Micrometer doc.
Since plain access to Micrometer registries is provided, it is possible to leverage the Micrometer API. For instance, to instrument the JVM:
var registry = Java.type("io.vertx.micrometer.backends.BackendRegistries").getDefaultNow();
new (Java.type("io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics"))().bindTo(registry);
new (Java.type("io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics"))().bindTo(registry);
new (Java.type("io.micrometer.core.instrument.binder.jvm.JvmGcMetrics"))().bindTo(registry);
new (Java.type("io.micrometer.core.instrument.binder.system.ProcessorMetrics"))().bindTo(registry);
new (Java.type("io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics"))().bindTo(registry);
From Micrometer documentation.
Vert.x Micrometer Metrics defines a set of labels (aka tags or fields) that are used to provide dimensionality to a metric. For instance, metrics related to event bus messages have an address label, which allows then to query timeseries for a specific event bus address, or compare timeseries per address, or perform any kind of aggregation that the query API allows.
While setting up metrics options, you can specify which labels you want to enable or not:
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"prometheusOptions" : {
"enabled" : true
},
"labels" : Java.type("java.util.EnumSet").of('REMOTE', 'LOCAL', 'HTTP_CODE', 'HTTP_PATH'),
"enabled" : true
}
});
The full list of labels is detailed here: Label
.
Warning
|
Enabling labels may result in a high cardinality in values, which can cause troubles on the metrics backend and affect performances. So it must be used with care. In general, it is fine to enable labels when the set of possible values is bounded. |
For that reason, labels enabled by default are restricted to the ones with known bounded values.
It is possible to interact with labels further than just enabling/disabling. There are two ways for that:
Match
objects can be used to filter or rename some label value
by matching it with either an exact string or a regular expression (the former being more efficient).
Here is an example to restrict HTTP server metrics to those with label local=localhost:8080 only:
var Vertx = require("vertx-js/vertx");
var vertx = Vertx.vertx({
"metricsOptions" : {
"prometheusOptions" : {
"enabled" : true
},
"labelMatchs" : [
{
"domain" : "HTTP_SERVER",
"label" : "local",
"value" : "localhost:8080"
}
],
"enabled" : true
}
});
When an alias is specified in the Match, it will be used to rename value instead of filtering.
Matchers are especially useful to control labelling through configuration as they are set via
MicrometerMetricsOptions
.
Micrometer’s MeterFilter API can be accessed directly in order to define rules on labels. Compared to Matchers, it offers more features in manipulating the labels, but cannot be defined from configuration. So both have their advantages.
Here is an example to replace the actual path
label of HTTP requests with a generic form using regex:
var registry = Java.type("io.vertx.micrometer.backends.BackendRegistries").getDefaultNow();
var pattern = Java.type("java.util.regex.Pattern").compile("/foo/bar/.*");
registry.config().meterFilter(Java.type("io.micrometer.core.instrument.config.MeterFilter").replaceTagValues('HTTP_PATH'.toString(), function (actualPath) {
var m = pattern.matcher(actualPath);
if (m.matches()) {
return "/foo/bar/:id"
}
return actualPath
}, ""));
Note
|
Matchers use MeterFilters under the hood. |
A MetricsService
can be created out of a Measured
object
in order to take a snapshot of its related metrics and measurements.
The snapshot is returned as a JsonObject
.
A well known Measured object is simply Vertx
:
var MetricsService = require("vertx-micrometer-metrics-js/metrics_service");
var metricsService = MetricsService.create(vertx);
var metrics = metricsService.getMetricsSnapshot();
console.log(metrics);
Other components, such as an EventBus
or a HttpServer
are
measurable:
var MetricsService = require("vertx-micrometer-metrics-js/metrics_service");
var server = vertx.createHttpServer();
var metricsService = MetricsService.create(server);
var metrics = metricsService.getMetricsSnapshot();
console.log(metrics);
Finally it is possible to filter the returned metrics from their base names:
var MetricsService = require("vertx-micrometer-metrics-js/metrics_service");
var metricsService = MetricsService.create(vertx);
// Client + server
var metrics = metricsService.getMetricsSnapshot("vertx.http");
console.log(metrics);
This section lists all the metrics generated by monitoring the Vert.x core tools.
Note
|
The metric backends may have different conventions or rules for naming metrics. The names described below are given with underscore separators, but the actual names may vary depending on the backend used. |
Metric type | Metric name | Description |
---|---|---|
Gauge |
|
Number of connections to the remote host currently opened. |
Summary |
|
Number of bytes received from the remote host. |
Summary |
|
Number of bytes sent to the remote host. |
Counter |
|
Number of errors. |
Metric type | Metric name | Description |
---|---|---|
Gauge |
|
Number of connections to the remote host currently opened. |
Summary |
|
Number of bytes received from the remote host. |
Summary |
|
Number of bytes sent to the remote host. |
Counter |
|
Number of errors. |
Gauge |
|
Number of requests waiting for a response. |
Counter |
|
Number of requests sent. |
Timer |
|
Response time. |
Counter |
|
Number of received responses. |
Gauge |
|
Number of websockets currently opened. |
Metric type | Metric name | Description |
---|---|---|
Summary |
|
Total number of bytes received on the |
Summary |
|
Total number of bytes sent to the remote host. |
Counter |
|
Total number of errors. |
Metric type | Metric name | Description |
---|---|---|
Gauge |
|
Number of opened connections to the Net Server. |
Summary |
|
Number of bytes received by the Net Server. |
Summary |
|
Number of bytes sent by the Net Server. |
Counter |
|
Number of errors. |
Metric type | Metric name | Description |
---|---|---|
Gauge |
|
Number of opened connections to the HTTP Server. |
Summary |
|
Number of bytes received by the HTTP Server. |
Summary |
|
Number of bytes sent by the HTTP Server. |
Counter |
|
Number of errors. |
Gauge |
|
Number of requests being processed. |
Counter |
|
Number of processed requests. |
Counter |
|
Number of requests reset. |
Timer |
|
Request processing time. |
Gauge |
|
Number of websockets currently opened. |
Metric type | Metric name | Description |
---|---|---|
Gauge |
|
Number of event bus handlers in use. |
Counter |
|
Number of errors. |
Summary |
|
Total number of bytes sent while sending messages to event bus cluster peers. |
Summary |
|
Total number of bytes received while reading messages from event bus cluster peers. |
Gauge |
|
Number of messages not processed yet. One message published will count for |
Counter |
|
Number of messages published (publish / subscribe). |
Counter |
|
Number of messages sent (point-to-point). |
Counter |
|
Number of messages received. |
Counter |
|
Number of messages delivered to handlers. |
Counter |
|
Number of message reply failures. |
Timer |
|
Processing time for handlers listening to the |
This section lists all the metrics generated by monitoring Vert.x pools.
There are two types currently supported:
worker (see WorkerExecutor
)
datasource (created with Vert.x JDBC client)
Note
|
Vert.x creates two worker pools upfront, worker-thread and internal-blocking. |
Metric type | Metric name | Description |
---|---|---|
Timer |
|
Time waiting for a resource (queue time). |
Gauge |
|
Number of elements waiting for a resource. |
Timer |
|
Time using a resource (i.e. processing time for worker pools). |
Gauge |
|
Number of resources used. |
Counter |
|
Number of elements done with the resource (i.e. total number of tasks executed for worker pools). |
Gauge |
|
Pool usage ratio, only present if maximum pool size could be determined. |
Metric type | Metric name | Description |
---|---|---|
Gauge |
|
Number of verticle instances deployed. |