Search in sources :

Example 1 with MetricMatcher

use of com.wavefront.agent.config.MetricMatcher in project java by wavefrontHQ.

the class EvictingMetricsRegistry method put.

@SuppressWarnings("unchecked")
private <M extends Metric> M put(MetricName metricName, MetricMatcher metricMatcher, Function<MetricName, M> getter) {
    @Nullable Metric cached = metricCache.getIfPresent(metricName);
    Objects.requireNonNull(metricNamesForMetricMatchers.get(metricMatcher)).add(metricName);
    if (cached != null && cached == metricsRegistry.allMetrics().get(metricName)) {
        return (M) cached;
    }
    return (M) metricCache.asMap().compute(metricName, (name, existing) -> {
        @Nullable Metric expected = metricsRegistry.allMetrics().get(name);
        return expected == null ? getter.apply(name) : expected;
    });
}
Also used : Ticker(com.github.benmanes.caffeine.cache.Ticker) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Counter(com.yammer.metrics.core.Counter) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) Set(java.util.Set) Histogram(com.yammer.metrics.core.Histogram) Cache(com.github.benmanes.caffeine.cache.Cache) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) MetricMatcher(com.wavefront.agent.config.MetricMatcher) CacheWriter(com.github.benmanes.caffeine.cache.CacheWriter) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) Gauge(com.yammer.metrics.core.Gauge) DeltaCounter(com.yammer.metrics.core.DeltaCounter) MetricName(com.yammer.metrics.core.MetricName) Metric(com.yammer.metrics.core.Metric) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) RemovalCause(com.github.benmanes.caffeine.cache.RemovalCause) Metric(com.yammer.metrics.core.Metric) Nullable(javax.annotation.Nullable)

Example 2 with MetricMatcher

use of com.wavefront.agent.config.MetricMatcher in project java by wavefrontHQ.

the class LogsIngester method ingestLog.

public void ingestLog(LogsMessage logsMessage) {
    LogsIngestionConfig logsIngestionConfig = logsIngestionConfigManager.getConfig();
    boolean success = false;
    for (MetricMatcher metricMatcher : logsIngestionConfig.counters) {
        success |= maybeIngestLog(evictingMetricsRegistry::getCounter, metricMatcher, logsMessage);
    }
    for (MetricMatcher metricMatcher : logsIngestionConfig.gauges) {
        success |= maybeIngestLog(evictingMetricsRegistry::getGauge, metricMatcher, logsMessage);
    }
    for (MetricMatcher metricMatcher : logsIngestionConfig.histograms) {
        success |= maybeIngestLog(evictingMetricsRegistry::getHistogram, metricMatcher, logsMessage);
    }
    if (success) {
        parsed.inc();
    } else {
        unparsed.inc();
    }
}
Also used : MetricMatcher(com.wavefront.agent.config.MetricMatcher) LogsIngestionConfig(com.wavefront.agent.config.LogsIngestionConfig)

Example 3 with MetricMatcher

use of com.wavefront.agent.config.MetricMatcher in project java by wavefrontHQ.

the class LogsIngesterTest method testHotloadedConfigClearsOldMetrics.

@Test
public void testHotloadedConfigClearsOldMetrics() throws Exception {
    setup(parseConfigFile("test.yml"));
    assertThat(getPoints(1, "plainCounter"), contains(PointMatchers.matches(1L, MetricConstants.DELTA_PREFIX + "plainCounter", ImmutableMap.of())));
    // once the counter is reported, it is reset because now it is treated as delta counter.
    // hence we check that plainCounter has value 1L below.
    assertThat(getPoints(2, "plainCounter", "counterWithValue 42"), containsInAnyOrder(ImmutableList.of(PointMatchers.matches(42L, MetricConstants.DELTA_PREFIX + "counterWithValue", ImmutableMap.of()), PointMatchers.matches(1L, MetricConstants.DELTA_PREFIX + "plainCounter", ImmutableMap.of()))));
    List<MetricMatcher> counters = Lists.newCopyOnWriteArrayList(logsIngestionConfig.counters);
    int oldSize = counters.size();
    counters.removeIf((metricMatcher -> metricMatcher.getPattern().equals("plainCounter")));
    assertThat(counters, hasSize(oldSize - 1));
    // Get a new config file because the SUT has a reference to the old one, and we'll be monkey patching
    // this one.
    logsIngestionConfig = parseConfigFile("test.yml");
    logsIngestionConfig.verifyAndInit();
    logsIngestionConfig.counters = counters;
    logsIngesterUnderTest.logsIngestionConfigManager.forceConfigReload();
    // once the counter is reported, it is reset because now it is treated as delta counter.
    // since zero values are filtered out, no new values are expected.
    assertThat(getPoints(0, "plainCounter"), emptyIterable());
}
Also used : ReportableEntityHandler(com.wavefront.agent.handlers.ReportableEntityHandler) EasyMock.reset(org.easymock.EasyMock.reset) Map(java.util.Map) After(org.junit.After) HandlerKey(com.wavefront.agent.handlers.HandlerKey) ReportPoint(wavefront.report.ReportPoint) GrokException(oi.thekraken.grok.api.exception.GrokException) LogsIngestionConfig(com.wavefront.agent.config.LogsIngestionConfig) ImmutableMap(com.google.common.collect.ImmutableMap) InetSocketAddress(java.net.InetSocketAddress) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReportableEntityType(com.wavefront.data.ReportableEntityType) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PointMatchers(com.wavefront.agent.PointMatchers) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetricMatcher(com.wavefront.agent.config.MetricMatcher) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) RawLogsIngesterPortUnificationHandler(com.wavefront.agent.listeners.RawLogsIngesterPortUnificationHandler) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) Matchers.lessThan(org.hamcrest.Matchers.lessThan) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ConfigurationException(com.wavefront.agent.config.ConfigurationException) EasyMock.replay(org.easymock.EasyMock.replay) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) EasyMock.createMock(org.easymock.EasyMock.createMock) TokenAuthenticatorBuilder(com.wavefront.agent.auth.TokenAuthenticatorBuilder) MetricConstants(com.wavefront.common.MetricConstants) Capture(org.easymock.Capture) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) EasyMock.expect(org.easymock.EasyMock.expect) Maps(com.google.common.collect.Maps) File(java.io.File) Message(org.logstash.beats.Message) Consumer(java.util.function.Consumer) Channel(io.netty.channel.Channel) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) AtomicLong(java.util.concurrent.atomic.AtomicLong) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) CaptureType(org.easymock.CaptureType) ReportableEntityHandlerFactory(com.wavefront.agent.handlers.ReportableEntityHandlerFactory) NoopHealthCheckManager(com.wavefront.agent.channel.NoopHealthCheckManager) EasyMock.verify(org.easymock.EasyMock.verify) Histogram(wavefront.report.Histogram) MetricMatcher(com.wavefront.agent.config.MetricMatcher) ReportPoint(wavefront.report.ReportPoint) Test(org.junit.Test)

Aggregations

MetricMatcher (com.wavefront.agent.config.MetricMatcher)3 LogsIngestionConfig (com.wavefront.agent.config.LogsIngestionConfig)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Cache (com.github.benmanes.caffeine.cache.Cache)1 CacheWriter (com.github.benmanes.caffeine.cache.CacheWriter)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 RemovalCause (com.github.benmanes.caffeine.cache.RemovalCause)1 Ticker (com.github.benmanes.caffeine.cache.Ticker)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 PointMatchers (com.wavefront.agent.PointMatchers)1 TokenAuthenticatorBuilder (com.wavefront.agent.auth.TokenAuthenticatorBuilder)1 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)1 ConfigurationException (com.wavefront.agent.config.ConfigurationException)1 HandlerKey (com.wavefront.agent.handlers.HandlerKey)1