Dear all,
I do have an item that fetches an update every second or less.
To not overload the persistence service InfluxDB, I would like to persist the change only every 5 seconds.
Currently my strategy is:
Items {
* : strategy = everyChange
}
How can I change the strategy for only a single item e.g. to persist the change every 5 minutes.
Just to elaborate a bit on @HFM’s answer. The * under Items will apply to every Item. So your .persist file will need two entries, one which has the everyChange applied to every Item except this one Item and another one that has the every5Seconds strategy. To accomplish this the easiest way is to use Groups.
You can’t. You have to list all the Items but the one for one strategy and just the one Item for the other strategy. You have a bit more control and it’s a little easier if you use Groups. then you can use MyGroup* for the one strategy and all members of that Group will be persisted based on that strategy.
var runtime = (typeof(require) === "function") ? require("@runtime") : {
itemRegistry: itemRegistry,
events: events,
items: items,
DateTimeType: DateTimeType
};
// filter Items by Type
var filteredItems = utils.javaSetToJsArray(runtime.itemRegistry.getItems().stream().filter((i) => { return i.type.indexOf("Rollershutter") >= 0; }));
console.log("FilterdItems Length " + filteredItems.length);
for (var i = 0; i < filteredItems.length; i++) {
console.log("Item " + i );
console.log("Itemname " + filteredItems1[i].name);
console.log("ItemType " + filteredItems1[i].type);
console.log("ItemState " + filteredItems1[i].state);
console.log("ItemGroups" + filteredItems1[i].groupNames);
var tempItem = items.getItem(filteredItems1[i].name);
// add Group
tempItem.addGroups("gDatabaseRollershutter");
}
This example looks for all Rollershutter items and adds the group “gDatabaseRollershutter”. In my scenario I used it to put all Rollershutter items into a group, so that I can index them in a database.
Create a new Script or Rule
edit the types or adjust the filter expression to your needs
All these answers are all good, but is it really a problem to be writing to influxdb every second? Are you hitting any kind of performance issues as a consequence? If not, it will be a lot easier to simply leave it as-is.
Influxdb (on dedicated hardware) supports hundreds of thousands of writes per second.
To be honest, I do not know. I have 20 sensors with approximately 100 items which write on everyChange. So there is a lot of traffic, but I think it is a lot more than 1 second on average.
My approach has been to only store metrics for the things that I actually care about measuring by using a specific group. But then again, I’m generating the openhab configuration so it’s very easy to have various types of items automatically added to that group.
With influxdb you can enable a special “_internal” database that gives you metrics on influxdb itself. I haven’t tried it, but it but it might give you more data.