parent
8cbeecd347
commit
4e8ca603fe
|
@ -9,7 +9,7 @@ import java.io.File;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class NetworkGauge implements Gauge<Long> {
|
||||
public abstract class NetworkGauge implements Gauge<Double> {
|
||||
|
||||
protected Pair<Long, Long> getSentReceived() throws IOException {
|
||||
File proc = new File("/proc/net/dev");
|
||||
|
|
|
@ -13,23 +13,31 @@ public class NetworkReceivedGauge extends NetworkGauge {
|
|||
private long lastTimestamp;
|
||||
private long lastReceived;
|
||||
|
||||
public NetworkReceivedGauge() {
|
||||
try {
|
||||
this.lastTimestamp = System.currentTimeMillis();
|
||||
this.lastReceived = getSentReceived().second();
|
||||
} catch (IOException e) {
|
||||
logger.warn(NetworkReceivedGauge.class.getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getValue() {
|
||||
public Double getValue() {
|
||||
try {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
Pair<Long, Long> sentAndReceived = getSentReceived();
|
||||
long result = 0;
|
||||
double bytesReceived = sentAndReceived.second() - lastReceived;
|
||||
double secondsElapsed = (timestamp - this.lastTimestamp) / 1000;
|
||||
double result = bytesReceived / secondsElapsed;
|
||||
|
||||
if (lastTimestamp != 0) {
|
||||
result = sentAndReceived.second() - lastReceived;
|
||||
lastReceived = sentAndReceived.second();
|
||||
}
|
||||
this.lastTimestamp = timestamp;
|
||||
this.lastReceived = sentAndReceived.second();
|
||||
|
||||
lastTimestamp = timestamp;
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
logger.warn("NetworkReceivedGauge", e);
|
||||
return -1L;
|
||||
return -1D;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,23 +13,31 @@ public class NetworkSentGauge extends NetworkGauge {
|
|||
private long lastTimestamp;
|
||||
private long lastSent;
|
||||
|
||||
@Override
|
||||
public Long getValue() {
|
||||
public NetworkSentGauge() {
|
||||
try {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
Pair<Long, Long> sentAndReceived = getSentReceived();
|
||||
long result = 0;
|
||||
this.lastTimestamp = System.currentTimeMillis();
|
||||
this.lastSent = getSentReceived().first();
|
||||
} catch (IOException e) {
|
||||
logger.warn(NetworkSentGauge.class.getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (lastTimestamp != 0) {
|
||||
result = sentAndReceived.first() - lastSent;
|
||||
lastSent = sentAndReceived.first();
|
||||
}
|
||||
@Override
|
||||
public Double getValue() {
|
||||
try {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
Pair<Long, Long> sentAndReceived = getSentReceived();
|
||||
double bytesTransmitted = sentAndReceived.first() - lastSent;
|
||||
double secondsElapsed = (timestamp - this.lastTimestamp) / 1000;
|
||||
double result = bytesTransmitted / secondsElapsed;
|
||||
|
||||
this.lastSent = sentAndReceived.first();
|
||||
this.lastTimestamp = timestamp;
|
||||
|
||||
lastTimestamp = timestamp;
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
logger.warn("NetworkSentGauge", e);
|
||||
return -1L;
|
||||
return -1D;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue