Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ebean-api/src/main/java/io/ebean/meta/MetaInfoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@ default List<MetricData> collectMetricsAsData() {
*/
List<MetaQueryPlan> queryPlanCollectNow(QueryPlanRequest request);

/**
* Creates a new MetricReportGenerator. This can be used to embed in your web-application
*/
MetricReportGenerator createReportGenerator();

}
22 changes: 22 additions & 0 deletions ebean-api/src/main/java/io/ebean/meta/MetricReportGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.ebean.meta;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

/**
* The metric report. most likely a HTML report.
*/
public interface MetricReportGenerator {

/**
* Writes the report to the outputStream. The stream will not be closed.
*/
void writeReport(OutputStream out) throws IOException;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used outputStream here, because someone might want to generate PDFs


/**
* Used to configure the metric. This report dependent.
* Returns a string result, that should be sent back to the web application
*/
String configure(List<MetricReportValue> values);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bit hackish, but it allows me to keep the Spring rest controller very simple

}
39 changes: 39 additions & 0 deletions ebean-api/src/main/java/io/ebean/meta/MetricReportValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.ebean.meta;

/**
* A Metric report value used to configure a metric report.
* This is most likely a REST call from the provided web-application
*/
public class MetricReportValue {
private String name;
private String value;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public int intValue() {
return Integer.valueOf(value);
}

public MetricReportValue() {

}

public MetricReportValue(String name, Object value) {
this.name = name;
this.value = String.valueOf(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public BasicMetricVisitor visitBasic() {
return basic;
}

@Override
public MetricReportGenerator createReportGenerator() {
return new HtmlMetricReportGenerator(server);
}

@Override
public void resetAllMetrics() {
server.visitMetrics(new ResetVisitor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import io.ebean.meta.SortMetric;
import io.ebeaninternal.api.SpiEbeanServer;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.List;

Expand All @@ -19,6 +25,7 @@ final class DumpMetrics {
private boolean dumpHash;
private boolean dumpSql;
private boolean dumpLoc;
private boolean dumpHtml;

private Comparator<MetaTimedMetric> sortBy = SortMetric.NAME;

Expand All @@ -32,6 +39,7 @@ final class DumpMetrics {
dumpLoc = options.contains("loc");
dumpSql = options.contains("sql");
dumpHash = options.contains("hash");
dumpHtml = options.contains("html");
for (int i = 5; i < 10; i++) {
width = Math.max(width, optionWidth(i * 10));
}
Expand Down Expand Up @@ -72,7 +80,16 @@ private Comparator<MetaTimedMetric> setSortOption(String option) {
}

void dump() {

if (dumpHtml) {
File file = new File("metric-report-" + server.name() + "-"
+ DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss.SSS").format(LocalDateTime.now()) + ".html");
try (OutputStream out = new FileOutputStream(file)) {
server.metaInfo().createReportGenerator().writeReport(out);
out("html report written to: " + file.getAbsolutePath() + "\n");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
out("-- Dumping metrics for " + server.name() + " -- ");
ServerMetrics serverMetrics = server.metaInfo().collectMetrics();

Expand Down
Loading