org.apache.zookeeper.server.ServerCnxnFactory Java Examples
The following examples show how to use
org.apache.zookeeper.server.ServerCnxnFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientBaseWithFixes.java From hadoop with Apache License 2.0 | 6 votes |
static ServerCnxnFactory createNewServerInstance(File dataDir, ServerCnxnFactory factory, String hostPort, int maxCnxns) throws IOException, InterruptedException { ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); final int PORT = getPort(hostPort); if (factory == null) { factory = ServerCnxnFactory.createFactory(PORT, maxCnxns); } factory.startup(zks); Assert.assertTrue("waiting for server up", ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); return factory; }
Example #2
Source File: ClientBaseWithFixes.java From big-c with Apache License 2.0 | 6 votes |
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) { if (factory != null) { ZKDatabase zkDb; { ZooKeeperServer zs = getServer(factory); zkDb = zs.getZKDatabase(); } factory.shutdown(); try { zkDb.close(); } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } final int PORT = getPort(hostPort); Assert.assertTrue("waiting for server down", ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); } }
Example #3
Source File: ClientBaseWithFixes.java From big-c with Apache License 2.0 | 6 votes |
static ServerCnxnFactory createNewServerInstance(File dataDir, ServerCnxnFactory factory, String hostPort, int maxCnxns) throws IOException, InterruptedException { ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); final int PORT = getPort(hostPort); if (factory == null) { factory = ServerCnxnFactory.createFactory(PORT, maxCnxns); } factory.startup(zks); Assert.assertTrue("waiting for server up", ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); return factory; }
Example #4
Source File: KafkaOperatorTestBase.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
public static void stopZookeeper() { for (ZooKeeperServer zs : zkServer) { if (zs != null) { zs.shutdown(); } } for (ServerCnxnFactory zkf : zkFactory) { if (zkf != null) { zkf.closeAll(); zkf.shutdown(); } } zkServer = new ZooKeeperServer[2]; zkFactory = new ServerCnxnFactory[2]; }
Example #5
Source File: KafkaOperatorTestBase.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
public static void stopZookeeper() { for (ZooKeeperServer zs : zkServer) { if (zs != null) { zs.shutdown(); } } for (ServerCnxnFactory zkf : zkFactory) { if (zkf != null) { zkf.closeAll(); zkf.shutdown(); } } zkServer = new ZooKeeperServer[2]; zkFactory = new ServerCnxnFactory[2]; }
Example #6
Source File: ZookeeperDiscoverySpiSaslAuthAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ private void shutdownServerInstance(ServerCnxnFactory factory) { if (factory != null) { ZKDatabase zkDb = null; { ZooKeeperServer zs = getServer(factory); if (zs != null) zkDb = zs.getZKDatabase(); } factory.shutdown(); try { if (zkDb != null) zkDb.close(); } catch (IOException ie) { // ignore } } }
Example #7
Source File: ClientBaseWithFixes.java From hadoop with Apache License 2.0 | 6 votes |
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) { if (factory != null) { ZKDatabase zkDb; { ZooKeeperServer zs = getServer(factory); zkDb = zs.getZKDatabase(); } factory.shutdown(); try { zkDb.close(); } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } final int PORT = getPort(hostPort); Assert.assertTrue("waiting for server down", ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); } }
Example #8
Source File: Compatibility.java From curator with Apache License 2.0 | 6 votes |
public static void serverCnxnFactoryCloseAll(ServerCnxnFactory factory) { try { if ( closeAllMethod != null ) { closeAllMethod.invoke(factory); } else { closeAllWithReasonMethod.invoke(factory, disconnectReasonObj); } } catch ( Exception e ) { throw new RuntimeException("Could not close factory", e); } }
Example #9
Source File: TestingQuorumPeerMain.java From xian with Apache License 2.0 | 6 votes |
@Override public void kill() { try { if ( quorumPeer != null ) { Field cnxnFactoryField = QuorumPeer.class.getDeclaredField("cnxnFactory"); cnxnFactoryField.setAccessible(true); ServerCnxnFactory cnxnFactory = (ServerCnxnFactory)cnxnFactoryField.get(quorumPeer); cnxnFactory.closeAll(); Field ssField = cnxnFactory.getClass().getDeclaredField("ss"); ssField.setAccessible(true); ServerSocketChannel ss = (ServerSocketChannel)ssField.get(cnxnFactory); ss.close(); } close(); } catch ( Exception e ) { e.printStackTrace(); } }
Example #10
Source File: TestingQuorumPeerMain.java From curator with Apache License 2.0 | 6 votes |
@Override public void kill() { try { if ( quorumPeer != null ) { Field cnxnFactoryField = QuorumPeer.class.getDeclaredField("cnxnFactory"); cnxnFactoryField.setAccessible(true); ServerCnxnFactory cnxnFactory = (ServerCnxnFactory)cnxnFactoryField.get(quorumPeer); Compatibility.serverCnxnFactoryCloseAll(cnxnFactory); Field ssField = cnxnFactory.getClass().getDeclaredField("ss"); ssField.setAccessible(true); ServerSocketChannel ss = (ServerSocketChannel)ssField.get(cnxnFactory); ss.close(); } close(); } catch ( Exception e ) { e.printStackTrace(); } }
Example #11
Source File: TestingZooKeeperMain.java From xian with Apache License 2.0 | 6 votes |
@Override public void kill() { try { Field cnxnFactoryField = ZooKeeperServerMain.class.getDeclaredField("cnxnFactory"); cnxnFactoryField.setAccessible(true); ServerCnxnFactory cnxnFactory = (ServerCnxnFactory)cnxnFactoryField.get(this); cnxnFactory.closeAll(); Field ssField = cnxnFactory.getClass().getDeclaredField("ss"); ssField.setAccessible(true); ServerSocketChannel ss = (ServerSocketChannel)ssField.get(cnxnFactory); ss.close(); close(); } catch ( Exception e ) { e.printStackTrace(); // just ignore - this class is only for testing } }
Example #12
Source File: ZookeeperDiscoverySpiSaslAuthAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void startServerInstance(File dataDir, ServerCnxnFactory factory) throws IOException, InterruptedException { ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); factory.startup(zks); }
Example #13
Source File: ZooKeeperStateServer.java From localization_nifi with Apache License 2.0 | 5 votes |
private void startDistributed() throws IOException { logger.info("Starting Embedded ZooKeeper Peer"); try { transactionLog = new FileTxnSnapLog(new File(quorumPeerConfig.getDataLogDir()), new File(quorumPeerConfig.getDataDir())); connectionFactory = ServerCnxnFactory.createFactory(); connectionFactory.configure(quorumPeerConfig.getClientPortAddress(), quorumPeerConfig.getMaxClientCnxns()); quorumPeer = new QuorumPeer(); quorumPeer.setClientPortAddress(quorumPeerConfig.getClientPortAddress()); quorumPeer.setTxnFactory(new FileTxnSnapLog(new File(quorumPeerConfig.getDataLogDir()), new File(quorumPeerConfig.getDataDir()))); quorumPeer.setQuorumPeers(quorumPeerConfig.getServers()); quorumPeer.setElectionType(quorumPeerConfig.getElectionAlg()); quorumPeer.setMyid(quorumPeerConfig.getServerId()); quorumPeer.setTickTime(quorumPeerConfig.getTickTime()); quorumPeer.setMinSessionTimeout(quorumPeerConfig.getMinSessionTimeout()); quorumPeer.setMaxSessionTimeout(quorumPeerConfig.getMaxSessionTimeout()); quorumPeer.setInitLimit(quorumPeerConfig.getInitLimit()); quorumPeer.setSyncLimit(quorumPeerConfig.getSyncLimit()); quorumPeer.setQuorumVerifier(quorumPeerConfig.getQuorumVerifier()); quorumPeer.setCnxnFactory(connectionFactory); quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory())); quorumPeer.setLearnerType(quorumPeerConfig.getPeerType()); quorumPeer.setSyncEnabled(quorumPeerConfig.getSyncEnabled()); quorumPeer.setQuorumListenOnAllIPs(quorumPeerConfig.getQuorumListenOnAllIPs()); quorumPeer.start(); } catch (final IOException ioe) { throw new IOException("Failed to start embedded ZooKeeper Peer", ioe); } catch (final Exception e) { throw new RuntimeException("Failed to start embedded ZooKeeper Peer", e); } }
Example #14
Source File: ZookeeperDiscoverySpiSaslAuthAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private ServerCnxnFactory createNewServerInstance( ServerCnxnFactory factory, String hostPort, int maxCnxns) throws IOException { final int port = getPort(hostPort); if (factory == null) factory = ServerCnxnFactory.createFactory(port, maxCnxns); return factory; }
Example #15
Source File: EmbeddedZookeeper.java From nd4j with Apache License 2.0 | 5 votes |
public void startup() throws IOException { if (this.port == -1) { this.port = TestUtils.getAvailablePort(); } this.factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024); this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot"); this.logDir = TestUtils.constructTempDir("embeeded-zk/log"); try { factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime)); } catch (InterruptedException e) { throw new IOException(e); } }
Example #16
Source File: KafkaOperatorTestBase.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
public void stopZookeeper() { for (ServerCnxnFactory zkf : zkFactory) { if (zkf != null) { zkf.shutdown(); } } }
Example #17
Source File: ZooKeeperStateServer.java From nifi with Apache License 2.0 | 5 votes |
private void startDistributed() throws IOException { logger.info("Starting Embedded ZooKeeper Peer"); try { transactionLog = new FileTxnSnapLog(quorumPeerConfig.getDataLogDir(), quorumPeerConfig.getDataDir()); connectionFactory = ServerCnxnFactory.createFactory(); connectionFactory.configure(quorumPeerConfig.getClientPortAddress(), quorumPeerConfig.getMaxClientCnxns()); quorumPeer = new QuorumPeer(); quorumPeer.setTxnFactory(new FileTxnSnapLog(quorumPeerConfig.getDataLogDir(), quorumPeerConfig.getDataDir())); quorumPeer.setElectionType(quorumPeerConfig.getElectionAlg()); quorumPeer.setMyid(quorumPeerConfig.getServerId()); quorumPeer.setTickTime(quorumPeerConfig.getTickTime()); quorumPeer.setMinSessionTimeout(quorumPeerConfig.getMinSessionTimeout()); quorumPeer.setMaxSessionTimeout(quorumPeerConfig.getMaxSessionTimeout()); quorumPeer.setInitLimit(quorumPeerConfig.getInitLimit()); quorumPeer.setSyncLimit(quorumPeerConfig.getSyncLimit()); quorumPeer.setQuorumVerifier(quorumPeerConfig.getQuorumVerifier(), false); quorumPeer.setCnxnFactory(connectionFactory); quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory())); quorumPeer.setLearnerType(quorumPeerConfig.getPeerType()); quorumPeer.setSyncEnabled(quorumPeerConfig.getSyncEnabled()); quorumPeer.setQuorumListenOnAllIPs(quorumPeerConfig.getQuorumListenOnAllIPs()); quorumPeer.start(); } catch (final IOException ioe) { throw new IOException("Failed to start embedded ZooKeeper Peer", ioe); } catch (final Exception e) { throw new RuntimeException("Failed to start embedded ZooKeeper Peer", e); } }
Example #18
Source File: SpliceZoo.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
public SpliceZoo(QuorumPeerConfig config, int number) throws IOException { this.config = config; try { if (QuorumPeer.class.getMethod("testingQuorumPeer", null) != null) this.peer = (QuorumPeer) QuorumPeer.class.getMethod("testingQuorumPeer", null).invoke(null,null); else this.peer = QuorumPeer.class.newInstance(); } catch (Exception e) { throw new RuntimeException("Quorum Peer Signature Issue for Unit Tests"); } ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(),config.getMaxClientCnxns()); peer.setClientPortAddress(config.getClientPortAddress()); peer.setTxnFactory(new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir()))); peer.setQuorumPeers(config.getServers()); peer.setElectionType(config.getElectionAlg()); peer.setMyid(config.getServerId()); peer.setTickTime(config.getTickTime()); peer.setMinSessionTimeout(config.getMinSessionTimeout()); peer.setMaxSessionTimeout(config.getMaxSessionTimeout()); peer.setInitLimit(config.getInitLimit()); peer.setSyncLimit(config.getSyncLimit()); peer.setQuorumVerifier(config.getQuorumVerifier()); peer.setCnxnFactory(cnxnFactory); peer.setZKDatabase(new ZKDatabase(peer.getTxnFactory())); peer.setLearnerType(config.getPeerType()); peer.setMyid(number); }
Example #19
Source File: MicroZookeeperService.java From hadoop with Apache License 2.0 | 5 votes |
/** * Startup: start ZK. It is only after this that * the binding information is valid. * @throws Exception */ @Override protected void serviceStart() throws Exception { setupSecurity(); ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, dataDir); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(tickTime); LOG.info("Starting Local Zookeeper service"); factory = ServerCnxnFactory.createFactory(); factory.configure(getAddress(port), -1); factory.startup(zkServer); String connectString = getConnectionString(); LOG.info("In memory ZK started at {}\n", connectString); if (LOG.isDebugEnabled()) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); zkServer.dumpConf(pw); pw.flush(); LOG.debug(sw.toString()); } binding = new BindingInformation(); binding.ensembleProvider = new FixedEnsembleProvider(connectString); binding.description = getName() + " reachable at \"" + connectString + "\""; addDiagnostics(binding.description); // finally: set the binding information in the config getConfig().set(KEY_REGISTRY_ZK_QUORUM, connectString); }
Example #20
Source File: ZooKeeperServerRunner.java From waltz with Apache License 2.0 | 5 votes |
public ZooKeeperServerRunner(int port, Path zkDir) throws IOException { int zkPort = port == 0 ? new PortFinder().getPort() : port; InetAddress inetAddress = InetAddress.getLocalHost(); this.connectString = inetAddress.getCanonicalHostName() + ":" + zkPort; try { InetSocketAddress socketAddress = new InetSocketAddress(inetAddress, zkPort); this.standaloneServerFactory = ServerCnxnFactory.createFactory(socketAddress, NUM_CONNECTIONS); } catch (IOException ex) { throw new IOException("failed to create zookeeper ServerCnxnFactory: port=" + zkPort, ex); } this.zkDir = zkDir.toFile(); }
Example #21
Source File: TestingZooKeeperMain.java From xian with Apache License 2.0 | 5 votes |
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") @Override public void blockUntilStarted() throws Exception { latch.await(); ServerCnxnFactory cnxnFactory = getServerConnectionFactory(); if ( cnxnFactory != null ) { final ZooKeeperServer zkServer = getZooKeeperServer(cnxnFactory); if ( zkServer != null ) { synchronized(zkServer) { if ( !zkServer.isRunning() ) { zkServer.wait(); } } } } Thread.sleep(1000); Exception exception = startingException.get(); if ( exception != null ) { throw exception; } }
Example #22
Source File: EmbeddedZooKeeper.java From centraldogma with Apache License 2.0 | 5 votes |
private static ServerCnxnFactory createCnxnFactory(QuorumPeerConfig zkCfg) throws IOException { final InetSocketAddress bindAddr = zkCfg.getClientPortAddress(); final ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); // Listen only on 127.0.0.1 because we do not want to expose ZooKeeper to others. cnxnFactory.configure(new InetSocketAddress("127.0.0.1", bindAddr != null ? bindAddr.getPort() : 0), zkCfg.getMaxClientCnxns()); return cnxnFactory; }
Example #23
Source File: ZookeeperInstance.java From netcrusher-java with Apache License 2.0 | 5 votes |
public ZookeeperInstance(File commonWorkDir, boolean useCrusher, int instance) throws Exception { File workDir = new File(commonWorkDir, "instance-" + instance); FileUtils.forceMkdir(workDir); File logDir = new File(commonWorkDir, "log-" + instance); FileUtils.forceMkdir(logDir); File markerFile = new File(workDir, "myid"); FileUtils.write(markerFile, Integer.toString(instance), "UTF-8"); this.instance = instance; this.clientPort = PORT_BASE_CLIENT + instance; Properties properties = new Properties(); properties.put("tickTime", "100"); properties.put("dataDir", workDir.getAbsolutePath()); properties.put("dataLogDir", logDir.getAbsolutePath()); properties.put("clientPort", Integer.toString(clientPort)); properties.put("clientPortAddress", "127.0.0.1"); properties.put("initLimit", "5"); properties.put("syncLimit", "5"); for (int i = 1; i <= CLUSTER_SIZE; i++) { int leaderPort = (i != instance && useCrusher) ? PORT_BASE_LEADER + PORT_CRUSHER_BASE + i : PORT_BASE_LEADER + i; int electionPort = (i != instance && useCrusher) ? PORT_BASE_ELECTION + PORT_CRUSHER_BASE + i : PORT_BASE_ELECTION + i; properties.put("server." + i, "127.0.0.1:" + leaderPort + ":" + electionPort); } QuorumPeerConfig config = new QuorumPeerConfig(); config.parseProperties(properties); this.factory = ServerCnxnFactory.createFactory(); this.peer = createPeer(factory, config); LOGGER.info("Zookeeper #{} is started", instance); }
Example #24
Source File: ZookeeperInstance.java From netcrusher-java with Apache License 2.0 | 5 votes |
private QuorumPeer createPeer(ServerCnxnFactory cnxnFactory, QuorumPeerConfig config) throws IOException { cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); QuorumPeer quorumPeer = new QuorumPeer(); quorumPeer.setClientPortAddress(config.getClientPortAddress()); quorumPeer.setTxnFactory(new FileTxnSnapLog( new File(config.getDataLogDir()), new File(config.getDataDir()))); quorumPeer.setQuorumPeers(config.getServers()); quorumPeer.setElectionType(config.getElectionAlg()); quorumPeer.setMyid(config.getServerId()); quorumPeer.setTickTime(config.getTickTime()); quorumPeer.setMinSessionTimeout(config.getMinSessionTimeout()); quorumPeer.setMaxSessionTimeout(config.getMaxSessionTimeout()); quorumPeer.setInitLimit(config.getInitLimit()); quorumPeer.setSyncLimit(config.getSyncLimit()); quorumPeer.setQuorumVerifier(config.getQuorumVerifier()); quorumPeer.setCnxnFactory(cnxnFactory); quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory())); quorumPeer.setLearnerType(config.getPeerType()); quorumPeer.setSyncEnabled(config.getSyncEnabled()); quorumPeer.setQuorumListenOnAllIPs(config.getQuorumListenOnAllIPs()); quorumPeer.start(); return quorumPeer; }
Example #25
Source File: InMemoryZKServer.java From twill with Apache License 2.0 | 5 votes |
@Override protected void startUp() throws Exception { ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, dataDir); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(tickTime); factory = ServerCnxnFactory.createFactory(); factory.configure(getAddress(port), -1); factory.startup(zkServer); LOG.info("In memory ZK started: " + getConnectionStr()); }
Example #26
Source File: MicroZookeeperService.java From big-c with Apache License 2.0 | 5 votes |
/** * Startup: start ZK. It is only after this that * the binding information is valid. * @throws Exception */ @Override protected void serviceStart() throws Exception { setupSecurity(); ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, dataDir); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(tickTime); LOG.info("Starting Local Zookeeper service"); factory = ServerCnxnFactory.createFactory(); factory.configure(getAddress(port), -1); factory.startup(zkServer); String connectString = getConnectionString(); LOG.info("In memory ZK started at {}\n", connectString); if (LOG.isDebugEnabled()) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); zkServer.dumpConf(pw); pw.flush(); LOG.debug(sw.toString()); } binding = new BindingInformation(); binding.ensembleProvider = new FixedEnsembleProvider(connectString); binding.description = getName() + " reachable at \"" + connectString + "\""; addDiagnostics(binding.description); // finally: set the binding information in the config getConfig().set(KEY_REGISTRY_ZK_QUORUM, connectString); }
Example #27
Source File: ZookeeperDiscoverySpiSaslAuthAbstractTest.java From ignite with Apache License 2.0 | 4 votes |
/** */ private ZooKeeperServer getServer(ServerCnxnFactory fac) { ZooKeeperServer zs = U.field(fac, "zkServer"); return zs; }
Example #28
Source File: ClientBaseWithFixes.java From hadoop with Apache License 2.0 | 4 votes |
protected static ZooKeeperServer getServer(ServerCnxnFactory fac) { ZooKeeperServer zs = ServerCnxnFactoryAccessor.getZkServer(fac); return zs; }
Example #29
Source File: ClientBaseWithFixes.java From big-c with Apache License 2.0 | 4 votes |
protected static ZooKeeperServer getServer(ServerCnxnFactory fac) { ZooKeeperServer zs = ServerCnxnFactoryAccessor.getZkServer(fac); return zs; }
Example #30
Source File: ZooKeeperServerAspect.java From pulsar with Apache License 2.0 | 4 votes |
@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; } 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() { ServerCnxnFactory cnxFactory = zkServer.getServerCnxnFactory(); if (cnxFactory != null) { return cnxFactory.getNumAliveConnections(); } else { return -1; } } }).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(); }