com.github.marschall.micrometer.jfr.JfrMeter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micrometer-jfr Show documentation
Show all versions of micrometer-jfr Show documentation
A Micrometer meter registry that generates JFR events
package com.github.marschall.micrometer.jfr;
import java.util.concurrent.TimeUnit;
import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Meter;
final class JfrMeter extends AbstractJfrMeter implements Meter {
private final Type type;
private final Iterable measurements;
private final Runnable hook;
JfrMeter(Id id, Type type, Iterable measurements, TimeUnit baseTimeUnit) {
super(id, new MeterEventFactory(id, baseTimeUnit, measurements));
this.type = type;
this.measurements = measurements;
this.hook = () -> this.recordEvent();
this.meterEventFactory.registerPeriodicEvent(this.jfrEventFactory, this.hook);
}
@Override
public void close() {
this.meterEventFactory.unregisterPeriodicEvent(this.hook);
super.close();
}
private void recordEvent() {
JfrMeterEvent event = this.newEmptyEvent();
event.recordValues(this.type, this.measurements);
event.commit();
}
@Override
public Iterable measure() {
return this.measurements;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy