Example usage for org.apache.zookeeper.server ZooKeeperServer serverStats

List of usage examples for org.apache.zookeeper.server ZooKeeperServer serverStats

Introduction

In this page you can find the example usage for org.apache.zookeeper.server ZooKeeperServer serverStats.

Prototype

ServerStats serverStats

To view the source code for org.apache.zookeeper.server ZooKeeperServer serverStats.

Click Source Link

Usage

From source file:org.apache.pulsar.zookeeper.ZooKeeperServerAspect.java

License:Apache License

@After("zkServerConstructorPointCut()")
public void zkServerConstructor(JoinPoint joinPoint) throws Throwable {
    // ZooKeeperServer instance was created
    ZooKeeperServer zkServer = (ZooKeeperServer) joinPoint.getThis();

    synchronized (ZooKeeperServerAspect.class) {
        if (metricsRegistered) {
            // We can only register the metrics a single time for the process
            return;
        }//w ww . ja  v  a  2s . co  m

        metricsRegistered = true;
    }

    Gauge.build().name("zookeeper_server_znode_count").help("Number of z-nodes stored").create()
            .setChild(new Gauge.Child() {
                @Override
                public double get() {
                    return zkServer.getZKDatabase().getNodeCount();
                }
            }).register();

    Gauge.build().name("zookeeper_server_data_size_bytes").help("Size of all of z-nodes stored (bytes)")
            .create().setChild(new Gauge.Child() {
                @Override
                public double get() {
                    return zkServer.getZKDatabase().getDataTree().approximateDataSize();
                }
            }).register();

    Gauge.build().name("zookeeper_server_connections").help("Number of currently opened connections").create()
            .setChild(new Gauge.Child() {
                @Override
                public double get() {
                    return zkServer.serverStats().getNumAliveClientConnections();
                }
            }).register();

    Gauge.build().name("zookeeper_server_watches_count").help("Number of watches").create()
            .setChild(new Gauge.Child() {
                @Override
                public double get() {
                    return zkServer.getZKDatabase().getDataTree().getWatchCount();
                }
            }).register();

    Gauge.build().name("zookeeper_server_ephemerals_count").help("Number of ephemerals z-nodes").create()
            .setChild(new Gauge.Child() {
                @Override
                public double get() {
                    return zkServer.getZKDatabase().getDataTree().getEphemeralsCount();
                }
            }).register();
}