fix: diagonal line in parallelRequests plot
This commit is contained in:
@@ -14,6 +14,10 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ParallelRequestsAggregator implements CustomAggregator {
|
||||
|
||||
private static final char NEWLINE = '\n';
|
||||
|
||||
private static final char SEPARATOR = ',';
|
||||
|
||||
private static final Logger METRICS_LOGGER = LoggerFactory
|
||||
.getLogger("org.lucares.metrics.aggregator.parallelRequests");
|
||||
|
||||
@@ -23,9 +27,12 @@ public class ParallelRequestsAggregator implements CustomAggregator {
|
||||
|
||||
private final long fromEpochMilli;
|
||||
|
||||
private final long toEpochMilli;
|
||||
|
||||
public ParallelRequestsAggregator(final Path tmpDir, final long fromEpochMilli, final long toEpochMilli) {
|
||||
this.tmpDir = tmpDir;
|
||||
this.fromEpochMilli = fromEpochMilli;
|
||||
this.toEpochMilli = toEpochMilli;
|
||||
|
||||
if ((toEpochMilli - fromEpochMilli) > 3600 * 1000) {
|
||||
throw new IllegalArgumentException("The " + ParallelRequestsAggregator.class.getSimpleName()
|
||||
@@ -51,8 +58,6 @@ public class ParallelRequestsAggregator implements CustomAggregator {
|
||||
public AggregatedData getAggregatedData() throws IOException {
|
||||
|
||||
final long start = System.nanoTime();
|
||||
final char separator = ',';
|
||||
final char newline = '\n';
|
||||
|
||||
final File dataFile = File.createTempFile("data", ".dat", tmpDir.toFile());
|
||||
try (final Writer output = new BufferedWriter(
|
||||
@@ -60,19 +65,22 @@ public class ParallelRequestsAggregator implements CustomAggregator {
|
||||
|
||||
final StringBuilder data = new StringBuilder();
|
||||
|
||||
// first and last value should be 0, or gnuplot will draw a diagonal line
|
||||
appendTimeAndValue(data, fromEpochMilli, 0);
|
||||
|
||||
int value = 0;
|
||||
for (int i = 0; i < increments.length - 1; i++) {
|
||||
final int increment = increments[i];
|
||||
final int nextIncrement = increments[i + 1];
|
||||
if (increment != 0 || nextIncrement != 0) {
|
||||
value += increment;
|
||||
data.append(String.format("%.3f", (fromEpochMilli + i) / 1000.0));
|
||||
data.append(separator);
|
||||
data.append(value);
|
||||
data.append(newline);
|
||||
appendTimeAndValue(data, fromEpochMilli + i, value);
|
||||
}
|
||||
}
|
||||
|
||||
// first and last value should be 0, or gnuplot will draw a diagonal line
|
||||
appendTimeAndValue(data, toEpochMilli, 0);
|
||||
|
||||
output.write(data.toString());
|
||||
|
||||
}
|
||||
@@ -83,4 +91,11 @@ public class ParallelRequestsAggregator implements CustomAggregator {
|
||||
return new AggregatedData(title, dataFile);
|
||||
}
|
||||
|
||||
private void appendTimeAndValue(final StringBuilder builder, final long timeEpochMilli, final int value) {
|
||||
builder.append(String.format("%.3f", timeEpochMilli / 1000.0));
|
||||
builder.append(SEPARATOR);
|
||||
builder.append(value);
|
||||
builder.append(NEWLINE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user