Skip to content

Commit

Permalink
New meta-metrics: jinsight.build_info and jvm.info (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
rshivane authored Jun 10, 2019
1 parent a7db3b2 commit 7194800
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ai.apptuit.metrics.client.Sanitizer;
import ai.apptuit.metrics.dropwizard.ApptuitReporter.ReportingMode;
import ai.apptuit.metrics.dropwizard.ApptuitReporterFactory;
import ai.apptuit.metrics.dropwizard.TagEncodedMetricName;
import ai.apptuit.metrics.jinsight.modules.jvm.JvmMetricSet;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ScheduledReporter;
Expand Down Expand Up @@ -61,6 +62,9 @@ boolean initialize() {

private void initialize(ConfigService configService, ApptuitReporterFactory factory) {
registry.registerAll(new JvmMetricSet());
String buildInfoMetricName = TagEncodedMetricName.decode("jinsight").submetric("build_info")
.withTags("version", configService.getAgentVersion()).toString();
registry.gauge(buildInfoMetricName, () -> () -> 1L);
MetricRegistryCollection metricRegistryCollection = MetricRegistryCollection.getInstance();
metricRegistryCollection.initialize(registry);
startReportingOnRegistryCollection(configService, factory, metricRegistryCollection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static java.lang.management.ManagementFactory.getRuntimeMXBean;
import static java.lang.management.ManagementFactory.newPlatformMXBeanProxy;

import ai.apptuit.metrics.dropwizard.TagEncodedMetricName;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
Expand All @@ -42,6 +43,10 @@
public class JvmMetricSet implements MetricSet {

private static final Logger LOGGER = Logger.getLogger(JvmMetricSet.class.getName());
static final String JVM_INFO_METRIC_NAME = TagEncodedMetricName.decode("jvm.info")
.withTags("version", System.getProperty("java.version"))
.withTags("vendor", System.getProperty("java.vendor"))
.toString();

private final Map<String, Metric> metrics = new HashMap<>();

Expand All @@ -55,6 +60,8 @@ public JvmMetricSet() {

metrics.put("jvm.uptime.seconds", new UptimeGauge());

metrics.put(JVM_INFO_METRIC_NAME, (Gauge) () -> 1L);

try {
metrics.put("jvm.process.cpu.seconds", new ProcessCpuTicksGauge());
} catch (ClassNotFoundException | IOException e) {
Expand Down Expand Up @@ -99,7 +106,7 @@ public ProcessCpuTicksGauge() throws ClassNotFoundException, IOException {
Class.forName("com.sun.management.OperatingSystemMXBean");

osMxBean = newPlatformMXBeanProxy(mbsc, OPERATING_SYSTEM_MXBEAN_NAME,
com.sun.management.OperatingSystemMXBean.class);
com.sun.management.OperatingSystemMXBean.class);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

package ai.apptuit.metrics.jinsight.modules.jvm;

import static ai.apptuit.metrics.jinsight.modules.jvm.JvmMetricSet.JVM_INFO_METRIC_NAME;
import static java.lang.management.ManagementFactory.getRuntimeMXBean;
import static org.junit.Assert.assertEquals;

import ai.apptuit.metrics.dropwizard.TagEncodedMetricName;
import com.codahale.metrics.MetricRegistry;

import java.lang.management.RuntimeMXBean;
import java.util.Arrays;
import java.util.List;
import java.util.TreeSet;
Expand Down Expand Up @@ -126,6 +130,8 @@ public void testJVMMetrics() throws Exception {
expectedMetrics.add("jvm.fd.open");
}

expectedMetrics.add(JVM_INFO_METRIC_NAME);

assertEquals(expectedMetrics, registry.getNames());
}
}

0 comments on commit 7194800

Please sign in to comment.