This section describes how to create a metric or a group of metrics to extend the monitoring metrics that Che 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 Che components, such as workspace or user managers
Procedure
-
Create a class that extends the
MeterBinderclass. This allows to register the created metric in the overriddenbindTo(MeterRegistry registry)method.The following is an example of a metric that has a function that supplies the value for it:
Example metricpublic 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