Skip to content

Commit

Permalink
Report direct memory used in Proxy to prometheus (apache#3721)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat authored Mar 8, 2019
1 parent 44c8fd5 commit 8ea53f2
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.pulsar.common.stats.JvmMetrics.getJvmDirectMemoryUsed;
import static org.slf4j.bridge.SLF4JBridgeHandler.install;
import static org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger;

Expand All @@ -34,6 +35,10 @@
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;

import io.netty.util.internal.PlatformDependent;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Gauge;
import io.prometheus.client.Gauge.Child;
import io.prometheus.client.exporter.MetricsServlet;
import io.prometheus.client.hotspot.DefaultExports;
import org.apache.pulsar.common.configuration.VipStatus;
Expand Down Expand Up @@ -140,6 +145,22 @@ public ProxyServiceStarter(String[] args) throws Exception {

// Setup metrics
DefaultExports.initialize();

// Report direct memory from Netty counters
Gauge.build("jvm_memory_direct_bytes_used", "-").create().setChild(new Child() {
@Override
public double get() {
return getJvmDirectMemoryUsed();
}
}).register(CollectorRegistry.defaultRegistry);

Gauge.build("jvm_memory_direct_bytes_max", "-").create().setChild(new Child() {
@Override
public double get() {
return PlatformDependent.maxDirectMemory();
}
}).register(CollectorRegistry.defaultRegistry);

addWebServerHandlers(server, config, proxyService.getDiscoveryProvider());

// start web-service
Expand Down

0 comments on commit 8ea53f2

Please sign in to comment.