Calculate from bytes/sec total amout of megabytes per day

hi, i try to calculate total of mb per day using value coming from network card in bytes/sec .

i need help or the logic.

when value change for exemple after 10 sec can i do (100 bytes/sec * 10 sec ) = 1000 bytes ?

or there is another way to calculate sum of data comming from bytes/sec ?

thanks for your help

If you know the time between the measurements, or if the time is deterministic (e.g. you’ll get an update each 10s), then you can calculate it like that.
Otherwise it is not really doable, since you need to get rid of the “per second” which usually means you have a time interval you can use.
Which binding are you using to get the information about the network card? Isn’t there any other channel that provides the total amount of data?

1 Like

i use data coming from node red,
I know the interval between each change, I use 2 epoch value to know the time of each change, then I multiply the value by the number of seconds

Here the rule:

rule "server Nuc_2 network trafic send"
when
    Item Nuc_2_Server_NetworkIntf_Send changed

then
    var  ZonedDateTime zdt = ZonedDateTime.now()// epoch time to date
    epochStart = zdt.toInstant.toEpochMilli  // create a epoch start`

if(Nuc_2_Server_NetworkIntf_Send_total.state == NULL)
     {   
      Nuc_2_Server_NetworkIntf_Send_total.postUpdate(Nuc_2_Server_NetworkIntf_Send_total.previousState(true,"influxdb").state)
     }
    else 
     {    
    if (epochend != 0 )
    {
     // to secondes then to megabytes
      val avg_send = ( ((Nuc_2_Server_NetworkIntf_Send.state as Number) * ((epochStart - epochend) / 1000)) / 1000000)  // to megabyte
      logInfo("epoch","avg_send=  " + avg_send + "mb")
      // adding calculated Mb to Send_total  
      Nuc_2_Server_NetworkIntf_Send_total.sendCommand(Nuc_2_Server_NetworkIntf_Send_total.state as Number + avg_send as Number)
      logInfo("epoch","Nuc_2_Server_NetworkIntf_Send_total=  " +(Nuc_2_Server_NetworkIntf_Send_total.state as Number))
    }
    
 //update today value since time
 Nuc_2_Server_NetworkIntf_Send_today.sendCommand(Nuc_2_Server_NetworkIntf_Send_total.deltaSince(now.with(LocalTime.of(0,0,0,0)),"influxdb") as Number)
     //epoch a la sortie de la rule pour comparer avec le passage suivant
 epochend = zdt.toInstant.toEpochMilli  // create a epoch end`
    }

I think that will work OK. You’ll probably end up with rounding errors and such which build up over time but in general that should get you close to the amount of data transmitted over the course of time. The longer the time between reports, the more errors that will creep into the calculation. If you are looking for an accurate measurement of total amount of bytes transmitted over long periods of time, you might have to find ways to get that information elsewhere. But for a number that’s kind of close, this should be good enough.

The value can be not very accurate , its just for controling overtime

Thanks a lot!