su.nlq.prometheus.jmx.scraper.BeanValueScraper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmx-prometheus-collector Show documentation
Show all versions of jmx-prometheus-collector Show documentation
Pipe for JMX MBeans to Prometheus
package su.nlq.prometheus.jmx.scraper;
import org.jetbrains.annotations.NotNull;
import su.nlq.prometheus.jmx.bean.MBean;
import su.nlq.prometheus.jmx.logging.Logger;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularDataSupport;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
enum BeanValueScraper {
Incompatible(ObjectName.class, String.class, String[].class, long[].class, Boolean.class) {
@Override
protected void process(@NotNull Receiver receiver, @NotNull MBean bean, @NotNull Object value) {
Logger.instance.trace("Skipping incompatible data {}: {}", bean, value);
}
},
SimpleData(Number.class) {
@Override
protected void process(@NotNull Receiver receiver, @NotNull MBean bean, @NotNull Object value) {
Logger.instance.trace("Processing {}", bean);
receiver.accept(bean, value);
}
},
CompositeData(CompositeData.class) {
@Override
protected void process(@NotNull Receiver receiver, @NotNull MBean bean, @NotNull Object value) {
Logger.instance.trace("Processing composite data: {}", bean);
final CompositeData composite = (CompositeData) value;
composite.getCompositeType().keySet().forEach(key -> scrape(receiver, bean.compose(key), composite.get(key)));
}
},
CompositeDataArray(CompositeData[].class) {
@Override
protected void process(@NotNull Receiver receiver, @NotNull MBean bean, @NotNull Object value) {
Logger.instance.trace("Processing composite data array: {}", bean);
for (CompositeData element : (CompositeData[]) value) {
CompositeData.process(receiver, bean, element);
}
}
},
TabularData(TabularDataSupport.class) {
@Override
protected void process(@NotNull Receiver receiver, @NotNull MBean bean, @NotNull Object value) {
Logger.instance.trace("Processing tabular data: {}", bean);
for (Map.Entry
© 2015 - 2024 Weber Informatics LLC | Privacy Policy