Currently Sling Metrics only support Gauges via the whiteboard approach (see
To leverage gauges you have to register a gauge instance by yourself using the OSGI Framework API and also its whole livecycle. The Sling MetricsService should be able to handle this for you as well like it does for the other metric types (e.g. counter).
I propose to extend the MetricsService by a new method:
which registers a Gauge which on every request to getValue() calls the provided supplier. In most cases the returned Gauge object is not used, but it is returned for consistency with other methods of the MetricsService.