com.github.marschall.micrometer.jfr.CounterEventFactory 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.ArrayList;
import java.util.List;
import java.util.Optional;
import io.micrometer.core.instrument.Meter.Id;
import jdk.jfr.AnnotationElement;
import jdk.jfr.Description;
import jdk.jfr.EventFactory;
import jdk.jfr.Label;
import jdk.jfr.ValueDescriptor;
final class CounterEventFactory extends AbstractMeterEventFactory {
CounterEventFactory(Id id) {
super(id);
}
@Override
protected List getAdditionalValueDescriptors() {
List incrementAnnotations = new ArrayList<>(3);
incrementAnnotations.add(new AnnotationElement(Label.class, "Increment"));
incrementAnnotations.add(new AnnotationElement(Description.class, "Amount to add to the counter."));
Optional baseUnitAnnotation = this.getAnnotationElementOfBaseUnit();
if (baseUnitAnnotation.isPresent()) {
incrementAnnotations.add(baseUnitAnnotation.get());
}
ValueDescriptor incrementDescriptor = new ValueDescriptor(double.class, "increment", incrementAnnotations);
List valueAnnotations = new ArrayList<>(3);
valueAnnotations.add(new AnnotationElement(Label.class, "Value"));
valueAnnotations.add(new AnnotationElement(Description.class, "The current value of the counter."));
if (baseUnitAnnotation.isPresent()) {
valueAnnotations.add(baseUnitAnnotation.get());
}
ValueDescriptor valueDescriptor = new ValueDescriptor(double.class, "value", valueAnnotations);
return List.of(incrementDescriptor, valueDescriptor);
}
@Override
JfrCounterEvent newEmptyEvent(EventFactory eventFactory) {
return new JfrCounterEvent(this.id, eventFactory.newEvent());
}
}