diff --git a/src/main/java/org/warp/commonutils/metrics/AtomicTimeAbsoluteSamples.java b/src/main/java/org/warp/commonutils/metrics/AtomicTimeAbsoluteSamples.java index 6939267..49b1fec 100644 --- a/src/main/java/org/warp/commonutils/metrics/AtomicTimeAbsoluteSamples.java +++ b/src/main/java/org/warp/commonutils/metrics/AtomicTimeAbsoluteSamples.java @@ -88,23 +88,16 @@ public class AtomicTimeAbsoluteSamples implements AtomicTimeAbsoluteSamplesSnaps public synchronized double getAveragePerSecond(long timeRange) { updateSamples(); - long currentTime = System.nanoTime() / 1000000L; double preciseTimeRange = timeRange; // Fix if the time range is bigger than the collected data since start - if (currentTime - preciseTimeRange < startTime) { - preciseTimeRange = currentTime - startTime; + if (currentSampleStartTime - preciseTimeRange < startTime) { + preciseTimeRange = currentSampleStartTime - startTime; } double samplesCount = Math.min(Math.max(preciseTimeRange / sampleTime, 1d), samples.length); double value = 0; - for (int i = samplesCount == 1 ? 0 : 1; i < samplesCount; i++) { - double sampleValue; - if (i == 0) { - sampleValue = samples[i] * sampleTime / (double) (currentTime - currentSampleStartTime); - } else { - sampleValue = samples[i]; - } - value += sampleValue; + for (int i = 1; i <= samplesCount; i++) { + value += samples[i]; } return value / samplesCount; } diff --git a/src/main/java/org/warp/commonutils/metrics/AtomicTimeIncrementalSamples.java b/src/main/java/org/warp/commonutils/metrics/AtomicTimeIncrementalSamples.java index 9a1b96f..95d3a38 100644 --- a/src/main/java/org/warp/commonutils/metrics/AtomicTimeIncrementalSamples.java +++ b/src/main/java/org/warp/commonutils/metrics/AtomicTimeIncrementalSamples.java @@ -81,24 +81,17 @@ public class AtomicTimeIncrementalSamples implements AtomicTimeIncrementalSample public synchronized double getAveragePerSecond(long timeRange) { updateSamples(); - long currentTime = System.nanoTime() / 1000000L; double preciseTimeRange = timeRange; // Fix if the time range is bigger than the collected data since start - if (currentTime - preciseTimeRange < startTime) { - preciseTimeRange = currentTime - startTime; + if (currentSampleStartTime - preciseTimeRange < startTime) { + preciseTimeRange = currentSampleStartTime - startTime; } double samplesCount = Math.min(Math.max(preciseTimeRange / sampleTime, 1d), samples.length); double roundedTimeRange = samplesCount * sampleTime; double value = 0; - for (int i = samplesCount == 1 ? 0 : 1; i < samplesCount; i++) { - double sampleValue; - if (i == 0) { - sampleValue = samples[i] * sampleTime / (double) (currentTime - currentSampleStartTime); - } else { - sampleValue = samples[i]; - } - value += sampleValue; + for (int i = 1; i <= samplesCount; i++) { + value += samples[i]; } return (value / roundedTimeRange) * 1000d; }