Skip to content

Commit

Permalink
Merge pull request #61 from cybertec-postgresql/monitoring_fix_pgback…
Browse files Browse the repository at this point in the history
…rest

add function for pgbackrest-data
  • Loading branch information
Schmaetz authored Nov 26, 2024
2 parents acef3d2 + 644066f commit e726ef2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion pkg/cluster/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,40 @@ const (
CREATE EXTENSION IF NOT EXISTS pgnodemx with SCHEMA exporter;
alter extension pgnodemx UPDATE;
CREATE TABLE IF NOT EXISTS exporter.pgbackrestbackupinfo (
name text NOT NULL,
data jsonb NOT NULL,
data_time timestamp with time zone DEFAULT now() NOT NULL
)
WITH (autovacuum_analyze_scale_factor='0', autovacuum_vacuum_scale_factor='0', autovacuum_vacuum_threshold='2', autovacuum_analyze_threshold='2');
ALTER TABLE exporter.pgbackrestbackupinfo OWNER TO cpo_exporter;
CREATE OR REPLACE FUNCTION exporter.update_pgbackrest_info()
RETURNS VOID AS $$
DECLARE
last_entry_timestamp TIMESTAMP;
record_count INT;
BEGIN
SELECT COUNT(*) INTO record_count
FROM exporter.pgbackrestbackupinfo;
IF record_count > 0 THEN
SELECT data_time INTO last_entry_timestamp
FROM exporter.pgbackrestbackupinfo
ORDER BY data_time DESC
LIMIT 1;
IF last_entry_timestamp < NOW() - INTERVAL '5 minutes' THEN
DELETE FROM exporter.pgbackrestbackupinfo;
ELSE
RETURN;
END IF;
END IF;
EXECUTE format(
'COPY exporter.pgbackrestbackupinfo (data) FROM program ''pgbackrest info --output=json'' WITH (FORMAT text, DELIMITER ''|'')'
);
END;
$$ LANGUAGE plpgsql;
`
)

Expand Down

0 comments on commit e726ef2

Please sign in to comment.