-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgresql output plugin (for using with timescaledb) #3408
Comments
+1 |
I've written an output plugin for postgresql. Let me know if you need any other features. PR #3428 |
It's, cool!. Can you add a more flexible way of creating the tables? For example: when creating the tables for using with timescaledb, after the table creation, but before the first insertion, you need to execute a command that create the table partition. By example: CREATE TABLE conditions (
time TIMESTAMPTZ NOT NULL,
location TEXT NOT NULL,
temperature DOUBLE PRECISION NULL,
humidity DOUBLE PRECISION NULL
);
SELECT create_hypertable('conditions', 'time'); Another use case: using pg 10 and want to use a automatic partitioned table or citusdb with a sharded table. I know that I can create the tables manually, but if I need a lot of metrics then it will imply a lot of repetitive sql writing. Maybe a template parameter for table creation can solve this or a post_create_hook for execute a command giving the table's name and the primary key attribute. |
I guess a template is most flexible as a post_create_hook wouldnt help much with pg10 partitioning. |
I like the template idea, and we won't want to add an output which is not generally usable in many use cases. If you design a template configuration please post it here for comments. |
I was thinking about having the following placeholders: The template syntax is just a suggestion but curly braces shouldnt conflict with any SQL. Example Templates-- Default Value
CREATE TABLE {TABLE}({COLUMNS},PRIMARY KEY({PK_COLUMNS}));
-- PostgreSQL 10 Partitioning by year and month
CREATE TABLE {TABLE}({COLUMNS}) PARTITION BY RANGE (EXTRACT(YEAR FROM time),EXTRACT(MONTH FROM time));
-- Timescale
CREATE TABLE {TABLE}({COLUMNS});
SELECT create_hypertable({TABLENAME}, 'time'); |
Would a user need to design tables for every input? |
Awesome! |
The metric name is used as table name so every input plugin gets its own table. But the user would choose one of the 3 different example templates (or create their own) and the plugin would use those for all metricts and fill out the placeholder values with the metric specific stuff. |
Would the user need to specify all the columns in order to create the table? |
No the user wouldnt specify the columns, he would use the {COLUMNS} placeholder where he wants the columns to be in the statement. The plugin would replace {COLUMNS} with the actual columns used in the measurement. |
What if the fields on the measurement are dynamic and new fields are added after the table is created? |
I was reading the adaptor for prometheus from the same guys of timescaledb and there they use jsonb for the metrics. That way the metrics can be added dynamically. |
I was thinking about having an option for jsonb tags and values, but otherwise new fields would have to result in an alter table statement and wouldnt use the template. |
While some inputs create a static set of fields, quite a few of them create fields dynamically. I would imagine the alter table design would be tricky to get right, we would need to load the current table schema on startup in order to know when to alter, and when you factor in many telegraf agents it gets harder. You might also be interested in looking at the CrateDB output we recently added, it is almost compatible with postgres but has some differences. #3210 |
Ok havnt used any plugins with dynamic fields so i thought all plugins would handle dynamic stuff with tags. Using jsonb fields for tags and values would solve the dynamic field problem. I've seen the cratedb plugin it uses the postgres protocol but has different datatypes from what i've seen. Using jsonb probably matches the cratedb types most closely. |
I think that using jsonb for metrics is better, in the worst case it can be configurable too (dynamicFields: bool [true as default]) |
I have added support for jsonb tags and jsonb fields and made using jsonb the default. |
hooray! Merge it! |
Can someone please post a schema needed to get this up and running?
|
I've made my own stab at this one as well, combining the two with some optimizations. The plugin tries to combine items with the same timestamp into the same table, but also asks that the table be created first. This is still a work in progress, that I don't know that I'll continue with because it served my purposes to find out timescale didn't have the performance that influxdb did. Comments are welcome. https://github.com/srclosson/telegraf/tree/timescale/plugins/outputs |
Any updates on this? Will the Postgres output plugin be included in the 1.7 release? Any idea on availability? |
I am currently using the version from https://github.com/svenklemm/telegraf/tree/postgres which has been recently updated. |
@svenklemm Have you seen any issues with Telegraf storing the fields column as jsonb? Using your latest update here: https://github.com/svenklemm/telegraf/tree/postgres, I have a working configuration with metrics being output in individual columns successfully with jsonb = false. When enabled, the fields column is correctly initialized as jsonb, but all rows for fields and tags are null, only time is populated. |
Hi, |
Hi |
+1 |
No description provided.
The text was updated successfully, but these errors were encountered: