RESTHeart currently provides a metrics feature described here. It is embedded in the plugin mongo and only collects metrics for requests handled by the MongoService
We want:
keep using the dropwizard library
refactor the metrics feature in a new, dedicated plugin
Metrics will be collected for requests matching the include path templates and not matching the exclude ones.
Note that a variable such {tenant} in the include path templates make the metrics being tagged with path_template_param_tenant =<value>. This does not apply for wildcards in path templates.
Let's make a few requests to /acme/ping with httpie
$ http -b :8080/acme/ping
Greetings from RESTHeart!
$http -b :8080/acme/ping
Greetings from RESTHeart!
$http -b :8080/acme/ping
Greetings from RESTHeart!
Now we can ask for available metrics:
$ http -b -a admin:secret :8080/metrics
[
"/jvm",
"/{tenant}/ping"
]
Let's get the metrics for requests matching "/{tenant}/*":
$ http -b -a admin:secret :8080/metrics/{tenant}/\*
(omitting many rows)
http_requests_count{request_method="GET",path_template="/{tenant}/*",response_status_code="200",path_template_param_tenant="acme",} 3.0
The response is in prometheus format. The highlighted row is the metrics http_requests_count with value 3 and the following tags:
Prometheus will start scraping restheart metrics. Note that given the default exclude path templates, metrics for prometheus requests will not be collected.
Open localhosts:9090 with your browser and check the metrics:
Add metrics labels from a Service
The method Metrics.attachMetricLabels(Request<?> request, List<MetricLabel> labels) allows to add custom labels to the collected metrics.
This is used by GraphQLService that adds to the metrics the query label with the name of the GraphQL executed query.
Brief overview
RESTHeart currently provides a metrics feature described here. It is embedded in the plugin mongo and only collects metrics for requests handled by the
MongoService
We want:
query
to specify the executed query)Rationale
Allow administrator to better monitor RESTHeart instances and developers to snoop performance bottlenecks.
Detailed documentation
Tutorial
Run restheart enabling metrics and specifying a configuration:
Let's analyze the metrics configuration. With the given RHO env variable, it is:
Metrics will be collected for requests matching the
include
path templates and not matching theexclude
ones.Note that a variable such
{tenant}
in the include path templates make the metrics being tagged withpath_template_param_tenant =<value>
. This does not apply for wildcards in path templates.Let's make a few requests to
/acme/ping
with httpieNow we can ask for available metrics:
Let's get the metrics for requests matching
"/{tenant}/*"
:The response is in prometheus format. The highlighted row is the metrics
http_requests_count
with value3
and the following tags:Use prometheus to display metrics
Define the following prometheus configuration file
prometheus.yml
Run prometheus with:
Prometheus will start scraping restheart metrics. Note that given the default
exclude
path templates, metrics for prometheus requests will not be collected.Open
localhosts:9090
with your browser and check the metrics:Add metrics labels from a Service
The method
Metrics.attachMetricLabels(Request<?> request, List<MetricLabel> labels)
allows to add custom labels to the collected metrics.This is used by
GraphQLService
that adds to the metrics thequery
label with the name of the GraphQL executed query.