Hi Robert,
Thanks for the link. I have tried the Gauge support approach explained in the
Sling ticket you provided. I can't seem to get it to work to meet my use case.
Maybe I don't understand the approach completely.
It says to register the Gauge as a service instead of using the metricService
like the other 4 metrics (i.e. counter, timer etc)
I created a gauge interface:
import org.apache.sling.commons.metrics.Gauge;
public interface GaugeMonitor extends Gauge<Integer> {
void setValue(int val);
}
A gauge implementation:
public class GaugeImpl implements GaugeMonitor {
private volatile int value;
@Override
public void setValue(int val){
value = val;
}
@Override
public Integer getValue() {
return value;
}
}
Then I created a function in my monitoring service to register gauge as a
service:
@Reference(target = "(name=sling)")
private MetricRegistry registry;
public GaugeMonitor gauge(String name){
GaugeMonitor m = (GaugeMonitor) registry.getGauges().get(name);
if(m != null){
return m;
}
GaugeMonitor gauge = new GaugeImpl();
Dictionary<String, String> properties = new Hashtable<String, String>();
properties.put(Gauge.NAME, name);
bundleContext.registerService(Gauge.class, gauge, properties);
return gauge;
}
The first gauge works fine but if I want to reuse the gauge in another bundle
by calling monitorService.gauge("sameGaugeName"), I get a ClassCastException.
Do you know if there is a way to reuse the gauge without checking the
metricRegistry?
Thanks
Allen
On 5/27/20, 2:34 AM, "Robert Munteanu" <[email protected]> wrote:
On Wed, 2020-05-27 at 00:07 +0000, Allen Liu wrote:
> Hi Robert,
> Thanks a lot for the info. I was also using MetricRegistry to
> register the gauge metrics. I thought there was a way to add the
> gauge metric using metricsService.
> After looking into the implementation of metricsService, it seems to
> be not trivial to add the gauge registration in the metricsService.
>
> So, I will keep my implementation as it is to register gauge metrics
> using MetricRegistry.
While looking futher, it seems that there is Gague support, please see
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fissues.apache.org%2Fjira%2Fbrowse%2FSLING-5966&data=02%7C01%7Calliu%40adobe.com%7C776ef6f7866a435a194408d802211bb9%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C637261688512048503&sdata=Ksw5ueFzSazsjHOy7zuG0Rf4QFoY39fRc%2FRZUgbx%2Bq8%3D&reserved=0
Can you give this a try and let me know if it works for you?
Thanks,
Robert