Adventures in Rrd4j

NOTE: The forum auto number settings screwed up my step numbering.

I thought I’d document my 2 hours ordeal of installing and setting up rrdj4 so that anyone Googling may come across this and find a similar issue with their setup and be able to follow along. I’ll start from beginning to end as much as I can remember. NOTE: I’m pretty clueless when it comes to programming and linux in general. I don’t claim to know what I’m doing so follow along at your own risk (and chuckle at my mistakes, it’s ok… I can laugh at myself too).

Setup: RPi2, OH1 installed via apt-get method. Other setups your folders may vary.

I started wanting to set up rrd4j due to needing a virtual switch restored on startup. I chose rrd4j because of multiple posts showing problems with that for other forms of persistence.

  1. I installed the Rrd4j binding via apt-get in the /usr/share/openhab/configurations/addons folder:
    sudo apt-get install openhab-addon-persistence-rrd4j
    and then changed ownership:
    sudo chown -hR openhab:openhab /usr/share/openhab

  2. In the openhab.cfg file in /usr/share/openhab/configurations I made sure default persistence was set to “rrd4j” in the general section. I did not make any changes to the rrd4j section in Persistence, leaving all as default.

    Now where things go slightly wrong…

  3. I created a file “rrd4j.persist” in the /usr/share/openhab/configurations/persistence folder and inserted the following code:
    Strategies {
    everyMinute:"0 * * * * ?"
    everyHour : "0 0 * * * ?"
    everyDay : “0 0 0 * * ?”

         default = everyChange
    
     }
    
     Items {
         * : strategy = everyChange, restoreOnStartup
     }
    

Note: For testing it out, I just figured I’d do every item.
I once again set ownership:
sudo chown -hR openhab:openhab /usr/share/openhab

There may be a better way to do ownership but I really don’t know. I just found it easy to do the ownership commands any time I make a new file.

  1. At this point I stopped, and restarted openhab:
    sudo /etc/init.d/openhab stop sudo /etc/init.d/openhab start
    I waited for a few 5 minutes or so for everything to load and the rrdj4 database to start populating and stopped/restarted again.
    sudo /etc/init.d/openhab stop sudo /etc/init.d/openhab start

  2. At this point, VICTORY (or so I thought). My virtual switch restored status on restart. I then went to Habmin to check out the “Persistence” section and… nothing. So, half success. I started Googling and in 15 minutes had 15 or so browser tabs full of posts about Rrd4j. None though had the issue where NO items were in Habmin’s Persistence section. Some had items there but no data, this was different… nothing was showing up.

  3. I confirmed that the database was being populated in the /var/lib/openhab/persistence/rrd4j folder. Files were being created so I knew the data was being collected.

  4. After going trough the posts, I saw that I needed the “everyMinute” strategy in place so I added it to the rrd4j.persist file.
    `Strategies {
    everyMinute:"0 * * * * ?"
    everyHour : "0 0 * * * ?"
    everyDay : “0 0 0 * * ?”

         default = everyChange
    
     }
    
     Items {
         * : strategy = everyMinute, everyChange, restoreOnStartup
     }`
    
  5. I restarted Openhab again:
    sudo /etc/init.d/openhab stop sudo /etc/init.d/openhab start

  6. Nothing. Same situation. Item status was being retained but no items were showing up in Habmin Persistence. I then noticed that people used items in groups so I figured I’d try that and altered the rrd4j.persist file again:
    `Strategies {
    everyMinute:"0 * * * * ?"
    everyHour : "0 0 * * * ?"
    everyDay : “0 0 0 * * ?”

         default = everyChange
    
     }
    
     Items {
         * : strategy = everyChange, restoreOnStartup
         gPersist* : strategy = everyMinute, everyChange, restoreOnStartup
     }`
    

Note: I took everyMinute off the general item strategy as I didn’t need my switches recorded every minute and I added the “gPersist” group to certain items like temperature and humidity sensors in their respective item files.

  1. Stop/start once again:
    sudo /etc/init.d/openhab stop sudo /etc/init.d/openhab start
    SAME RESULT!!! No items populating in Habmin Persistence. Now I’m just blankly looking at the screen. Hitting refresh on the Habmin page hoping beyond hope they’ll just show up. I’m starting to pull at my remaining hair. I didn’t mention, but it is also 1:30 am (or 0130 for my international friends).

  2. Finally, after just a fluke guess, I decided to alter the rrd4j.persist file slightly. I put the group line ABOVE the item line:
    `Strategies {
    everyMinute:"0 * * * * ?"
    everyHour : "0 0 * * * ?"
    everyDay : “0 0 0 * * ?”

        default = everyChange
    
    }
    
    Items {
         gPersist* : strategy = everyMinute, everyChange, restoreOnStartup
         * : strategy = everyChange, restoreOnStartup
    }`
    
  3. Stop/Start once again:
    sudo /etc/init.d/openhab stop sudo /etc/init.d/openhab start
    MAGIC!!! SUCCESS!! All of a sudden all of my items in the gPersist group show up in Habmin.

So the tl/dr version is…
Rrd4j does not need everyMinute to simply restore item state on startup.
It does need everyMinute to chart.
Only grouped items show up in Habmin.
Groups must be above all wildcard items in rrdj4.persist file.

I hope this helps somebody. There are so many guides out there that it is easy to get lost as everyone has different configurations. Any questions feel free to ask, I tried to write this from memory and I’m not currently at my home computer to double check the files but I think I got everything.

Nice posting. The only thing I would add is that the restarts of OH were probably not needed.

Thanks, probably but I can never remember what files are automatically updated and what needs a restart. Often I’ve made changes and wondered why it wasn’t working only to have a restart fix it.

Now I don’t guess unless I see an update automatically in Designer.

@RHINESEL, very nice post, thanks so much. Apologies if the following is really too common to be mentioned here, but I recently (thanks to the tips on this forum) started having a Terminal window open where I am running

tail -f /var/log/openhab2/openhab.log 

This way I can watch the log file as it gets written. This immediately gives some feedback, such as message that the items, rules, sitemap files were updated and the errors associated with it, so I can fix them immediately.

Great hint, I always forget about running a log!

This is indeed very important. It’s also documented in the obvious place :innocent: http://docs.openhab.org/installation/linux.html#viewing-log-messages