
nl.nlighten.prometheus.wildfly.WildflyVersionExports Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wildfly_exporter_client Show documentation
Show all versions of wildfly_exporter_client Show documentation
Prometheus Collector for various Jboss Wildfly metrics.
The newest version!
package nl.nlighten.prometheus.wildfly;
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
* Exports wildfly product name and version.
*
* Example usage:
*
* {@code
* new WildflyVersionExports().register();
* }
*
*
* Example metrics being exported:
*
* wildfly_info{name="WildFly Full",version="10.1.0.Final",} 1.0
*
*/
public class WildflyVersionExports extends Collector {
public List collect() {
List mfs = new ArrayList<>();
try {
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
final ObjectName filterName = new ObjectName("jboss.as:management-root=server");
Set mBeans = server.queryMBeans(filterName, null);
if (mBeans.size() > 0 ) {
GaugeMetricFamily wildflyInfo = new GaugeMetricFamily(
"wildfly_info",
"Wildfly version info",
Arrays.asList("name", "version"));
for (final ObjectInstance mBean : mBeans) {
wildflyInfo.addMetric(Arrays.asList((String) server.getAttribute(mBean.getObjectName(), "productName"), (String) server.getAttribute(mBean.getObjectName(), "productVersion")), 1);
}
mfs.add(wildflyInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
return mfs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy