Commit a9f1ba6d authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Prefix/Postfix filtering for metric names; ActiveComponentFilter

- e.g., use Delta_* to filter for all metrics with a name starting with
"Delta_"
- Added an ActiveComponent filter, that utilizes a LifecycleComponent's
isActive() method to invalidate metrics for inactive hosts
- added STD to measurementStatistics DAO
parent c2ecb39e
...@@ -38,8 +38,8 @@ import de.tudarmstadt.maki.simonstrator.api.common.metric.MetricFilter; ...@@ -38,8 +38,8 @@ import de.tudarmstadt.maki.simonstrator.api.common.metric.MetricFilter;
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012 * @version 1.0, 08.08.2012
*/ */
public abstract class AbstractFilter<M extends MetricValue<?>> implements public abstract class AbstractFilter<M extends MetricValue<?>>
MetricFilter { implements MetricFilter {
private final String name; private final String name;
...@@ -67,6 +67,20 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements ...@@ -67,6 +67,20 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
if (metric.getName().equals(string)) { if (metric.getName().equals(string)) {
return true; return true;
} }
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
} }
return false; return false;
} }
...@@ -83,7 +97,9 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements ...@@ -83,7 +97,9 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
incomingMetrics.add(metric); incomingMetrics.add(metric);
} }
if (incomingMetrics.isEmpty()) { if (incomingMetrics.isEmpty()) {
throw new AssertionError("No incoming metrics configured! Available metrics are: "+metrics.toString()); throw new AssertionError(
"No incoming metrics configured! Available metrics are: "
+ metrics.toString());
} }
onInitialize(incomingMetrics); onInitialize(incomingMetrics);
...@@ -233,8 +249,8 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements ...@@ -233,8 +249,8 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012 * @version 1.0, 13.08.2012
*/ */
private class DerivedActiveMetric extends DerivedMetric implements private class DerivedActiveMetric extends DerivedMetric
ActiveMetric<M> { implements ActiveMetric<M> {
private final List<ActiveMetricListener> listeners; private final List<ActiveMetricListener> listeners;
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.analyzer.metric.filter;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.LifecycleComponent;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Filter a metric usign a {@link LifecycleComponent}s isActive method.
*
* @author Bjoern Richerzhagen
* @version 1.0, Feb 7, 2017
*/
public class ActiveComponentFilter extends AbstractFilter<MetricValue<?>> {
private Class<? extends LifecycleComponent> compClass;
private String description;
private String prefix;
@SuppressWarnings("unchecked")
@XMLConfigurableConstructor({ "clazz", "prefix" })
public ActiveComponentFilter(String clazz, String prefix) {
super("active");
this.prefix = prefix;
description = "only active "+clazz.substring(clazz.lastIndexOf(".") + 1);
// Find class
try {
compClass = (Class<? extends LifecycleComponent>) Class.forName(clazz);
} catch (ClassNotFoundException e) {
throw new AssertionError();
}
}
@Override
protected String getNameForDerivedMetric(List<Metric<?>> inputs) {
assert inputs.size() == 1;
return prefix + "_" + inputs.get(0).getName();
}
@Override
protected void onInitialize(List<Metric<?>> incomingMetrics) {
for (Metric metric : incomingMetrics) {
if (metric.isOverallMetric()) {
continue;
}
createDerivedMetric(metric, false, metric.getUnit(),
description + " of " + metric.getName(), false);
}
}
@Override
public void onStop() {
// nothing to do
}
@Override
protected MetricValue<?> getDerivedMetricValueFor(Metric<?> derivedMetric,
List<Metric<?>> inputs, Host host) {
assert inputs.size() == 1;
assert host != null;
Metric<?> input = inputs.get(0);
if (input.isOverallMetric()) {
throw new AssertionError(
"Only available for per-host input metrics.");
}
try {
LifecycleComponent comp = host.getComponent(compClass);
MetricValue mvIn = input.getPerHostMetric(host.getId());
if (mvIn != null) {
return new ActiveHostMetricValue(input.getPerHostMetric(host.getId()), comp);
}
} catch (ComponentNotAvailableException e) {
//
}
return null; // no derived metric
}
/**
* Computes statistics such as svg, sum, std...
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
private class ActiveHostMetricValue implements MetricValue {
private final MetricValue input;
private final LifecycleComponent comp;
public ActiveHostMetricValue(MetricValue input, LifecycleComponent comp) {
this.input = input;
this.comp = comp;
}
@Override
public Object getValue() {
return input.getValue();
}
@Override
public boolean isValid() {
return comp.isActive() && input.isValid();
}
}
}
...@@ -25,6 +25,7 @@ import java.util.LinkedHashSet; ...@@ -25,6 +25,7 @@ import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
...@@ -56,6 +57,8 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -56,6 +57,8 @@ public class MetricOutputDAO extends AbstractOutput {
protected Set<String> metricsToAggregate = new LinkedHashSet<>(); protected Set<String> metricsToAggregate = new LinkedHashSet<>();
protected List<MetricDaoAdapter> daoAdapters = new LinkedList<>();
/** /**
* *
* @param table * @param table
...@@ -93,6 +96,29 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -93,6 +96,29 @@ public class MetricOutputDAO extends AbstractOutput {
this.metricsToAggregate.add(metric); this.metricsToAggregate.add(metric);
} }
} }
public boolean isToAggregate(Metric metric) {
for (String string : metricsToAggregate) {
if (metric.getName().equals(string)) {
return true;
}
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
}
return false;
}
@Override @Override
public void onInitialize(List<Metric> metrics) { public void onInitialize(List<Metric> metrics) {
...@@ -103,13 +129,18 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -103,13 +129,18 @@ public class MetricOutputDAO extends AbstractOutput {
*/ */
if (metric instanceof ActiveMetric) { if (metric instanceof ActiveMetric) {
ActiveMetric am = (ActiveMetric) metric; ActiveMetric am = (ActiveMetric) metric;
am.addActiveMetricListener(new MetricDaoAdapter(am)); MetricDaoAdapter adapter = new MetricDaoAdapter(am);
am.addActiveMetricListener(adapter);
daoAdapters.add(adapter);
} }
} }
} }
@Override @Override
public void onStop() { public void onStop() {
for (MetricDaoAdapter adapter : daoAdapters) {
adapter.onStop();
}
/* /*
* Commit missing values * Commit missing values
*/ */
...@@ -135,7 +166,9 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -135,7 +166,9 @@ public class MetricOutputDAO extends AbstractOutput {
private final boolean writeAggregates; private final boolean writeAggregates;
private final Map<String, List<SimHost>> hostsByGroup; private final Map<String, List<SimHost>> hostsByGroup;
private final Map<String, DescriptiveStatistics> globalStatsByGroup;
private long timestampLastEvent = -1; private long timestampLastEvent = -1;
public MetricDaoAdapter(ActiveMetric metric) { public MetricDaoAdapter(ActiveMetric metric) {
...@@ -144,17 +177,33 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -144,17 +177,33 @@ public class MetricOutputDAO extends AbstractOutput {
metric.getName(), metric.getDescription(), metric.getName(), metric.getDescription(),
metric.getUnit().toString()); metric.getUnit().toString());
this.hosts = GlobalOracle.getHosts(); this.hosts = GlobalOracle.getHosts();
writeAggregates = metricsToAggregate.contains(metric.getName()); this.writeAggregates = isToAggregate(metric);
this.hostsByGroup = new LinkedHashMap<>(); this.hostsByGroup = new LinkedHashMap<>();
this.globalStatsByGroup = new LinkedHashMap<>();
for (SimHost simHost : hosts) { for (SimHost simHost : hosts) {
String groupId = simHost.getProperties().getGroupID(); String groupId = simHost.getProperties().getGroupID();
if (!this.hostsByGroup.containsKey(groupId)) { if (!this.hostsByGroup.containsKey(groupId)) {
this.hostsByGroup.put(groupId, new LinkedList<>()); this.hostsByGroup.put(groupId, new LinkedList<>());
this.globalStatsByGroup.put(groupId,
new DescriptiveStatistics());
} }
this.hostsByGroup.get(groupId).add(simHost); this.hostsByGroup.get(groupId).add(simHost);
} }
} }
public void onStop() {
if (writeAggregates) {
for (Entry<String, DescriptiveStatistics> groupData : globalStatsByGroup
.entrySet()) {
MeasurementDAO.storeGroupStatisticsMeasurement(md,
groupData.getKey(), Time.getCurrentTime(),
groupData.getValue(),
Time.getCurrentTime() - timeEnableDao, true);
}
globalStatsByGroup.clear();
}
}
@Override @Override
public void onMetricUpdate(ActiveMetric metric) { public void onMetricUpdate(ActiveMetric metric) {
long time = Time.getCurrentTime(); long time = Time.getCurrentTime();
...@@ -184,6 +233,8 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -184,6 +233,8 @@ public class MetricOutputDAO extends AbstractOutput {
// Iterate over groups // Iterate over groups
for (String group : hostsByGroup.keySet()) { for (String group : hostsByGroup.keySet()) {
DescriptiveStatistics stats = new DescriptiveStatistics(); DescriptiveStatistics stats = new DescriptiveStatistics();
DescriptiveStatistics globalStats = globalStatsByGroup
.get(group);
for (SimHost host : hostsByGroup.get(group)) { for (SimHost host : hostsByGroup.get(group)) {
MetricValue mv = metric MetricValue mv = metric
.getPerHostMetric(host.getId()); .getPerHostMetric(host.getId());
...@@ -198,14 +249,17 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -198,14 +249,17 @@ public class MetricOutputDAO extends AbstractOutput {
} }
// Add value // Add value
stats.addValue(vd); stats.addValue(vd);
globalStats.addValue(vd);
} }
} }
} }
} }
// Write Group stats // Write Group stats
long observationDuration = Time.getCurrentTime() - timestampLastEvent; long observationDuration = Time.getCurrentTime()
- timestampLastEvent;
if (timestampLastEvent == -1) { if (timestampLastEvent == -1) {
observationDuration = Time.getCurrentTime() - timeEnableDao; observationDuration = Time.getCurrentTime()
- timeEnableDao;
} }
MeasurementDAO.storeGroupStatisticsMeasurement(md, MeasurementDAO.storeGroupStatisticsMeasurement(md,
group, time, stats, observationDuration, false); group, time, stats, observationDuration, false);
......
...@@ -73,6 +73,9 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -73,6 +73,9 @@ public class MeasurementStatistic implements GroupMetricBound {
*/ */
@Column(nullable = true, name = "[values]") @Column(nullable = true, name = "[values]")
private Double values; private Double values;
@Column(nullable = true, name = "[std]")
private Double std;
@Column(nullable = true, name = "[sum]") @Column(nullable = true, name = "[sum]")
private Double sum; private Double sum;
...@@ -181,6 +184,7 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -181,6 +184,7 @@ public class MeasurementStatistic implements GroupMetricBound {
this.perc95 = checkForSpecialNumbers(stats.getPercentile(95)); this.perc95 = checkForSpecialNumbers(stats.getPercentile(95));
this.skewness = checkForSpecialNumbers(stats.getSkewness()); this.skewness = checkForSpecialNumbers(stats.getSkewness());
this.kurtosis = checkForSpecialNumbers(stats.getKurtosis()); this.kurtosis = checkForSpecialNumbers(stats.getKurtosis());
this.std = checkForSpecialNumbers(stats.getStandardDeviation());
} }
/** /**
......
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