influxDB 1.2.2 retention policy

Hi,
is it possible to use different retention policy for different items, or the retention policy in influxdb.cfg is always used?

Thanks

1 Like

Since the persistence configuration file (e.g. influxdb.persist in this case) does not have an option to set the retention policy per Items line… the answer must be no (99% sure… not 100%) :slight_smile:

1 Like

Hi @marcolino7,
There is the retention policy in influxdb.cfg, but why use it (thanks @Dim)?
The retention of states in the database (meaning the startegy persistance of items’ states) is declared only in the influxdb.persist (manually written file) located in the conf directory (as per the manual installation of OH2), or in the /etc/openhab2 (when using apt).
More info here. It 's the redirection from here.

Best regards,

George

To limit the growing database to a certain amount.
I only need the last 180 days, so I’ve set my retention policy to 190 days …

Yes, true! But then, you do not really need a database for that (I mean a system with queries. etc.)!
Just my two cents!
BR,

George

If I want to show the highest/lowest temperature from the last 180 days: yes :grinning:

1 Like

Hi @george.erhan @Dim
@sihui has right. I want to keep into database only last 180 days of roof and basement temperature, but last 3 year for rest of my house. I would like to keep for 5 year radiation level and so on.
Would be better to have te ability to apply different InfluxDB retetention policy for every Items or groups.
as I understood is not possible at all for now. Can this be an feature request?

Regards

Marco

Of course you can raise such feature request but think about the following:

a) How many people will actually need (and use) such (advanced) feature?
b) The default retention policy in an Influx time series database has infinite retention
c) You could manage your stored data within Influx by deleting series older than x days/months/years from your measurements

So, imho the cost/benefit of developing such feature is not really worth it :stuck_out_tongue:

For (c) above, see also here: https://docs.influxdata.com/influxdb/v1/query_language/manage-database/
One solution would be to create a cron job that deletes every month older data from selected areas within InfluxDB.

To store the data into influxdb I’m using a simple rule to create a http post call using it’s inline protocol. Using this way you’ll be able to store data using all the options such as retention policy.

I put all the items that have to be stored in a group so i can write a more or less generic rule:

rule "Save Energy into influxdb"
when
	Time cron "0 * * * * ?"
then
	var data = "gInfluxEnergy"
	var ts = now.getMillis()
	var space = " "
	gInfluxEnergy?.members.forEach[s |
		var value = s.state as DecimalType
		data = data + space + s.name + "=" + value
		space = ","
	]
	data = data + " " + ts
	logInfo("Save Energy into influxdb", data)
	sendHttpPostRequest("https://<server>:8086/write?db=<db>&u=<user>&p=<password>&precision=ms", "text/plain", data)
end

The full spec for the POST API is here:

1 Like

Is there a solution for this?
I would also like to do the same.

No.
You are only able to use one retention policy

Just revisiting this since I started adding some retention policies on my data (as I was moving influx to a new server and wanted to drop the data footprint somewhat).

So on seeing that there is only a single retention policy that is set (or just use the default), I believe you might be able to get varying retention policies by using constant queries to roll up and insert data from one table (with a default = eg 180 day retention period) to a destination table that could have the same or different retention period.

Yes, the CQ’s work just fine. I have 4 or 5 running myself. But Fulvio’s post is helpful because there are additional features in InfluxDB that are not available in the binding such as tags and multiple fields which you could put into his rule.