Skip to content

Commit

Permalink
Keep the stats of unhealty replica and add the timeline info
Browse files Browse the repository at this point in the history
  • Loading branch information
blogh committed Sep 28, 2023
1 parent cee0ff8 commit ea8541d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions check_patroni/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def cluster_has_replica(
),
nagiosplugin.ScalarContext("unhealthy_replica"),
nagiosplugin.ScalarContext("replica_lag"),
nagiosplugin.ScalarContext("replica_timeline"),
nagiosplugin.ScalarContext("replica_sync"),
)
check.main(verbose=ctx.obj.verbose, timeout=ctx.obj.timeout)
Expand Down
18 changes: 11 additions & 7 deletions check_patroni/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ def probe(self: "ClusterHasReplica") -> Iterable[nagiosplugin.Metric]:
# Look for replicas
for member in cluster_item_dict["members"]:
if member["role"] in ["replica", "sync_standby"]:
replicas.append(
{
"name": member["name"],
"lag": member["lag"],
"timeline": member["timeline"],
"sync": 1 if member["role"] == "sync_standby" else 0,
}
)
if (
(has_streaming_state and member["state"] == "streaming")
or (
Expand All @@ -137,13 +145,6 @@ def probe(self: "ClusterHasReplica") -> Iterable[nagiosplugin.Metric]:
and member["timeline"] == leader_tl
)
) and member["lag"] != "unknown":
replicas.append(
{
"name": member["name"],
"lag": member["lag"],
"sync": 1 if member["role"] == "sync_standby" else 0,
}
)

if member["role"] == "sync_standby":
sync_replica += 1
Expand All @@ -163,6 +164,9 @@ def probe(self: "ClusterHasReplica") -> Iterable[nagiosplugin.Metric]:
yield nagiosplugin.Metric(
f"{replica['name']}_lag", replica["lag"], context="replica_lag"
)
yield nagiosplugin.Metric(
f"{replica['name']}_timeline", replica["timeline"], context="replica_timeline"
)
yield nagiosplugin.Metric(
f"{replica['name']}_sync", replica["sync"], context="replica_sync"
)
Expand Down

0 comments on commit ea8541d

Please sign in to comment.