How to purge/delete data point history programmatically
-
Can you, from a meta data point script, purge the history of another data point? How?
Thanks -
@till yes you can but it will require accessing Mango Java classes. There are many examples of loading Java classes into the script engine in this forum so please read up on those first.
The basic idea is to get access to the Common class and the data point VO you want to purge and use one of these methods:
/** * Purge values before a given time * @param vo data point VO * @param before epoch timestamp in ms * @return count of values deleted */ long purgeDataPointValues(DataPointVO vo, long before); /** * Purge values between a time range inclusive of startTime exclusive of endTime * @param vo data point VO * @param startTime epoch timestamp in ms * @param endTime epoch timestamp in ms * @return count of values deleted */ long purgeDataPointValuesBetween(DataPointVO vo, long startTime, long endTime); /** * Purge values before a given time * @param vo data point VO * @param before epoch timestamp in ms * @return true if any data was deleted */ boolean purgeDataPointValuesWithoutCount(DataPointVO vo, long before);
So your code will have something like this in it for the purge, note the syntax may be wrong as I'm doing this from memory:
var Common = Java.type('com.serotonin.m2m2.Common'); //--- get data point vo here -- var vo = {}; var before = 0; var purged = Common.purgeDataPointValues(vo, before);
-
Thanks @terrypacker,
I'll read up on this. -
@terrypacker, I had abit of a look.
I realise that I can actually avoid this if there's an option to only keep the last (few) value(s) in the database and purge everything else.
Of course there is the purge option in a data point but it's not very much customisable. Setting it to purge daily (fixed at 3.05am apparently) is too often but weekly is not often enough. Ideally I just keep a single value.
Even better would be a way to only update the current value and not create a history of values in the first place. I'll never need any historic value, just the current one. Is there a setting or a specific data point type that allows this? I currently use a virtual data point.
Thanks!
-
You can set the logging setting on your data point to not log any values.
-
@joelhaggar Many thanks for your swift responses.
I expected no logging to not hold the value for long enough for my purpose. But that works - currently.
This way it's storing the value in memory only, instead of in the database, right? So in a fault situation, resulting in a Mango restart, that value is gone?
Cheers
-
@till That is correct. The value will be held in the cache. You can even set the data point to hold x number of values in the cache so there is some history there.