0
votes

am using collectd to monitor the system metric .... For network metric I need to know what will be the incoming and the outgoing traffic per minute ...But Rx(total number of packets transmitted) and Tx(total number of packets received) packets is giving the data from since the machine is last rebooted...

So i need to query the influxdb to get the difference between current value and the previous value. How to query to get the difference.....

Am using the query like

select difference(last("value")) from interface_rx WHERE  "type" = 'if_octets' > now() - 1h group by time(10s)

Please help me ..Am not getting the exact output like i need

enter image description here

Am getting the following error when i used the query

Select difference(last("value")) from interface_rx WHERE "type" = 'if_octets' and time > now() - 1h group by time(1m)

enter image description here

enter image description here

1
In the upper right corner of Grafana where it says last 5 minutes; can you change it to last 1 hour? Also can you put your mouse cursor over the red indicator in the upper left corner to see the error message?Nikolay Manolov
@NikolayManolov I added the image above...pls help meShwettha RR
Hmm, what is the name of the field(table column) that you want to calculate the difference for? It seems like it is not value. In difference(last("value")) the value part should be the name of the actual field that you need. And it must be a field, not a tag.Nikolay Manolov
@NikolayManolov i attached the above picture of my influxdb data...My feild name is value....i need to the difference of every miniute from the previos valueShwettha RR

1 Answers

1
votes

It should be something like this

select difference(last("value")) from interface_rx WHERE "type" = 'if_octets' and time > now() - 1h group by time(1m)

This query should return about 60 values; 1 difference per minute for the past hour. The last in this case means that for every 1 minute period the last value is used (in case there are more than one)

Differences to your query: and time > now() - 1h was missing - this may have been an editing error but it did not seem valid. if you want the statistic per minute then you need to group by time(1m). You were grouping by 10 seconds so the result would have been the difference for every 10 seconds.

What you also may want to do is fill missing values with the previous available value (and respectively you'd get a zero for that period) select difference(last("value")) from interface_rx WHERE "type" = 'if_octets' and time > now() - 1h group by time(1m) fill(previous) EDIT: fill(previous) is probably not what you want though because if most recent values are not recorded yet they will be substituted with older ones and you'll get difference=0 as a most recent value.

If you only want the very last value you could do something like select difference(last("value")) from interface_rx WHERE "type" = 'if_octets' and time > now() - 1h group by time(1m) fill(previous) order by time DESC limit 1