55 lines
1.6 KiB
Plaintext
55 lines
1.6 KiB
Plaintext
// monitoring-che
|
|
|
|
[id="extending-che-monitoring-metrics_che"]
|
|
= Extending Che monitoring metrics
|
|
|
|
This section describes how to create a metric or a group of metrics to extend the monitoring metrics that Che is exposing.
|
|
|
|
Che has two major modules metrics:
|
|
|
|
* `che-core-metrics-core` -- contains core metrics module
|
|
* `che-core-api-metrics` -- contains metrics that are dependent on core Che 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 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]
|