See: Description
| Interface | Description |
|---|---|
| MetricsService |
The metrics service mainly allows to return a snapshot of measured objects.
|
| Class | Description |
|---|---|
| DropwizardMetricsOptions |
Vert.x Dropwizard metrics configuration.
|
| Match |
A match for a value.
|
| ScheduledMetricsConsumer |
TODO - support listening to more than one Measured
|
| ThroughputMeter |
A throughput metric, wraps a
Meter object to provide a one second instant
throughput value returned by ThroughputMeter.getValue(). |
| ThroughputTimer |
A throughput metric, wraps a
Meter object to provide a one second instant
throughput value returned by ThroughputTimer.getValue(). |
| Enum | Description |
|---|---|
| MatchType |
The type of match.
|
Measured
interface which is implemented by various Vert.x components like HttpServer,
NetServer, and even Vertx itself.
Confiugrable JMX reporting based on Dropwizard implementation, exposing Vert.x as JMX MBeans.
== Getting started
To enable metrics, add the following dependency to the _dependencies_ section of your build descriptor:
* Maven (in your `pom.xml`):
[source,xml,subs="+attributes"]
----
DropwizardMetricsOptions:
[source,$lang]
----
examples.MetricsExamples#setup()
----
You can also enable JMX:
[source,$lang]
----
examples.MetricsExamples#setupJMX()
----
To see details about JMX see the <vertx.metrics.options.registryName
configures the <vertx.metrics.options.jmxEnabled and
vertx.metrics.options.jmxDomain
configures the <vertx.metrics.options.configPath
option allows to reconfigure the metrics from a property file.
== Metrics service
While Vert.x core defines an SPI for reporting metrics (implemented for instance in this project), it does not define
an API for retrieving metrics (because some metrics collectors just do reporting and nothing more).
The MetricsService provides an API in front of the Dropwizard Registry to get
metrics data snapshots.
=== Naming
Each measured component listed below (except for Vertx) will have a base name associated with it. Each metric
can be retrieved by providing the fully qualified name examples.MetricsExamples#naming1
----
or from the measured component itself using just the metric name:
[source,$lang]
----
examples.MetricsExamples#naming2
----
See more examples below on how to retrieve/use metrics for a specific component.
Metrics names can also be listed:
[source,$lang]
----
examples.MetricsExamples#naming3
----
`baseName` defaults to `vertx`, but can be set to a custom value:
[source,$lang]
----
examples.MetricsExamples#baseName
----
=== Retrieving metrics
Once enabled, the MetricsService allows to retrieve metrics snapshots from any
Measured object which provides a map of the metric name to the data,
represented by a JsonObject. So for example if we were to print out all metrics
for a particular Vert.x instance:
[source,$lang]
----
examples.MetricsExamples#example1
----
NOTE: For details on the actual contents of the data (the actual metric) represented by the JsonObject
consult the implementation documentation like https://github.com/vert-x3/vertx-metrics[vertx-metrics]
Often it is desired that you only want to capture specific metrics for a particular component, like an http server
without having to know the details of the naming scheme of every metric (something which is left to the implementers of the SPI).
Since HttpServer implements Measured, you can easily grab all metrics
that are specific for that particular http server.
[source,$lang]
----
examples.MetricsExamples#example2
----
Metrics can also be retrieved using a base name:
[source,$lang]
----
examples.MetricsExamples#example3
----
== Data
Below is how each dropwizard metric is represented in JSON. Please refer to the
https://github.com/dropwizard/metrics[Dropwizard metrics] documentation for detailed information on each metric.
[[gauge]]
=== Gauge
[source,javascript]
----
{
"type" : "gauge",
"value" : value // any json value
}
----
[[counter]]
=== Counter
[source,$lang]
----
{
"type" : "counter",
"count" : 1 // number
}
----
[[histogram]]
=== Histogram
[source,javascript]
----
{
"type" : "histogram",
"count" : 1 // long
"min" : 1 // long
"max" : 1 // long
"mean" : 1.0 // double
"stddev" : 1.0 // double
"median" : 1.0 // double
"75%" : 1.0 // double
"95%" : 1.0 // double
"98%" : 1.0 // double
"99%" : 1.0 // double
"99.9%" : 1.0 // double
}
----
[[meter]]
=== Meter
[source,$lang]
----
{
"type" : "meter",
"count" : 1 // long
"meanRate" : 1.0 // double
"oneMinuteRate" : 1.0 // double
"fiveMinuteRate" : 1.0 // double
"fifteenMinuteRate" : 1.0 // double
"rate" : "events/second" // string representing rate
}
----
[[throughput_meter]]
=== ThroughputMeter
Extends a <DropwizardMetricsOptions via
a specific address match or a regex match:
[source,$lang]
----
examples.MetricsExamples#setupMonitoredHandlers()
----
WARNING: if you use regex match, a wrong regex can potentially match a lot of handlers.
[[http-server-metrics]]
=== Http server metrics
Base name: `vertx.http.servers.examples.MetricsExamples#setupMonitoredUris()
----
In case if the uri contains some path parameters like `/users/:userId` it might not make sense to have a separate entry in the registry for each user
id (like `get-requests./users/1`, `get-requests./users/2` and so on) but a summarized one. To achieve that you can set an alias to the match instance
in this case the alias will be used as a part of the registry name instead of uri like `examples.MetricsExamples#setupMonitoredUrisWithAliases()
----
*For `bytes-read` and `bytes-written` the bytes represent the body of the request/response, so headers, etc are ignored.*
=== Http client metrics
Base name: `vertx.http.clients` (by default) or `vertx.http.clients.HttpClientOptions.setMetricsName(java.lang.String).
Http client includes all the metrics of a <DropwizardMetricsOptions via
a specific hostname match or a regex match:
[source,$lang]
----
examples.MetricsExamples#setupMonitoredEndpoints()
----
[[net-server-metrics]]
=== Net server metrics
Base name: `vertx.net.servers.NetClientOptions.setMetricsName(java.lang.String).
Net client includes all the metrics of a <WorkerExecutor are exposed.
Datasource created with Vert.x JDBC clients are exposed as _datasource_.
* `queue-delay` - A <examples.MetricsExamples#setupJMX()
----
If running Vert.x from the command line you can enable metrics and JMX by uncommented the JMX_OPTS line in the
`vertx` or `vertx.bat` script:
----
JMX_OPTS="-Dcom.sun.management.jmxremote -Dvertx.metrics.options.jmxEnabled=true"
----
You can configure the domain under which the MBeans will be created:
[source,$lang]
----
examples.MetricsExamples#setupJMXWithDomain()
----
In the command line, just append the following system properties to your application (works for the `vertx` cli and
fat jars):
[source]
----
-Dvertx.metrics.options.jmxEnabled=true -Dvertx.metrics.options.jmxDomain=vertx
----
== Enabling remote JMX
If you want the metrics to be exposed remotely over JMX, then you need to set, at minimum the following system property:
`com.sun.management.jmxremote`
If running from the command line this can be done by editing the `vertx` or `vertx.bat` and uncommenting the
`JMX_OPTS` line.
Please see the http://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html[Oracle JMX documentation] for more information on configuring JMX
*If running Vert.x on a public server please be careful about exposing remote JMX access*
[[dropwizard-registry]]
== Accessing Dropwizard Registry
When configuring the metrics service, an optional registry name can be specified for registering the underlying
https://dropwizard.github.io/metrics/3.1.0/getting-started/#the-registry[Dropwizard Registry] in the
the https://dropwizard.github.io/metrics/3.1.0/apidocs/com/codahale/metrics/SharedMetricRegistries.html[Dropwizard Shared Registry]
so you can retrieve this registry and use according to your needs.
[source,$lang]
----
examples.MetricsExamples#getRegistry()}
----
== Using Jolokia and Hawtio
https://jolokia.org/[Jolokia] is a JMX-HTTP bridge giving an alternative to JSR-160 connectors. It is an agent based
approach with support for many platforms. In addition to basic JMX operations it enhances JMX remoting with features
like bulk requests.
http://hawt.io/[Hawtio] is a modular web console consuming the data exposed by Jolokia. It lets you create dashboards
and retrieve data from JMX such as memory, cpu, or any vert.x metrics.
This section explains how to configure your vert.x application to retrieve the metrics in Hawtio.
First, you need to configure your vert.x instance with the following options:
[source,$lang]
----
examples.MetricsExamples#example4()
----
You can change the domain to whatever you want. The same configuration can be used for clustered Vert.x instances.
This configuration instructs vertx-dropwizard-metrics to expose the metrics in the local MBean server, so
Jolokia can retrieve them.
Then you need, to _plug_ jolokia to expose the data. There are several ways to _plug_ jolokia. See
https://jolokia.org/reference/html/architecture.html[for further details]. Here, we explain how to use the
Jolokia agent with the default configuration. Refer to the https://jolokia.org/reference/html/[the jolokia
documentation] to configure it.
The agent can either be attached when you start the application or attached on a running JVM (you would need
special permission to access the process). In the first case, launch you application using:
[source]
----
java -javaagent:/.../agents/jolokia-jvm.jar=port=7777,host=localhost -jar ...
----
The `-javaagent` specifies the path to the jolokia agent jar file. You can configure the port and host from the
command line. Here it registers the REST endpoint on `http://localhost:7777`.
You can also attach the agent on a running JVM with:
[source]
----
java -jar jolokia-jvm.jar start PID
----
Replace `PID` with the process id of the JVM.
Once Jolokia is configured and launched, you can consume the data from Hawtio.
On Hawtio, enter the connection details as follows:
image::../../images/hawtio-connect.png[]
Then, you can go to the _JMX_ tab and you should find a _directory_ with the name you entered as JMX domain
in the Vert.x configuration:
image::../../images/hawtio-jmx.png[]
From this, you can configure your dashboard and retrieve any metric exposed by vert.x.
== Using Jolokia and JMX4Perl to expose metrics to Nagios
http://search.cpan.org/~roland/jmx4perl/scripts/check_jmx4perl[Check_jmx4perl] is a Nagios plugin using jmx4perl for
accessing JMX data remotely. It lets you expose the Vert.x metrics to Nagios.
First you need to start your application with the Jolokia JVM agent attached to it. There are several ways to
attach jolokia. See https://jolokia.org/reference/html/architecture.html[for further details]. Here, we explain how
to use the Jolokia agent with the default configuration. Refer to the https://jolokia.org/reference/html/[the jolokia
documentation] to configure it.
The agent can either be attached when you start the application or attached on a running JVM (you would need
special permission to access the process). In the first case, launch you application using:
[source]
----
java -javaagent:/.../agents/jolokia-jvm.jar=port=7777,host=localhost -jar ...
----
The `-javaagent` specifies the path to the jolokia agent jar file. You can configure the port and host from the
command line. Here it registers the REST endpoint on `http://localhost:7777`.
You can also attach the agent on a running JVM with:
[source]
----
java -jar jolokia-jvm.jar start PID
----
Replace `PID` with the process id of the JVM.
Once Jolokia is started, you can configure your Nagios check such as:
[source]
----
check_jmx4perl --url http://10.0.2.2:8778/jolokia --name eventloops --mbean vertx:name=vertx.event-loop-size
--attribute Value --warning 4
----
Check http://search.cpan.org/~roland/jmx4perl/scripts/check_jmx4perl[check_jmx4perl documentation] to get more
details about check configuration.Copyright © 2017. All rights reserved.