Fixing an issue where stale port stats could be reported when collector stops or…
… negative load reported when device counters overflow or glitch. Change-Id: I9c7238758555a08fc3f02e6cded15fb4e211bf69
Showing
1 changed file
with
6 additions
and
3 deletions
... | @@ -49,7 +49,8 @@ public class PortStatisticsManager implements PortStatisticsService { | ... | @@ -49,7 +49,8 @@ public class PortStatisticsManager implements PortStatisticsService { |
49 | 49 | ||
50 | private final Logger log = getLogger(getClass()); | 50 | private final Logger log = getLogger(getClass()); |
51 | 51 | ||
52 | - private static final int SECOND = 1_000; | 52 | + private static final int SECOND = 1_000; // milliseconds |
53 | + private static final long STALE_LIMIT = 15_000; // milliseconds | ||
53 | 54 | ||
54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
55 | protected DeviceService deviceService; | 56 | protected DeviceService deviceService; |
... | @@ -63,7 +64,6 @@ public class PortStatisticsManager implements PortStatisticsService { | ... | @@ -63,7 +64,6 @@ public class PortStatisticsManager implements PortStatisticsService { |
63 | public void activate() { | 64 | public void activate() { |
64 | deviceService.addListener(deviceListener); | 65 | deviceService.addListener(deviceListener); |
65 | log.info("Started"); | 66 | log.info("Started"); |
66 | - | ||
67 | } | 67 | } |
68 | 68 | ||
69 | @Deactivate | 69 | @Deactivate |
... | @@ -76,7 +76,10 @@ public class PortStatisticsManager implements PortStatisticsService { | ... | @@ -76,7 +76,10 @@ public class PortStatisticsManager implements PortStatisticsService { |
76 | public Load load(ConnectPoint connectPoint) { | 76 | public Load load(ConnectPoint connectPoint) { |
77 | DataPoint c = current.get(connectPoint); | 77 | DataPoint c = current.get(connectPoint); |
78 | DataPoint p = previous.get(connectPoint); | 78 | DataPoint p = previous.get(connectPoint); |
79 | - if (c != null && p != null && (c.time > p.time + SECOND)) { | 79 | + long now = System.currentTimeMillis(); |
80 | + if (c != null && p != null && (now - c.time < STALE_LIMIT) && | ||
81 | + (c.time > p.time + SECOND) && | ||
82 | + (c.stats.bytesSent() - p.stats.bytesSent() >= 0)) { | ||
80 | return new DefaultLoad(c.stats.bytesSent(), p.stats.bytesSent(), | 83 | return new DefaultLoad(c.stats.bytesSent(), p.stats.bytesSent(), |
81 | (int) (c.time - p.time) / SECOND); | 84 | (int) (c.time - p.time) / SECOND); |
82 | } | 85 | } | ... | ... |
-
Please register or login to post a comment