From: Chris Brown Date: Fri, 9 Nov 2018 00:58:43 +0000 (-0800) Subject: Add 'quorum' stat to ZooKeeper plugin so that alerts are able to tell the difference... X-Git-Tag: collectd-5.11.0~13^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86375ffa31324584b0dde5c20cfb208010dc4fe0;p=thirdparty%2Fcollectd.git Add 'quorum' stat to ZooKeeper plugin so that alerts are able to tell the difference between data lag and loss of quorum. --- diff --git a/src/zookeeper.c b/src/zookeeper.c index a99bbc01c..6309b19d4 100644 --- a/src/zookeeper.c +++ b/src/zookeeper.c @@ -176,6 +176,7 @@ static int zookeeper_read(void) { char *save_ptr; char *line; char *fields[2]; + long followers = -1; if (zookeeper_query(buf, sizeof(buf)) < 0) { return -1; @@ -218,15 +219,23 @@ static int zookeeper_read(void) { } else if (FIELD_CHECK(fields[0], "zk_approximate_data_size")) { zookeeper_submit_gauge("bytes", "approximate_data_size", atol(fields[1])); } else if (FIELD_CHECK(fields[0], "zk_followers")) { - zookeeper_submit_gauge("count", "followers", atol(fields[1])); + followers = atol(fields[1]); + zookeeper_submit_gauge("count", "followers", followers); } else if (FIELD_CHECK(fields[0], "zk_synced_followers")) { zookeeper_submit_gauge("count", "synced_followers", atol(fields[1])); } else if (FIELD_CHECK(fields[0], "zk_pending_syncs")) { zookeeper_submit_gauge("count", "pending_syncs", atol(fields[1])); + } else if (FIELD_CHECK(fields[0], "zk_server_state")) { + if (followers < 0) { + followers = 0; + } } else { DEBUG("Uncollected zookeeper MNTR field %s", fields[0]); } } + /* Reports 0 for followers, -1 for no zk_server_state, # when zk_followers present. */ + /* Intended to be used for quorum detection by taking max for each time period. */ + zookeeper_submit_gauge("count", "quorum", followers); return 0; } /* zookeeper_read */