How do create a graph of how long a device was on for the day, week, month?

The fact you are using MySQL verses one of the embedded DBs puts you in a better position than most. I’d create a cron job that runs a script that clears out any data older than a certain age periodically. How often and how old the data must be depends largely on what you are doing with this data.

Personally I use rrd4j. I don’t really care if the precision of the data gets worse as the data ages and it is a small price to pay to have a DB that I don’t have to clear out.

Another alternative, more work but less DB intensive, is to write rules to keep a running total of your useage. It is not terrible easy to do but there is an example here:

1 Like