Class ProcessMetrics
These metrics are defined in the process metrics section of the Prometheus client library documentation, and they are implemented across client libraries in multiple programming languages.
Technically, some of them are OS-level metrics and not JVM-level metrics. However, I'm still
putting them in the prometheus-metrics-instrumentation-jvm module, because first it seems
overkill to create a separate Maven module just for the ProcessMetrics class, and seconds
some of these metrics are coming from the JVM via JMX anyway.
The ProcessMetrics are registered as part of the JvmMetrics like this:
JvmMetrics.builder().register();
However, if you want only the ProcessMetrics you can also register them directly:
ProcessMetrics.builder().register();
Example metrics being exported:
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. # TYPE process_cpu_seconds_total counter process_cpu_seconds_total 1.63 # HELP process_max_fds Maximum number of open file descriptors. # TYPE process_max_fds gauge process_max_fds 524288.0 # HELP process_open_fds Number of open file descriptors. # TYPE process_open_fds gauge process_open_fds 28.0 # HELP process_resident_memory_bytes Resident memory size in bytes. # TYPE process_resident_memory_bytes gauge process_resident_memory_bytes 7.8577664E7 # HELP process_start_time_seconds Start time of the process since unix epoch in seconds. # TYPE process_start_time_seconds gauge process_start_time_seconds 1.693829439767E9 # HELP process_virtual_memory_bytes Virtual memory size in bytes. # TYPE process_virtual_memory_bytes gauge process_virtual_memory_bytes 1.2683624448E10
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprivate static class(package private) static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final PrometheusPropertiesprivate final Labelsprivate final ProcessMetrics.Grepperprivate final booleanprivate final OperatingSystemMXBean(package private) static final Fileprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate final RuntimeMXBean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateProcessMetrics(OperatingSystemMXBean osBean, RuntimeMXBean runtimeBean, ProcessMetrics.Grepper grepper, PrometheusProperties config, Labels constLabels) -
Method Summary
Modifier and TypeMethodDescriptionstatic ProcessMetrics.Builderbuilder()static ProcessMetrics.Builderbuilder(PrometheusProperties config) private LongcallLongGetter(Method method, Object obj) Attempts to call a method either directly or via one of the implemented interfaces.private LongcallLongGetter(String getterName, Object obj) private voidregister(PrometheusRegistry registry)
-
Field Details
-
PROCESS_CPU_SECONDS_TOTAL
- See Also:
-
PROCESS_START_TIME_SECONDS
- See Also:
-
PROCESS_OPEN_FDS
- See Also:
-
PROCESS_MAX_FDS
- See Also:
-
PROCESS_VIRTUAL_MEMORY_BYTES
- See Also:
-
PROCESS_RESIDENT_MEMORY_BYTES
- See Also:
-
PROC_SELF_STATUS
-
config
-
osBean
-
runtimeBean
-
grepper
-
linux
private final boolean linux -
constLabels
-
-
Constructor Details
-
ProcessMetrics
private ProcessMetrics(OperatingSystemMXBean osBean, RuntimeMXBean runtimeBean, ProcessMetrics.Grepper grepper, PrometheusProperties config, Labels constLabels)
-
-
Method Details
-
register
-
callLongGetter
private Long callLongGetter(String getterName, Object obj) throws NoSuchMethodException, InvocationTargetException -
callLongGetter
Attempts to call a method either directly or via one of the implemented interfaces.A Method object refers to a specific method declared in a specific class. The first invocation might happen with method == SomeConcreteClass.publicLongGetter() and will fail if SomeConcreteClass is not public. We then recurse over all interfaces implemented by SomeConcreteClass (or extended by those interfaces and so on) until we eventually invoke callMethod() with method == SomePublicInterface.publicLongGetter(), which will then succeed.
There is a built-in assumption that the method will never return null (or, equivalently, that it returns the primitive data type, i.e.
longrather thanLong). If this assumption doesn't hold, the method might be called repeatedly and the returned value will be the one produced by the last call.- Throws:
InvocationTargetException
-
builder
-
builder
-