1 -- Written by Bob Cotton <bob.cotton@gmail.com>
2 -- This is free software; you can redistribute it and/or modify it under
3 -- the terms of the GNU General Public License as published by the Free
4 -- Software Foundation; only version 2 of the License is applicable.
5 drop table metrics cascade;
6 drop table hostname_dimension cascade;
7 drop table plugin_dimension cascade;
8 drop table type_dimension cascade;
9 drop type datasource_type cascade;
11 create type datasource_type as ENUM ('GUAGE', 'COUNTER');
13 create table metrics (id serial primary key,
15 measure double precision default 0,
16 hostname_id integer not null,
17 plugin_id integer not null,
18 type_id integer not null
21 create table hostname_dimension (id serial primary key,
22 hostname varchar(64) not null);
24 create table plugin_dimension (id serial primary key,
25 plugin varchar(64) not null,
26 plugin_instance varchar(64));
28 create table type_dimension (id serial primary key,
29 ds_type datasource_type,
30 type varchar(64) not null,
31 type_name varchar(64) not null,
32 type_instance varchar(64));
35 select create_partition_tables('metrics', now()::timestamp, '6 months'::interval, 'month', 'YYYY_MM');
36 select create_partition_trigger('metrics', now()::timestamp, '6 months'::interval, 'month', 'YYYY_MM');
37 CREATE TRIGGER insert_metrics_trigger BEFORE INSERT ON metrics FOR EACH ROW EXECUTE PROCEDURE metrics_insert_trigger();