Query rrd4j via REST API

Hi all,

to create a custom graph I try to query rrd4j with a given start time stamp (to be able to plot the last day, week, month … etc). When I try request using a starttime I always get exactly 24 data points. Strangely the time stamps (according to my calculations, which might be wrong) do not match the period I requested:

http://haus:8080/rest/persistence/items/ItemServerCpuLoad?serviceId=rrd4j&starttime=2017-02-05T12%3A00%3A00.000

Reponse:

{
  "name": "ItemServerCpuLoad",
  "datapoints": "24",
  "data": [
    {
      "time": 1495670400000,
      "state": "22.713272311212794107859735959209501743316650390625"
    },
    {
      "time": 1495713600000,
      "state": "5.1359722222222199405905485036782920360565185546875"
    },
    {
...
    },
    {
      "time": 1496664000000,
      "state": "10.587078651685398966719731106422841548919677734375"
    }
  ]
}

Which seems to be from “Thursday, May 25th 2017” to “Monday, June 5th 2017, 12:00:00”. Any advice what I do wrong here?

thanks & kind regards,
Patrik

rrd4j databases are a bit different! Depending on the startime you request, or better the time difference between now and the requested time, rrd4j will use that archive that fits. In your case the starttime is outside the first archive, which holds values for every minute. You can calculate the timestamps for that archive by the difference in timestamps.
Why don’t you use the standard charts? They will let you show the data as for the last day, week month. I did change my rrd4j setup in order to to persist exactly those timeframes as opposed to the default setup that holds data for years.
You are probably using this default setting and you are requesting from the archive that has one value for every12 houses.

Hi Jürgen (@opus),

thank you for your explanation. I try to beef up my classic ui with web elements:

The default charts work fine - but as said to give the UI more color I’ve started to add more and more webview stuff :slight_smile:.

I’ll try another persistence service for those use cases & mark this as solved once I’ve this working.

with many thanks & kind regards,
Patrik

To be more specific, rrd4j does hold the data for each minute ONLY in the first archive. Beyond the timeframe of the first archive archive there are no minute-values!
rrd4j is build exactly for that, it will compress the data,hence NOT holding all specific data. Beyond the first archive data will be compressed (like maximum in this timegap or average or…).
That is selectable by the user, although most people just use the default setting.

2 Likes

Sorry for late reply, however your picture made me think.
I do see no reason to change the persistence service for the usage you show. At least if I understand correctly. I would see charts displaying value for the last 24 h, last week last month. . That would be fine with rrd4j. A usage like the values of the 24 houres starting two weeks ago would not. In other words as long as you are trying to get data from now backwards to some point in time rrd4j can help you. The longer the time you are going back, the less detailed the data could be ( could be, because that is configurable).
As said before, I’m using rrd4j exactly that way for logging and displaying price data. Running for over a year now, the size of the database won’t change!

Hi Jürgen (@opus),

thank you for your reply & help. It works now with rrd4j; I made a stupid mistake during the time stamp calculation in my js … getMonth() returns 0 for Januar - thus I always requested way too much data by not added +1 … thus the answer did not match my expectations in precision and range.

with kind regards,
Patrik