Fixing port-stats DBZ
Change-Id: I2bd1f9d94c1441d6bdcde00a5d2a3e595e0c5c4f
Showing
2 changed files
with
8 additions
and
2 deletions
... | @@ -17,6 +17,8 @@ package org.onosproject.net.statistic; | ... | @@ -17,6 +17,8 @@ package org.onosproject.net.statistic; |
17 | 17 | ||
18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
19 | 19 | ||
20 | +import static com.google.common.base.Preconditions.checkArgument; | ||
21 | + | ||
20 | /** | 22 | /** |
21 | * Implementation of a load. | 23 | * Implementation of a load. |
22 | */ | 24 | */ |
... | @@ -62,6 +64,7 @@ public class DefaultLoad implements Load { | ... | @@ -62,6 +64,7 @@ public class DefaultLoad implements Load { |
62 | * @param interval poll interval for this load | 64 | * @param interval poll interval for this load |
63 | */ | 65 | */ |
64 | public DefaultLoad(long current, long previous, int interval) { | 66 | public DefaultLoad(long current, long previous, int interval) { |
67 | + checkArgument(interval > 0, "Interval must be greater than 0"); | ||
65 | this.current = current; | 68 | this.current = current; |
66 | this.previous = previous; | 69 | this.previous = previous; |
67 | this.time = System.currentTimeMillis(); | 70 | this.time = System.currentTimeMillis(); | ... | ... |
... | @@ -46,8 +46,11 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -46,8 +46,11 @@ import static org.slf4j.LoggerFactory.getLogger; |
46 | @Component(immediate = true) | 46 | @Component(immediate = true) |
47 | @Service | 47 | @Service |
48 | public class PortStatisticsManager implements PortStatisticsService { | 48 | public class PortStatisticsManager implements PortStatisticsService { |
49 | + | ||
49 | private final Logger log = getLogger(getClass()); | 50 | private final Logger log = getLogger(getClass()); |
50 | 51 | ||
52 | + private static final int SECOND = 1_000; | ||
53 | + | ||
51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
52 | protected DeviceService deviceService; | 55 | protected DeviceService deviceService; |
53 | 56 | ||
... | @@ -73,9 +76,9 @@ public class PortStatisticsManager implements PortStatisticsService { | ... | @@ -73,9 +76,9 @@ public class PortStatisticsManager implements PortStatisticsService { |
73 | public Load load(ConnectPoint connectPoint) { | 76 | public Load load(ConnectPoint connectPoint) { |
74 | DataPoint c = current.get(connectPoint); | 77 | DataPoint c = current.get(connectPoint); |
75 | DataPoint p = previous.get(connectPoint); | 78 | DataPoint p = previous.get(connectPoint); |
76 | - if (c != null && p != null) { | 79 | + if (c != null && p != null && (c.time > p.time + SECOND)) { |
77 | return new DefaultLoad(c.stats.bytesSent(), p.stats.bytesSent(), | 80 | return new DefaultLoad(c.stats.bytesSent(), p.stats.bytesSent(), |
78 | - (int) (c.time - p.time) / 1000); | 81 | + (int) (c.time - p.time) / SECOND); |
79 | } | 82 | } |
80 | return null; | 83 | return null; |
81 | } | 84 | } | ... | ... |
-
Please register or login to post a comment