Search in sources :

Example 1 with TaggedMetricName

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");
    }
}
Also used : TaggedMetricName(com.wavefront.common.TaggedMetricName) List(java.util.List) Yaml(org.yaml.snakeyaml.Yaml) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with TaggedMetricName

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);
    }
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) Histogram(com.yammer.metrics.core.Histogram) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Counter(com.yammer.metrics.core.Counter) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) TaggedMetricName(com.wavefront.common.TaggedMetricName)

Example 3 with TaggedMetricName

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();
}
Also used : TaggedMetricName(com.wavefront.common.TaggedMetricName) MetricName(com.yammer.metrics.core.MetricName) TaggedMetricName(com.wavefront.common.TaggedMetricName)

Example 4 with TaggedMetricName

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\"")));
}
Also used : Counter(com.yammer.metrics.core.Counter) TaggedMetricName(com.wavefront.common.TaggedMetricName) Test(org.junit.Test)

Example 5 with TaggedMetricName

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\"")));
}
Also used : Counter(com.yammer.metrics.core.Counter) TaggedMetricName(com.wavefront.common.TaggedMetricName) Test(org.junit.Test)

Aggregations

TaggedMetricName (com.wavefront.common.TaggedMetricName)21 IOException (java.io.IOException)6 Test (org.junit.Test)5 Counter (com.yammer.metrics.core.Counter)4 MetricName (com.yammer.metrics.core.MetricName)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Histogram (com.yammer.metrics.core.Histogram)2 WavefrontHistogram (com.yammer.metrics.core.WavefrontHistogram)2 URI (java.net.URI)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 CachingHostnameLookupResolver (com.wavefront.agent.channel.CachingHostnameLookupResolver)1 ChannelUtils.writeHttpResponse (com.wavefront.agent.channel.ChannelUtils.writeHttpResponse)1 ConnectionTrackingHandler (com.wavefront.agent.channel.ConnectionTrackingHandler)1 HealthCheckManagerImpl (com.wavefront.agent.channel.HealthCheckManagerImpl)1