Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.prometheus.metrics.config.PrometheusProperties;
import io.prometheus.metrics.core.metrics.GaugeWithCallback;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.Unit;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -48,11 +49,13 @@ public class JvmBufferPoolMetrics {

private final PrometheusProperties config;
private final List<BufferPoolMXBean> bufferPoolBeans;
private final Labels constLabels;

private JvmBufferPoolMetrics(
List<BufferPoolMXBean> bufferPoolBeans, PrometheusProperties config) {
List<BufferPoolMXBean> bufferPoolBeans, PrometheusProperties config, Labels constLabels) {
this.config = config;
this.bufferPoolBeans = bufferPoolBeans;
this.constLabels = constLabels == null ? Labels.EMPTY : constLabels;
}

private void register(PrometheusRegistry registry) {
Expand All @@ -68,6 +71,7 @@ private void register(PrometheusRegistry registry) {
callback.call(pool.getMemoryUsed(), pool.getName());
}
})
.constLabels(constLabels)
.register(registry);

GaugeWithCallback.builder(config)
Expand All @@ -81,6 +85,7 @@ private void register(PrometheusRegistry registry) {
callback.call(pool.getTotalCapacity(), pool.getName());
}
})
.constLabels(constLabels)
.register(registry);

GaugeWithCallback.builder(config)
Expand All @@ -93,6 +98,7 @@ private void register(PrometheusRegistry registry) {
callback.call(pool.getCount(), pool.getName());
}
})
.constLabels(constLabels)
.register(registry);
}

