Commit 993a8ce5 authored by Julian Zobel's avatar Julian Zobel
Browse files

Additional check if also statistic measurements from time frames are written...

Additional check if also statistic measurements from time frames are written to the DB or just an overall aggregate in the end.
parent 3050df20
......@@ -32,6 +32,7 @@ import java.util.Set;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.db.dao.DAO;
import de.tud.kom.p2psim.impl.util.db.dao.metric.MeasurementDAO;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
......@@ -54,13 +55,14 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @version 1.0, 13.08.2012
*/
public class MetricOutputDAO extends AbstractOutput {
public enum AGGREGATION {NONE, ALL, OVERALL_ONLY}
protected long timeEnableDao = 0;
protected long timeStopDao = Long.MAX_VALUE;
protected Set<String> metricsToAggregate = new LinkedHashSet<>();
protected Set<Tuple<String, AGGREGATION>> metricsToAggregate = new LinkedHashSet<>();
protected List<DaoAdapter> daoAdapters = new LinkedList<>();
......@@ -106,31 +108,39 @@ public class MetricOutputDAO extends AbstractOutput {
*/
public void setToAggregate(String[] metricsToAggregate) {
for (String metric : metricsToAggregate) {
this.metricsToAggregate.add(metric);
this.metricsToAggregate.add(new Tuple<String, AGGREGATION>(metric, AGGREGATION.ALL));
}
}
public void setToOverallOnlyAggregate(String[] metricsToAggregate) {
for (String metric : metricsToAggregate) {
this.metricsToAggregate.add(new Tuple<String, AGGREGATION>(metric, AGGREGATION.OVERALL_ONLY));
}
}
public boolean isToAggregate(Metric metric) {
for (String string : metricsToAggregate) {
public AGGREGATION isToAggregate(Metric metric) {
for (Tuple<String, AGGREGATION> tuple : metricsToAggregate) {
String string = tuple.getA();
if (metric.getName().equals(string)) {
return true;
return tuple.getB();
}
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
return tuple.getB();
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
return tuple.getB();
}
}
}
return false;
return AGGREGATION.NONE;
}
@Override
......@@ -186,7 +196,7 @@ public class MetricOutputDAO extends AbstractOutput {
private final List<SimHost> hosts;
private final boolean writeAggregates;
private final AGGREGATION writeAggregates;
private final Map<String, List<SimHost>> hostsByGroup;
......@@ -215,7 +225,7 @@ public class MetricOutputDAO extends AbstractOutput {
}
public void onStop() {
if (writeAggregates) {
if (!writeAggregates.equals(AGGREGATION.NONE)) {
for (Entry<String, DescriptiveStatistics> groupData : globalStatsByGroup
.entrySet()) {
MeasurementDAO.storeGroupStatisticsMeasurement(md,
......@@ -247,7 +257,7 @@ public class MetricOutputDAO extends AbstractOutput {
}
} else {
// per-host metric
if (writeAggregates) {
if (!writeAggregates.equals(AGGREGATION.NONE)) {
/*
* Write aggregates instead of individual metric values.
* This can be improved w.r.t. performance, but currently we
......@@ -286,11 +296,16 @@ public class MetricOutputDAO extends AbstractOutput {
observationDuration = Time.getCurrentTime()
- timeEnableDao;
}
MeasurementDAO.storeGroupStatisticsMeasurement(md,
group, time, stats, observationDuration, false);
// store a statistics measurement for a certain time frame
if(writeAggregates.equals(AGGREGATION.ALL)) {
MeasurementDAO.storeGroupStatisticsMeasurement(md,
group, time, stats, observationDuration, false);
}
}
timestampLastEvent = Time.getCurrentTime();
} else {
timestampLastEvent = Time.getCurrentTime();
}
else {
for (SimHost host : hosts) {
MetricValue mv = metric.getPerHostMetric(host.getId());
if (mv != null) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment