This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Get last value of trend
#1
Hi,

How do I fetch the last value of a trend?

I have a trend from which I would like periodically  get the last value as shown in the trend graph.

TIA
Reply
#2
Hi
Look here http://openrb.com/docs/trends-new.htm
BR
------------------------------
Ctrl+F5
Reply
#3
(06.02.2018, 13:37)Daniel. Wrote: Hi
Look here  http://openrb.com/docs/trends-new.htm
BR

I did...
I have a test script but I cannot figure out how to get the last value...

Thanks
Reply
#4
(06.02.2018, 13:42)baggins Wrote:
(06.02.2018, 13:37)Daniel. Wrote: Hi
Look here  http://openrb.com/docs/trends-new.htm
BR

I did...
I have a test script but I cannot figure out how to get the last value...

Thanks

In did, I couldn't get anything smaller than daily values.
------------------------------
Ctrl+F5
Reply
#5
You have to specify correct resolution in seconds, by default it is set to 1 day - 86400 seconds.
Reply
#6
(06.02.2018, 16:40)admin Wrote: You have to specify correct resolution in seconds, by default it is set to 1 day - 86400 seconds.

I'm still confused...
I took the example of the documentation and adapted where necessary:

Code:
require('trends')

dates = {
['start'] = { year = 2018, month = 2, day = 5},
['end'] = { year = 2018, month = 2, day = 6 },
}
--fetch current value
day = trends.fetch('CPU load', dates,300)
for i, v in ipairs(day) do log(i,v) end

This gives me 4 results. If I compare those results with the data in the trend, they don't match.

Result from script: 0,19, 0,12, 0,28, 0,34
Last 4 results in trend graph: 0,38, 0,33, 0.41, 0.33

I want to obtain the last result (0.33)...
Edit: if I run "day = trends.fetchone('CPU load', dates)" it returns 0.31 when at the same time in the graph is shows 0.1 as the latest value

BR
Reply
#7
Here you have what you looking forWink

Code:
require('trends')

-- get data for today
function returnLastTrendValue(trendName)
 dates = {}

 dates['start'] = os.date('*t')
 dates['start'].day = dates['start'].day - 1
 dates['end'] = os.date('*t')
 dates['end'].day = dates['end'].day + 1

 trends.NaN = '*'
 -- fetch previous value
 daily = trends.fetch(trendName, dates, 1)

 i = #daily
 while i > 0 do
   if daily[i] ~= '*' then return daily[i] end
   i=i-1
 end
end

lastValue = returnLastTrendValue('Your trend name')
log(lastValue)

I've tested Trends API some time ago and I've found that to have some data from today you must type not today timestamp but tomorrow and also 1 day before. The last value is the last measured value before midnight e.g. for 5minute resolution 23:55. For taking your maximum resolution you can type instead 86400 only 1. And then you should define undefined value from RRD db and ylou should look from 00:00 to first data which will appearWink
Reply
#8
Haha, I didn't realize it was that easy!   Wink 

Thanks a bunch!

BR
Reply
#9
Me tooWink
Reply


Forum Jump: