You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2017/12/12 18:44:56 UTC

zookeeper git commit: ZOOKEEPER-2950: Add keys for the Zxid from the stat command to check_zookeeper.py

Repository: zookeeper
Updated Branches:
  refs/heads/master dcfbe4524 -> 9e30b9bf8


ZOOKEEPER-2950: Add keys for the Zxid from the stat command to check_zookeeper.py

Add keys for the zxid and its component pieces: epoch and transaction counter. These are not reported by the 'mntr' command so they must be obtained from 'stat'. The counter is useful for tracking transaction rates, and epoch is useful for tracking leader churn.

 zk_zxid         - the 64bit zxid from ZK
 zk_zxid_counter - the lower 32 bits, AKA the counter
 zk_zxid_epoch   - the upper 32 bits, AKA the epoch

Author: Alex Bame <al...@724support.com>

Reviewers: phunt@apache.org

Closes #425 from alexbb/add_zxid_stats and squashes the following commits:

8dfdc9fc [Alex Bame] leave zk_zxid in hex
874628db [Alex Bame] add keys for the Zxid from the stat command:  zk_zxid         - the 64bit zxid from ZK  zk_zxid_counter - the lower 32 bits, AKA the counter  zk_zxid_epoch   - the upper 32 bits, AKA the epoch

Change-Id: I5b43b8e27deab23669c7b44f777ddb02f50db4aa


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/9e30b9bf
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/9e30b9bf
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/9e30b9bf

Branch: refs/heads/master
Commit: 9e30b9bf8fac56db3846c8cc42997cdc23a9358d
Parents: dcfbe45
Author: Alex Bame <al...@724support.com>
Authored: Tue Dec 12 10:44:32 2017 -0800
Committer: Patrick Hunt <ph...@apache.org>
Committed: Tue Dec 12 10:44:32 2017 -0800

----------------------------------------------------------------------
 src/contrib/monitoring/check_zookeeper.py | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/9e30b9bf/src/contrib/monitoring/check_zookeeper.py
----------------------------------------------------------------------
diff --git a/src/contrib/monitoring/check_zookeeper.py b/src/contrib/monitoring/check_zookeeper.py
index c00db8b..568d517 100755
--- a/src/contrib/monitoring/check_zookeeper.py
+++ b/src/contrib/monitoring/check_zookeeper.py
@@ -169,11 +169,16 @@ class ZooKeeperServer(object):
     def get_stats(self):
         """ Get ZooKeeper server stats as a map """
         data = self._send_cmd('mntr')
+        stat = self._parse_stat(self._send_cmd('stat'))
         if data:
-            return self._parse(data)
+            mntr = self._parse(data)
+            missing = ['zk_zxid', 'zk_zxid_counter', 'zk_zxid_epoch']
+            for m in missing:
+                if m in stat:
+                    mntr[m] = stat[m]
+            return mntr
         else:
-            data = self._send_cmd('stat')
-            return self._parse_stat(data)
+            return stat
 
     def _create_socket(self):
         return socket.socket()
@@ -251,6 +256,13 @@ class ZooKeeperServer(object):
                 result['zk_znode_count'] = int(m.group(1))
                 continue
 
+            m = re.match('Zxid: (0x[0-9a-fA-F]+)', line)
+            if m is not None:
+                result['zk_zxid']         = m.group(1)
+                result['zk_zxid_counter'] = int(m.group(1), 16) & int('0xffffffff', 16) # lower 32 bits
+                result['zk_zxid_epoch']   = int(m.group(1), 16) >>32 # high 32 bits
+                continue
+
         return result 
 
     def _parse_line(self, line):