mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
#2760 - Add MetaInfoManager.metricsAsJson() ... to support conversion of collected metrics to json
This commit is contained in:
1 parent
64311b2b9d
commit
bda0786924
9 files changed
+68
-17
No files matched your search
@@ -47,6 +47,11 @@ final class DefaultMetaInfoManager implements MetaInfoManager {
|
||||
return visitBasic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerMetricsAsJson metricsAsJson(ServerMetrics metrics) {
|
||||
return new DumpMetricsJson(metrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerMetricsAsJson collectMetricsAsJson() {
|
||||
return new DumpMetricsJson(server);
|
||||
@@ -59,7 +64,7 @@ final class DefaultMetaInfoManager implements MetaInfoManager {
|
||||
|
||||
@Override
|
||||
public BasicMetricVisitor visitBasic() {
|
||||
BasicMetricVisitor basic = new BasicMetricVisitor();
|
||||
BasicMetricVisitor basic = new BasicMetricVisitor(server.name());
|
||||
visitMetrics(basic);
|
||||
return basic;
|
||||
}
|
||||
|
||||
@@ -29,17 +29,13 @@ final class DumpMetricsData {
|
||||
}
|
||||
|
||||
private void collect(ServerMetrics serverMetrics) {
|
||||
final List<MetaTimedMetric> timedMetrics = serverMetrics.timedMetrics();
|
||||
final List<MetaCountMetric> countMetrics = serverMetrics.countMetrics();
|
||||
final List<MetaQueryMetric> queryMetrics = serverMetrics.queryMetrics();
|
||||
|
||||
for (MetaTimedMetric metric : timedMetrics) {
|
||||
for (MetaTimedMetric metric : serverMetrics.timedMetrics()) {
|
||||
add(metric);
|
||||
}
|
||||
for (MetaCountMetric metric : countMetrics) {
|
||||
for (MetaCountMetric metric : serverMetrics.countMetrics()) {
|
||||
addCount(metric);
|
||||
}
|
||||
for (MetaQueryMetric metric : queryMetrics) {
|
||||
for (MetaQueryMetric metric : serverMetrics.queryMetrics()) {
|
||||
addQuery(metric);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@ import java.util.List;
|
||||
final class DumpMetricsJson implements ServerMetricsAsJson {
|
||||
|
||||
private final Database database;
|
||||
private final ServerMetrics metrics;
|
||||
private final String name;
|
||||
private Appendable writer;
|
||||
/**
|
||||
* By default include sql and location attributes for the initial collection only.
|
||||
* By default, include sql and location attributes for the initial collection only.
|
||||
*/
|
||||
private int includeExtraAttributes = 1;
|
||||
private boolean withHeader = true;
|
||||
@@ -31,6 +33,14 @@ final class DumpMetricsJson implements ServerMetricsAsJson {
|
||||
|
||||
DumpMetricsJson(Database database) {
|
||||
this.database = database;
|
||||
this.name = database.name();
|
||||
this.metrics = null;
|
||||
}
|
||||
|
||||
DumpMetricsJson(ServerMetrics metrics) {
|
||||
this.database = null;
|
||||
this.metrics = metrics;
|
||||
this.name = metrics.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,14 +76,18 @@ final class DumpMetricsJson implements ServerMetricsAsJson {
|
||||
@Override
|
||||
public String json() {
|
||||
writer = new StringWriter();
|
||||
collect(database.metaInfo().collectMetrics());
|
||||
collect(obtainMetrics());
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Appendable buffer) {
|
||||
writer = buffer;
|
||||
collect(database.metaInfo().collectMetrics());
|
||||
collect(obtainMetrics());
|
||||
}
|
||||
|
||||
private ServerMetrics obtainMetrics() {
|
||||
return metrics != null ? metrics : database.metaInfo().collectMetrics();
|
||||
}
|
||||
|
||||
private void collect(ServerMetrics serverMetrics) {
|
||||
@@ -112,7 +126,7 @@ final class DumpMetricsJson implements ServerMetricsAsJson {
|
||||
if (withHeader) {
|
||||
objStart();
|
||||
key("db");
|
||||
val(database.name());
|
||||
val(name);
|
||||
key("metrics");
|
||||
listStart();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user