Skip to content

Commit

Permalink
Fix port_rate.lua to prevent negative values in BPS counters after co…
Browse files Browse the repository at this point in the history
…unter clear
  • Loading branch information
shiraez committed Aug 1, 2024
1 parent 43ac585 commit 1f8a854
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions orchagent/port_rates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ local function logit(msg)
logtable[#logtable+1] = tostring(msg)
end

local function calc_diff(new, last)
if new < last then
return 0
else
return (new - last)
end
end

local counters_db = ARGV[1]
local counters_table_name = ARGV[2]
local rates_table_name = "RATES"
Expand Down Expand Up @@ -58,8 +66,8 @@ local function compute_rate(port)
local out_octets_last = redis.call('HGET', rates_table_name .. ':' .. port, 'SAI_PORT_STAT_IF_OUT_OCTETS_last')

-- Calculate new rates values
local rx_bps_new = (in_octets - in_octets_last) / delta * 1000
local tx_bps_new = (out_octets - out_octets_last) / delta * 1000
local rx_bps_new = calc_diff(in_octets, in_octets_last) / delta * 1000
local tx_bps_new = calc_diff(out_octets, out_octets_last) / delta * 1000
local rx_pps_new = ((in_ucast_pkts + in_non_ucast_pkts) - (in_ucast_pkts_last + in_non_ucast_pkts_last)) / delta * 1000
local tx_pps_new = ((out_ucast_pkts + out_non_ucast_pkts) - (out_ucast_pkts_last + out_non_ucast_pkts_last)) / delta * 1000

Expand Down

0 comments on commit 1f8a854

Please sign in to comment.