Skip to content

Commit

Permalink
Report codecache metrics(#22)
Browse files Browse the repository at this point in the history
* upgrade version 1.4.3
* report code cache usage.
  • Loading branch information
caojie09 authored and luyiisme committed Jun 27, 2018
1 parent be02be8 commit 5287564
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/lookout-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/lookout-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/lookout-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/lookout-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/lookout-ext-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,29 @@
import com.alipay.lookout.api.Id;
import com.alipay.lookout.api.Registry;
import com.alipay.lookout.api.composite.MixinMetric;
import com.alipay.lookout.common.log.LookoutLoggerFactory;
import com.alipay.lookout.spi.MetricsImporter;
import org.slf4j.Logger;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.util.List;

/**
* Created by kevin.luy@alipay.com on 2017/2/16.
*/
public class JvmMemoryMetricsImporter implements MetricsImporter {
private static final Logger LOGGER = LookoutLoggerFactory
.getLogger(JvmMemoryMetricsImporter.class);
private static final String CODE_CACHE_NAME = "Code Cache";

@Override
public void register(Registry registry) {
Id id = registry.createId("jvm.memory");
MixinMetric mixin = registry.mixinMetric(id);
heapImport(mixin);
nonheapImport(mixin);
codeCacheImport(mixin);
}

private void nonheapImport(MixinMetric mixin) {
Expand Down Expand Up @@ -90,4 +99,48 @@ public Long value() {
}
});
}

private void codeCacheImport(MixinMetric mixin) {
final MemoryPoolMXBean codeCacheMXBean = getCodeCacheMXBean();
if (codeCacheMXBean == null) {
LOGGER.info("can't get code cache MemoryPoolMXBean, won't report code cache usage.");
return;
}

mixin.gauge("codecache.init", new Gauge<Long>() {
@Override
public Long value() {
return codeCacheMXBean.getUsage().getInit();
}
});
mixin.gauge("codecache.used", new Gauge<Long>() {
@Override
public Long value() {
return codeCacheMXBean.getUsage().getUsed();
}
});
mixin.gauge("codecache.committed", new Gauge<Long>() {
@Override
public Long value() {
return codeCacheMXBean.getUsage().getCommitted();
}
});
mixin.gauge("codecache.max", new Gauge<Long>() {
@Override
public Long value() {
return codeCacheMXBean.getUsage().getMax();
}
});
}

private MemoryPoolMXBean getCodeCacheMXBean() {
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
if (CODE_CACHE_NAME.equals(memoryPoolMXBean.getName())) {
return memoryPoolMXBean;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public void testMemInfo() {
Assert.assertTrue(gauge.value().longValue() >= 0);
gauge = mixin.gauge("heap.max", null);
Assert.assertTrue(gauge.value().longValue() >= -1);

gauge = mixin.gauge("codecache.init", null);
Assert.assertTrue(gauge.value().longValue() >= 0);
gauge = mixin.gauge("codecache.used", null);
Assert.assertTrue(gauge.value().longValue() >= 0);
gauge = mixin.gauge("codecache.committed", null);
Assert.assertTrue(gauge.value().longValue() >= 0);
gauge = mixin.gauge("codecache.max", null);
Assert.assertTrue(gauge.value().longValue() >= -1);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion client/lookout-ext-os/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/lookout-reg-dropwizard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/lookout-reg-prometheus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/lookout-reg-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/lookout-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<packaging>pom</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>It is a library which allows you to instrument your app with custom metrics</description>
Expand Down
2 changes: 1 addition & 1 deletion client/samples/lookout-client-samples-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<lookout.client.version>1.4.2</lookout.client.version>
<lookout.client.version>1.4.3</lookout.client.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<lookout.client.version>1.4.2</lookout.client.version>
<lookout.client.version>1.4.3</lookout.client.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion client/samples/lookout-client-samples-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-client</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
</dependency>
<!-- log4j 2 for lookout client-->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion client/samples/lookout-client-samples-prometheus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<lookout.client.version>1.4.2</lookout.client.version>
<lookout.client.version>1.4.3</lookout.client.version>
</properties>

<dependencies>
Expand Down

0 comments on commit 5287564

Please sign in to comment.