com.codahale.metrics.jvm.JvmAttributeGaugeSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metrics-jvm Show documentation
Show all versions of metrics-jvm Show documentation
A set of classes which allow you to monitor critical aspects of your Java Virtual Machine
using Metrics.
The newest version!
package com.codahale.metrics.jvm;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricSet;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* A set of gauges for the JVM name, vendor, and uptime.
*/
public class JvmAttributeGaugeSet implements MetricSet {
private final RuntimeMXBean runtime;
/**
* Creates a new set of gauges.
*/
public JvmAttributeGaugeSet() {
this(ManagementFactory.getRuntimeMXBean());
}
/**
* Creates a new set of gauges with the given {@link RuntimeMXBean}.
*
* @param runtime JVM management interface with access to system properties
*/
public JvmAttributeGaugeSet(RuntimeMXBean runtime) {
this.runtime = runtime;
}
@Override
public Map getMetrics() {
final Map gauges = new HashMap<>();
gauges.put("name", (Gauge) runtime::getName);
gauges.put("vendor", (Gauge) () -> String.format(Locale.US,
"%s %s %s (%s)",
runtime.getVmVendor(),
runtime.getVmName(),
runtime.getVmVersion(),
runtime.getSpecVersion()));
gauges.put("uptime", (Gauge) runtime::getUptime);
return Collections.unmodifiableMap(gauges);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy