Skip to content

Commit

Permalink
added support for sampler templates
Browse files Browse the repository at this point in the history
  • Loading branch information
dimovelev committed Sep 10, 2012
1 parent 31f44c7 commit 911f454
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,15 @@ Check out the following configuration as a quick-start:
</selector-groups>
<!-- These are the actual active runtime components that sample the date from their input, use the given selectors to determine which metrics are relevant (and rename them) and sends them to the given outputs. An input without a sampler does not do anything. -->
<samplers>
<!-- fetch data from wls01 input, use the regular expressions in a group named "wls" to select and rename metrics and send them to graphite every 10 seconds. -->
<sampler input="wls01" outputs="graphite" interval="10">
<selectors>
<use-group name="wls" />
</selectors>
</sampler>
<sampler input="wls02" outputs="graphite" interval="10">
<!-- template defining common values for weblogic samplers. -->
<sampler name="wls" abstract="true" outputs="graphite" interval="10">
<selectors>
<use-group name="wls" />
</selectors>
</sampler>
<!-- fetch data from wls01 input, use the regular expressions in a group named "wls" to select and rename metrics and send them to graphite every 10 seconds. -->
<sampler input="wls01" template="wls" />
<sampler input="wls02" template="wls" />
<sampler input="tomcat01" outputs="graphite" interval="10">
<selectors>
<use-group name="tomcat" />
Expand Down Expand Up @@ -148,6 +146,7 @@ Version 0.4.0
-------------
* Renamed most of the XML configuration elements
* Added support for input templates
* Added support for sampler templates
* Fixed problems with multiple JDBC drivers
* Renamed to metrics-sampler (from jmx-sampler) as it better reflects the purpose of the application
* Improved debug logging
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
public class ConfigurationException extends RuntimeException {
private static final long serialVersionUID = 1L;

public ConfigurationException() {
}

public ConfigurationException(final String msg) {
super(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ public class ConfigurationXBean {
private int poolSize;

private List<InputXBean> inputs;

private List<OutputXBean> outputs;

private List<SamplerXBean> samplers;

private List<PlaceholderXBean> placeholders;

@XStreamAlias("selector-groups")
Expand Down Expand Up @@ -143,9 +140,14 @@ private Map<String, List<SelectorConfig>> configureSelectorGroups(final List<Sel
}

private List<SamplerConfig> configureSamplers(final List<SamplerXBean> samplers, final Map<String, InputConfig> inputs, final Map<String, OutputConfig> outputs, final Map<String, List<SelectorConfig>> selectorGroups, final List<Placeholder> placeholders) {
final LinkedHashMap<String, SamplerXBean> namedSamplers = TemplatableXBeanUtils.sortByDependency(samplers);

final List<SamplerConfig> result = new LinkedList<SamplerConfig>();
for (final SamplerXBean def : samplers) {
result.add(def.toConfig(inputs, outputs, selectorGroups, placeholders));
TemplatableXBeanUtils.applyTemplate(def, namedSamplers);
if (def.isInstantiatable()) {
result.add(def.toConfig(inputs, outputs, selectorGroups, placeholders));
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
/**
* Base class for sampler XBeans.
*/
public abstract class SamplerXBean {
public abstract class SamplerXBean extends TemplatableXBean {
@XStreamAsAttribute
private int interval;
private Integer interval;

@XStreamAsAttribute
private boolean disabled;

public abstract SamplerConfig toConfig(Map<String, InputConfig> inputs, Map<String, OutputConfig> outputs, Map<String, List<SelectorConfig>> selectorGroups, List<Placeholder> placeholders);

public int getInterval() {
public Integer getInterval() {
return interval;
}

public void setInterval(final int interval) {
public void setInterval(final Integer interval) {
this.interval = interval;
}

Expand All @@ -41,7 +41,11 @@ public void setDisabled(final boolean disabled) {
this.disabled = disabled;
}

@Override
protected void validate() {
greaterThanZero("interval", "default sampler", getInterval());
super.validate();
if (isInstantiatable()) {
greaterThanZero("interval", "default sampler", getInterval());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public static void validPort(final String name, final String context, final int
}
}

public static void greaterThanZero(final String name, final String context, final int value) {
public static void greaterThanZero(final String name, final String context, final Integer value) {
if (value == null) {
throw new ConfigurationException("Attribute "+name+" of "+context+" is mandatory");
}
if (value < 1) {
throw new ConfigurationException("Attribute "+name+" of "+context+" with value "+value+" is not a valid number higher than 0");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public String getInput() {
return input;
}

@Override
public String getName() {
final String name = super.getName();
if (name == null) {
return input;
}
return name;
}


public void setInput(final String input) {
this.input = input;
}
Expand Down Expand Up @@ -66,9 +76,11 @@ public void setSelectors(final List<SelectorXBean> selectors) {
@Override
protected void validate() {
super.validate();
notEmpty("input", "default sampler", getInput());
notEmpty("outputs", "default sampler", getOutputs());
notEmpty("selectors", "default sampler", getSelectors());
if (isInstantiatable()) {
notEmpty("input", "default sampler", getInput());
notEmpty("outputs", "default sampler", getOutputs());
notEmpty("selectors", "default sampler", getSelectors());
}
}
@Override
public SamplerConfig toConfig(final Map<String, InputConfig> inputs, final Map<String, OutputConfig> outputs, final Map<String, List<SelectorConfig>> selectorTemplates, final List<Placeholder> globalPlaceholders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.metricssampler.selector.MetricsSelector;
import org.metricssampler.writer.MetricsWriter;

public class DeafultSamplerTest {
public class DefaultSamplerTest {
private DefaultSampler testee;
private BulkMetricsReader bulkReader;
private MetricsWriter writer1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

0 comments on commit 911f454

Please sign in to comment.