blob: e126baad3b926b3db38d73b41dbe9c48f573a295 [file] [log] [blame]
// monitoring-{prod-id-short}
[id="extending-{prod-id-short}-monitoring-metrics_{context}"]
= Extending {prod-short} monitoring metrics
This section describes how to create a metric or a group of metrics to extend the monitoring metrics that {prod-short} is exposing.
There are two major modules for metrics:
* `che-core-metrics-core` -- contains core metrics module
* `che-core-api-metrics` -- contains metrics that are dependent on core {prod-short} components, such as workspace or user managers
.Procedure
* Create a class that extends the `MeterBinder` class. This allows to register the created metric in the overridden `bindTo(MeterRegistry registry)` method.
+
The following is an example of a metric that has a function that supplies the value for it:
+
.Example metric
[source,java]
----
public class UserMeterBinder implements MeterBinder {
private final UserManager userManager;
@Inject
public UserMeterBinder(UserManager userManager) {
this.userManager = userManager;
}
@Override
public void bindTo(MeterRegistry registry) {
Gauge.builder("che.user.total", this::count)
.description("Total amount of users")
.register(registry);
}
private double count() {
try {
return userManager.getTotalCount();
} catch (ServerException e) {
return Double.NaN;
}
}
----
+
Alternatively, the metric can be stored with a reference and updated manually in some other place in the code.
.Additional resources
* link:https://prometheus.io/docs/practices/naming/[Metric and label naming for Prometheus]
* link:https://prometheus.io/docs/concepts/metric_types/[Metric types for Prometheus]