Expand All @@ -108,11 +114,17 @@ public static class Builder {

private final PrometheusProperties config;
@Nullable private List<BufferPoolMXBean> bufferPoolBeans;
private Labels constLabels = Labels.EMPTY;

private Builder(PrometheusProperties config) {
this.config = config;
}

public Builder constLabels(Labels constLabels) {
this.constLabels = constLabels == null ? Labels.EMPTY : constLabels;
return this;
}

/** Package private. For testing only. */
Builder bufferPoolBeans(List<BufferPoolMXBean> bufferPoolBeans) {
this.bufferPoolBeans = bufferPoolBeans;
Expand All @@ -128,7 +140,7 @@ public void register(PrometheusRegistry registry) {
if (bufferPoolBeans == null) {
bufferPoolBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
}
new JvmBufferPoolMetrics(bufferPoolBeans, config).register(registry);
new JvmBufferPoolMetrics(bufferPoolBeans, config, constLabels).register(registry);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.prometheus.metrics.core.metrics.CounterWithCallback;
import io.prometheus.metrics.core.metrics.GaugeWithCallback;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
import io.prometheus.metrics.model.snapshots.Labels;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -44,10 +45,13 @@ public class JvmClassLoadingMetrics {

private final PrometheusProperties config;
private final ClassLoadingMXBean classLoadingBean;
private final Labels constLabels;

private JvmClassLoadingMetrics(ClassLoadingMXBean classLoadingBean, PrometheusProperties config) {
private JvmClassLoadingMetrics(
ClassLoadingMXBean classLoadingBean, PrometheusProperties config, Labels constLabels) {
this.classLoadingBean = classLoadingBean;
this.config = config;
this.constLabels = constLabels == null ? Labels.EMPTY : constLabels;
}

private void register(PrometheusRegistry registry) {
Expand All @@ -56,13 +60,15 @@ private void register(PrometheusRegistry registry) {
.name(JVM_CLASSES_CURRENTLY_LOADED)
.help("The number of classes that are currently loaded in the JVM")
.callback(callback -> callback.call(classLoadingBean.getLoadedClassCount()))
.constLabels(constLabels)
.register(registry);

CounterWithCallback.builder(config)
.name(JVM_CLASSES_LOADED_TOTAL)
.help(
"The total number of classes that have been loaded since the JVM has started execution")
.callback(callback -> callback.call(classLoadingBean.getTotalLoadedClassCount()))
.constLabels(constLabels)
.register(registry);

CounterWithCallback.builder(config)
Expand All @@ -71,6 +77,7 @@ private void register(PrometheusRegistry registry) {
"The total number of classes that have been unloaded since the JVM has "
+ "started execution")
.callback(callback -> callback.call(classLoadingBean.getUnloadedClassCount()))
.constLabels(constLabels)
.register(registry);
}

Expand All @@ -86,11 +93,17 @@ public static class Builder {

private final PrometheusProperties config;
@Nullable private ClassLoadingMXBean classLoadingBean;
private Labels constLabels = Labels.EMPTY;

private Builder(PrometheusProperties config) {
this.config = config;
}

public Builder constLabels(Labels constLabels) {
this.constLabels = constLabels == null ? Labels.EMPTY : constLabels;
return this;
}

/** Package private. For testing only. */
Builder classLoadingBean(ClassLoadingMXBean classLoadingBean) {
this.classLoadingBean = classLoadingBean;
Expand All @@ -106,7 +119,7 @@ public void register(PrometheusRegistry registry) {
this.classLoadingBean != null
? this.classLoadingBean
: ManagementFactory.getClassLoadingMXBean();
new JvmClassLoadingMetrics(classLoadingBean, config).register(registry);
new JvmClassLoadingMetrics(classLoadingBean, config, constLabels).register(registry);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.prometheus.metrics.config.PrometheusProperties;
import io.prometheus.metrics.core.metrics.CounterWithCallback;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.Unit;
import java.lang.management.CompilationMXBean;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -39,10 +40,13 @@ public class JvmCompilationMetrics {

private final PrometheusProperties config;
private final CompilationMXBean compilationBean;
private final Labels constLabels;

private JvmCompilationMetrics(CompilationMXBean compilationBean, PrometheusProperties config) {
private JvmCompilationMetrics(
CompilationMXBean compilationBean, PrometheusProperties config, Labels constLabels) {
this.compilationBean = compilationBean;
this.config = config;
this.constLabels = constLabels == null ? Labels.EMPTY : constLabels;
}

private void register(PrometheusRegistry registry) {
Expand All @@ -57,6 +61,7 @@ private void register(PrometheusRegistry registry) {
.unit(Unit.SECONDS)
.callback(
callback -> callback.call(millisToSeconds(compilationBean.getTotalCompilationTime())))
.constLabels(constLabels)
.register(registry);
}

Expand All @@ -72,11 +77,17 @@ public static class Builder {

private final PrometheusProperties config;
@Nullable private CompilationMXBean compilationBean;
private Labels constLabels = Labels.EMPTY;

private Builder(PrometheusProperties config) {
this.config = config;
}

public Builder constLabels(Labels constLabels) {
this.constLabels = constLabels == null ? Labels.EMPTY : constLabels;
return this;
}

/** Package private. For testing only. */
Builder compilationBean(CompilationMXBean compilationBean) {
this.compilationBean = compilationBean;
Expand All @@ -92,7 +103,7 @@ public void register(PrometheusRegistry registry) {
this.compilationBean != null
? this.compilationBean
: ManagementFactory.getCompilationMXBean();
new JvmCompilationMetrics(compilationBean, config).register(registry);
new JvmCompilationMetrics(compilationBean, config, constLabels).register(registry);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.prometheus.metrics.config.PrometheusProperties;
import io.prometheus.metrics.core.metrics.SummaryWithCallback;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.Quantiles;
import io.prometheus.metrics.model.snapshots.Unit;
import java.lang.management.GarbageCollectorMXBean;
Expand Down Expand Up @@ -42,11 +43,15 @@ public class JvmGarbageCollectorMetrics {

private final PrometheusProperties config;
private final List<GarbageCollectorMXBean> garbageCollectorBeans;
private final Labels constLabels;

private JvmGarbageCollectorMetrics(
List<GarbageCollectorMXBean> garbageCollectorBeans, PrometheusProperties config) {
List<GarbageCollectorMXBean> garbageCollectorBeans,
PrometheusProperties config,
Labels constLabels) {
this.config = config;
this.garbageCollectorBeans = garbageCollectorBeans;
this.constLabels = constLabels == null ? Labels.EMPTY : constLabels;
}

private void register(PrometheusRegistry registry) {
Expand All @@ -66,6 +71,7 @@ private void register(PrometheusRegistry registry) {
gc.getName());
}
})
.constLabels(constLabels)
.register(registry);
}

Expand All @@ -81,11 +87,17 @@ public static class Builder {

private final PrometheusProperties config;
@Nullable private List<GarbageCollectorMXBean> garbageCollectorBeans;
private Labels constLabels = Labels.EMPTY;

private Builder(PrometheusProperties config) {
this.config = config;
}

public Builder constLabels(Labels constLabels) {
this.constLabels = constLabels == null ? Labels.EMPTY : constLabels;
return this;
}

/** Package private. For testing only. */
Builder garbageCollectorBeans(List<GarbageCollectorMXBean> garbageCollectorBeans) {
this.garbageCollectorBeans = garbageCollectorBeans;
Expand All @@ -101,7 +113,7 @@ public void register(PrometheusRegistry registry) {
if (garbageCollectorBeans == null) {
garbageCollectorBeans = ManagementFactory.getGarbageCollectorMXBeans();
}
new JvmGarbageCollectorMetrics(garbageCollectorBeans, config).register(registry);
new JvmGarbageCollectorMetrics(garbageCollectorBeans, config, constLabels).register(registry);
}
}
}
Loading