Compare commits

...

5 Commits

Author SHA1 Message Date
29bfd07dad
Run code through black 2025-07-14 01:58:08 -04:00
60589c2058
Update undiscovered item behavior 2025-07-14 01:39:57 -04:00
ea3aca3455
Filter out initial logical replication sync workers
* Slots are crated for each table during the initial sync, which only
  live for the duration of the copy for that table.

* The initial sync backend workers' names are also based on the table
  being copied.

* Filter out the above in Zabbix discovery based on application_name and
  slot_name.
2025-07-07 13:15:03 -04:00
cc71547f5f
Include application_name in replication discovery data 2025-07-07 13:07:11 -04:00
107d5056d6
Merge branch 'main' into develop 2025-07-06 03:37:37 -04:00
4 changed files with 43 additions and 13 deletions

View File

@ -18,6 +18,7 @@ metrics:
query:
0: >
SELECT host(client_addr) || '_' || regexp_replace(application_name, '[ ,]', '_', 'g') AS repid,
application_name,
client_addr,
state
FROM pg_stat_replication

View File

@ -400,7 +400,7 @@ def json_encode_special(obj):
"""
if isinstance(obj, Decimal):
return float(obj)
raise TypeError(f'Cannot serialize object of {type(obj)}')
raise TypeError(f"Cannot serialize object of {type(obj)}")
def run_query_no_retry(pool, return_type, query, args):
@ -424,7 +424,9 @@ def run_query_no_retry(pool, return_type, query, args):
elif return_type == "column":
if len(res) == 0:
return "[]"
return json.dumps([list(r.values())[0] for r in res], default=json_encode_special)
return json.dumps(
[list(r.values())[0] for r in res], default=json_encode_special
)
elif return_type == "set":
return json.dumps(res, default=json_encode_special)
except:
@ -667,7 +669,12 @@ def test_queries():
for name, metric in config["metrics"].items():
# If the metric has arguments to use while testing, grab those
args = metric.get("test_args", {})
print("Testing {} [{}]".format(name, ", ".join(["{}={}".format(key, value) for key, value in args.items()])))
print(
"Testing {} [{}]".format(
name,
", ".join(["{}={}".format(key, value) for key, value in args.items()]),
)
)
# When testing against a docker container, we may end up connecting
# before the service is truly up (it restarts during the initialization
# phase). To cope with this, we'll allow a few connection failures.

View File

@ -795,17 +795,17 @@ metrics:
def test_json_encode_special(self):
# Confirm that we're getting the right type
self.assertFalse(isinstance(Decimal('0.5'), float))
self.assertTrue(isinstance(pgmon.json_encode_special(Decimal('0.5')), float))
self.assertFalse(isinstance(Decimal("0.5"), float))
self.assertTrue(isinstance(pgmon.json_encode_special(Decimal("0.5")), float))
# Make sure we get sane values
self.assertEqual(pgmon.json_encode_special(Decimal('0.5')), 0.5)
self.assertEqual(pgmon.json_encode_special(Decimal('12')), 12.0)
self.assertEqual(pgmon.json_encode_special(Decimal("0.5")), 0.5)
self.assertEqual(pgmon.json_encode_special(Decimal("12")), 12.0)
# Make sure we can still fail for other types
self.assertRaises(
TypeError, pgmon.json_encode_special, object
)
self.assertRaises(TypeError, pgmon.json_encode_special, object)
# Make sure we can actually serialize a Decimal
self.assertEqual(json.dumps(Decimal('2.5'), default=pgmon.json_encode_special), '2.5')
self.assertEqual(
json.dumps(Decimal("2.5"), default=pgmon.json_encode_special), "2.5"
)

View File

@ -167,7 +167,8 @@ zabbix_export:
operator: NOT_MATCHES_REGEX
formulaid: A
lifetime: 30d
enabled_lifetime_type: DISABLE_NEVER
enabled_lifetime_type: DISABLE_AFTER
enabled_lifetime: 1d
item_prototypes:
- uuid: a30babe4a6f4440bba2a3ee46eff7ce2
name: 'Time spent executing statements on {#DBNAME}'
@ -982,6 +983,9 @@ zabbix_export:
type: DEPENDENT
key: pgmon_discover_io_backend_types
delay: '0'
lifetime: 30d
enabled_lifetime_type: DISABLE_AFTER
enabled_lifetime: 1h
item_prototypes:
- uuid: b1ac2e56b30f4812bf33ce973ef16b10
name: 'I/O Evictions by {#BACKEND_TYPE}'
@ -1572,8 +1576,15 @@ zabbix_export:
type: HTTP_AGENT
key: pgmon_discover_rep
delay: 10m
filter:
conditions:
- macro: '{#APPLICATION_NAME}'
value: '^pg_[0-9]+_sync_[0-9]+_[0-9]+$'
operator: NOT_MATCHES_REGEX
formulaid: A
lifetime: 30d
enabled_lifetime_type: DISABLE_NEVER
enabled_lifetime_type: DISABLE_AFTER
enabled_lifetime: 7d
item_prototypes:
- uuid: 3a5a60620e6a4db694e47251148d82f5
name: 'Flush lag for {#REPID}'
@ -1775,6 +1786,8 @@ zabbix_export:
value: Raw
url: 'http://localhost:{$AGENT_PORT}/discover_rep'
lld_macro_paths:
- lld_macro: '{#APPLICATION_NAME}'
path: $.application_name
- lld_macro: '{#CLIENT_ADDR}'
path: $.client_addr
- lld_macro: '{#REPID}'
@ -1786,6 +1799,15 @@ zabbix_export:
type: HTTP_AGENT
key: pgmon_discover_slots
delay: 10m
filter:
conditions:
- macro: '{#SLOT_NAME}'
value: '^pg_[0-9]+_sync_[0-9]+_[0-9]+$'
operator: NOT_MATCHES_REGEX
formulaid: A
lifetime: 30d
enabled_lifetime_type: DISABLE_AFTER
enabled_lifetime: 7d
item_prototypes:
- uuid: 536c5f82e3074ddfbfd842b3a2e8d46c
name: 'Slot {#SLOT_NAME} - Confirmed Flushed Bytes Lag'