Skip to content

Commit

Permalink
Avoid NullPointerException in ZK server stats collection (apache#2710)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat authored Oct 3, 2018
1 parent 1f37326 commit fe04ce8
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.prometheus.client.Gauge;

import org.apache.zookeeper.server.ServerCnxnFactory;
import org.apache.zookeeper.server.ZooKeeperServer;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
Expand Down Expand Up @@ -71,7 +72,12 @@ public double get() {
.setChild(new Gauge.Child() {
@Override
public double get() {
return zkServer.serverStats().getNumAliveClientConnections();
ServerCnxnFactory cnxFactory = zkServer.getServerCnxnFactory();
if (cnxFactory != null) {
return cnxFactory.getNumAliveConnections();
} else {
return -1;
}
}
}).register();

Expand Down

0 comments on commit fe04ce8

Please sign in to comment.