use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.
the class AgentPreprocessorConfiguration method loadFromStream.
public void loadFromStream(InputStream stream) {
totalValidRules = 0;
totalInvalidRules = 0;
Yaml yaml = new Yaml();
try {
// noinspection unchecked
Map<String, Object> rulesByPort = (Map<String, Object>) yaml.load(stream);
for (String strPort : rulesByPort.keySet()) {
int validRules = 0;
// noinspection unchecked
List<Map<String, String>> rules = (List<Map<String, String>>) rulesByPort.get(strPort);
for (Map<String, String> rule : rules) {
try {
requireArguments(rule, "rule", "action");
allowArguments(rule, "rule", "action", "scope", "search", "replace", "match", "tag", "newtag", "value", "source", "iterations");
String ruleName = rule.get("rule").replaceAll("[^a-z0-9_-]", "");
PreprocessorRuleMetrics ruleMetrics = new PreprocessorRuleMetrics(Metrics.newCounter(new TaggedMetricName("preprocessor." + ruleName, "count", "port", strPort)), Metrics.newCounter(new TaggedMetricName("preprocessor." + ruleName, "cpu_nanos", "port", strPort)));
if (rule.get("scope") != null && rule.get("scope").equals("pointLine")) {
switch(rule.get("action")) {
case "replaceRegex":
allowArguments(rule, "rule", "action", "scope", "search", "replace", "match", "iterations");
this.forPort(strPort).forPointLine().addTransformer(new PointLineReplaceRegexTransformer(rule.get("search"), rule.get("replace"), rule.get("match"), Integer.parseInt(rule.getOrDefault("iterations", "1")), ruleMetrics));
break;
case "blacklistRegex":
allowArguments(rule, "rule", "action", "scope", "match");
this.forPort(strPort).forPointLine().addFilter(new PointLineBlacklistRegexFilter(rule.get("match"), ruleMetrics));
break;
case "whitelistRegex":
allowArguments(rule, "rule", "action", "scope", "match");
this.forPort(strPort).forPointLine().addFilter(new PointLineWhitelistRegexFilter(rule.get("match"), ruleMetrics));
break;
default:
throw new IllegalArgumentException("Action '" + rule.get("action") + "' is not valid or cannot be applied to pointLine");
}
} else {
switch(rule.get("action")) {
case "replaceRegex":
allowArguments(rule, "rule", "action", "scope", "search", "replace", "match", "iterations");
this.forPort(strPort).forReportPoint().addTransformer(new ReportPointReplaceRegexTransformer(rule.get("scope"), rule.get("search"), rule.get("replace"), rule.get("match"), Integer.parseInt(rule.getOrDefault("iterations", "1")), ruleMetrics));
break;
case "forceLowercase":
allowArguments(rule, "rule", "action", "scope", "match");
this.forPort(strPort).forReportPoint().addTransformer(new ReportPointForceLowercaseTransformer(rule.get("scope"), rule.get("match"), ruleMetrics));
break;
case "addTag":
allowArguments(rule, "rule", "action", "tag", "value");
this.forPort(strPort).forReportPoint().addTransformer(new ReportPointAddTagTransformer(rule.get("tag"), rule.get("value"), ruleMetrics));
break;
case "addTagIfNotExists":
allowArguments(rule, "rule", "action", "tag", "value");
this.forPort(strPort).forReportPoint().addTransformer(new ReportPointAddTagIfNotExistsTransformer(rule.get("tag"), rule.get("value"), ruleMetrics));
break;
case "dropTag":
allowArguments(rule, "rule", "action", "tag", "match");
this.forPort(strPort).forReportPoint().addTransformer(new ReportPointDropTagTransformer(rule.get("tag"), rule.get("match"), ruleMetrics));
break;
case "extractTag":
allowArguments(rule, "rule", "action", "tag", "source", "search", "replace", "match");
this.forPort(strPort).forReportPoint().addTransformer(new ReportPointExtractTagTransformer(rule.get("tag"), rule.get("source"), rule.get("search"), rule.get("replace"), rule.get("match"), ruleMetrics));
break;
case "renameTag":
allowArguments(rule, "rule", "action", "tag", "newtag", "match");
this.forPort(strPort).forReportPoint().addTransformer(new ReportPointRenameTagTransformer(rule.get("tag"), rule.get("newtag"), rule.get("match"), ruleMetrics));
break;
case "blacklistRegex":
allowArguments(rule, "rule", "action", "scope", "match");
this.forPort(strPort).forReportPoint().addFilter(new ReportPointBlacklistRegexFilter(rule.get("scope"), rule.get("match"), ruleMetrics));
break;
case "whitelistRegex":
allowArguments(rule, "rule", "action", "scope", "match");
this.forPort(strPort).forReportPoint().addFilter(new ReportPointWhitelistRegexFilter(rule.get("scope"), rule.get("match"), ruleMetrics));
break;
default:
throw new IllegalArgumentException("Action '" + rule.get("action") + "' is not valid");
}
}
validRules++;
} catch (IllegalArgumentException | NullPointerException ex) {
logger.warning("Invalid rule " + (rule == null || rule.get("rule") == null ? "" : rule.get("rule")) + " (port " + strPort + "): " + ex);
totalInvalidRules++;
}
}
logger.info("Loaded " + validRules + " rules for port " + strPort);
totalValidRules += validRules;
}
logger.info("Total " + totalValidRules + " rules loaded");
if (totalInvalidRules > 0) {
throw new RuntimeException("Total " + totalInvalidRules + " invalid rules detected, aborting start-up");
}
} catch (ClassCastException e) {
throw new RuntimeException("Can't parse preprocessor configuration - aborting start-up");
}
}
use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.
the class Main method main.
public static void main(String[] args) throws IOException, InterruptedException {
// Parse inputs.
System.out.println("Args: " + Joiner.on(", ").join(args));
if (args.length != 2) {
System.out.println("Usage: java -jar this.jar <metricsPort> <histogramsPort>");
return;
}
int port = Integer.parseInt(args[0]);
int histoPort = Integer.parseInt(args[1]);
// Set up periodic reporting.
MetricsRegistry metricsRegistry = new MetricsRegistry();
WavefrontYammerMetricsReporter wavefrontYammerMetricsReporter = new WavefrontYammerMetricsReporter(metricsRegistry, "wavefrontYammerMetrics", "localhost", port, histoPort, System::currentTimeMillis);
wavefrontYammerMetricsReporter.start(5, TimeUnit.SECONDS);
// Populate test metrics.
Counter counter = metricsRegistry.newCounter(new TaggedMetricName("group", "mycounter", "tag1", "value1"));
Histogram histogram = metricsRegistry.newHistogram(new TaggedMetricName("group2", "myhisto"), false);
WavefrontHistogram wavefrontHistogram = WavefrontHistogram.get(metricsRegistry, new TaggedMetricName("group", "mywavefronthisto", "tag2", "value2"));
while (true) {
counter.inc();
histogram.update(counter.count());
wavefrontHistogram.update(counter.count());
Thread.sleep(1000);
}
}
use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.
the class SocketMetricsProcessor method processTimer.
@Override
public void processTimer(MetricName name, Timer timer, Void context) throws Exception {
MetricName samplingName, rateName;
if (name instanceof TaggedMetricName) {
TaggedMetricName taggedMetricName = (TaggedMetricName) name;
samplingName = new TaggedMetricName(taggedMetricName.getGroup(), taggedMetricName.getName() + ".duration", taggedMetricName.getTags());
rateName = new TaggedMetricName(taggedMetricName.getGroup(), taggedMetricName.getName() + ".rate", taggedMetricName.getTags());
} else {
samplingName = new MetricName(name.getGroup(), name.getType(), name.getName() + ".duration");
rateName = new MetricName(name.getGroup(), name.getType(), name.getName() + ".rate");
}
writeSummarizable(samplingName, timer);
writeSampling(samplingName, timer);
writeMetered(rateName, timer);
if (clear)
timer.clear();
}
use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.
the class WavefrontYammerMetricsReporterTest method testTransformer.
@Test(timeout = 1000)
public void testTransformer() throws Exception {
innerSetUp(false, pair -> Pair.of(new TaggedMetricName(pair._1.getGroup(), pair._1.getName(), "tagA", "valueA"), pair._2), false, false);
TaggedMetricName taggedMetricName = new TaggedMetricName("group", "mycounter", "tag1", "value1", "tag2", "value2");
Counter counter = metricsRegistry.newCounter(taggedMetricName);
counter.inc();
counter.inc();
wavefrontYammerMetricsReporter.run();
assertThat(receiveFromSocket(1, fromMetrics), contains(equalTo("\"mycounter\" 2.0 1485224035 tagA=\"valueA\"")));
}
use of com.wavefront.common.TaggedMetricName in project java by wavefrontHQ.
the class WavefrontYammerMetricsReporterTest method testTaggedCounter.
@Test(timeout = 1000)
public void testTaggedCounter() throws Exception {
TaggedMetricName taggedMetricName = new TaggedMetricName("group", "mycounter", "tag1", "value1", "tag2", "value2");
Counter counter = metricsRegistry.newCounter(taggedMetricName);
counter.inc();
counter.inc();
wavefrontYammerMetricsReporter.run();
assertThat(receiveFromSocket(1, fromMetrics), contains(equalTo("\"mycounter\" 2.0 1485224035 tag1=\"value1\" tag2=\"value2\"")));
}
Aggregations