X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=contrib%2Fpostgresql%2Fcollectd_insert.sql;h=00c5519b7a211cdfde7f283aa528805020f93dc3;hb=5090238f2bd3761778a19ef3f5e9d32911444324;hp=e20b0bf1e64b1ab3f3024c936f0e3db8dc9484fb;hpb=fb21b66983a3f8303eb33dd5d2436922dffff6bb;p=collectd.git diff --git a/contrib/postgresql/collectd_insert.sql b/contrib/postgresql/collectd_insert.sql index e20b0bf1..00c5519b 100644 --- a/contrib/postgresql/collectd_insert.sql +++ b/contrib/postgresql/collectd_insert.sql @@ -85,11 +85,31 @@ CREATE INDEX identifiers_type_inst ON identifiers USING btree (type_inst); CREATE TABLE "values" ( id integer NOT NULL, - tstamp timestamp without time zone NOT NULL, + tstamp timestamp with time zone NOT NULL, name character varying(64) NOT NULL, value double precision NOT NULL ); +CREATE OR REPLACE VIEW collectd + AS SELECT host, plugin, plugin_inst, type, type_inst, + host + || '/' || plugin + || CASE + WHEN plugin_inst IS NOT NULL THEN '-' + ELSE '' + END + || coalesce(plugin_inst, '') + || '/' || type + || CASE + WHEN type_inst IS NOT NULL THEN '-' + ELSE '' + END + || coalesce(type_inst, '') AS identifier, + tstamp, name, value + FROM identifiers + JOIN values + ON values.id = identifiers.id; + -- partition "values" by day (or week, month, ...) -- create the child tables for today and the next 'days' days: @@ -97,7 +117,7 @@ CREATE TABLE "values" ( -- the tables for the next couple of days CREATE OR REPLACE FUNCTION values_update_childs( integer - ) RETURNS integer + ) RETURNS SETOF text LANGUAGE plpgsql AS $_$ DECLARE @@ -105,14 +125,12 @@ DECLARE cur_day date; next_day date; i integer; - n integer; BEGIN IF days < 1 THEN RAISE EXCEPTION 'Cannot have negative number of days'; END IF; i := 0; - n := 0; LOOP EXIT WHEN i > days; @@ -130,8 +148,7 @@ BEGIN CONTINUE; END; - RAISE INFO 'Created table "values$%"', cur_day; - n := n + 1; + RETURN NEXT 'values$' || cur_day::text; EXECUTE 'ALTER TABLE ONLY "values$' || cur_day || '" ADD CONSTRAINT "values_' || cur_day || '_pkey" @@ -140,7 +157,7 @@ BEGIN ADD CONSTRAINT "values_' || cur_day || '_id_fkey" FOREIGN KEY (id) REFERENCES identifiers(id)'; END LOOP; - RETURN n; + RETURN; END; $_$; @@ -171,7 +188,7 @@ CREATE TRIGGER insert_values_trigger -- SET constraint_exclusion = on; CREATE OR REPLACE FUNCTION collectd_insert( - timestamp, character varying, + timestamp with time zone, character varying, character varying, character varying, character varying, character varying, character varying[], character varying[], double precision[]