su.nlq.prometheus.jmx.scraper.BeanScraper 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.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.Optional;
final class BeanScraper {
private final @NotNull MBeanServerConnection connection;
private final @NotNull Receiver receiver;
public BeanScraper(@NotNull MBeanServerConnection connection, @NotNull Receiver receiver) {
this.connection = connection;
this.receiver = receiver;
}
public void scrape(@NotNull ObjectName name) {
getMBeanAttributesInfo(name).ifPresent(infos -> infos.forEach(info ->
getAttributeValue(name, info).ifPresent(value -> {
Logger.instance.trace("Scraping '{}[{}]'", name, info);
MBean.of(name, info).ifPresent(bean -> BeanValueScraper.scrape(receiver, bean, value));
})));
}
private @NotNull Optional
© 2015 - 2024 Weber Informatics LLC | Privacy Policy