fix: diagonal line in parallelRequests plot

This commit is contained in:
2018-08-18 12:31:11 +02:00
parent ea5e16fad5
commit 2a68fd72da

View File

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