io.micrometer.core.instrument.config.NamingConvention Java Examples
The following examples show how to use
io.micrometer.core.instrument.config.NamingConvention.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SysdigStatsdLineBuilder.java From micrometer with Apache License 2.0 | 6 votes |
private void updateIfNamingConventionChanged() { NamingConvention next = config.namingConvention(); if (this.namingConvention != next) { this.name = sanitize(next.name(id.getName(), id.getType(), id.getBaseUnit())); synchronized (conventionTagsLock) { this.tags.clear(); this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ? id.getConventionTags(next).stream() .map(t -> sanitize(t.getKey()) + "=" + sanitize(t.getValue())) .collect(Collectors.joining(",")) : null; } this.tagsNoStat = tags(null, conventionTags, "=", "#"); this.namingConvention = next; } }
Example #2
Source File: MonitoringConfiguration.java From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License | 6 votes |
@Bean public MetricsExporter graphiteExporter(GraphiteConfig graphiteConfig, Clock clock) { NamingConvention namingConvention = namingConvention(); GraphiteMeterRegistry registry = new GraphiteMeterRegistry(graphiteConfig, (id, convention) -> { String prefix = "bookpub.app."; String tags = ""; if (id.getTags().iterator().hasNext()) { tags = "." + id.getConventionTags(convention).stream() .map(t -> t.getKey() + "." + t.getValue()) .map(nameSegment -> nameSegment.replace(" ", "_")) .collect(Collectors.joining(".")); } return prefix + id.getConventionName(convention) + tags; }, clock); registry.config().namingConvention(namingConvention); registry.start(); return () -> registry; }
Example #3
Source File: MonitoringConfiguration.java From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License | 6 votes |
@Bean public MetricsExporter graphiteExporter(GraphiteConfig graphiteConfig, Clock clock) { NamingConvention namingConvention = namingConvention(); GraphiteMeterRegistry registry = new GraphiteMeterRegistry(graphiteConfig, (id, convention) -> { String prefix = "bookpub.app."; String tags = ""; if (id.getTags().iterator().hasNext()) { tags = "." + id.getConventionTags(convention).stream() .map(t -> t.getKey() + "." + t.getValue()) .map(nameSegment -> nameSegment.replace(" ", "_")) .collect(Collectors.joining(".")); } return prefix + id.getConventionName(convention) + tags; }, clock); registry.config().namingConvention(namingConvention); registry.start(); return () -> registry; }
Example #4
Source File: DatadogStatsdLineBuilder.java From micrometer with Apache License 2.0 | 6 votes |
private void updateIfNamingConventionChanged() { NamingConvention next = config.namingConvention(); if (this.namingConvention != next) { synchronized (conventionTagsLock) { if (this.namingConvention == next) { return; } this.tags.clear(); this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ? id.getConventionTags(next).stream() .map(t -> formatTag(t)) .collect(Collectors.joining(",")) : null; } this.name = next.name(sanitizeName(id.getName()), id.getType(), id.getBaseUnit()) + ":"; this.tagsNoStat = tags(null, conventionTags, ":", "|#"); this.namingConvention = next; } }
Example #5
Source File: NewRelicMeterRegistry.java From micrometer with Apache License 2.0 | 6 votes |
NewRelicMeterRegistry(NewRelicConfig config, @Nullable NewRelicClientProvider clientProvider, NamingConvention namingConvention, Clock clock, ThreadFactory threadFactory) { super(config, clock); if (clientProvider == null) { //default to Insight API client provider if not specified in config or provided clientProvider = (config.clientProviderType() == ClientProviderType.INSIGHTS_AGENT) ? new NewRelicInsightsAgentClientProvider(config) : new NewRelicInsightsApiClientProvider(config); } this.clientProvider = clientProvider; thisConfig = new Config() { @Override public Config namingConvention(NamingConvention convention) { NewRelicMeterRegistry.this.clientProvider.setNamingConvention(convention); return super.namingConvention(convention); } }; config().namingConvention(namingConvention); start(threadFactory); }
Example #6
Source File: GangliaMeterRegistry.java From micrometer with Apache License 2.0 | 6 votes |
private GangliaMeterRegistry(GangliaConfig config, Clock clock, HierarchicalNameMapper nameMapper, ThreadFactory threadFactory) { super(config, clock); // Technically, Ganglia doesn't have any constraints on metric or tag names, but the encoding of Unicode can look // horrible in the UI. So be aware... this.config = config; this.nameMapper = nameMapper; config().namingConvention(NamingConvention.camelCase); try { this.ganglia = new GMetric(config.host(), config.port(), config.addressingMode(), config.ttl()); start(threadFactory); } catch (IOException e) { throw new RuntimeException("Failed to configure Ganglia metrics reporting", e); } }
Example #7
Source File: SignalFxMeterRegistry.java From micrometer with Apache License 2.0 | 6 votes |
private Stream<SignalFxProtocolBuffers.DataPoint.Builder> addMeter(Meter meter) { return stream(meter.measure().spliterator(), false).flatMap(measurement -> { String statSuffix = NamingConvention.camelCase.tagKey(measurement.getStatistic().toString()); switch (measurement.getStatistic()) { case TOTAL: case TOTAL_TIME: case COUNT: case DURATION: return Stream.of(addDatapoint(meter, COUNTER, statSuffix, measurement.getValue())); case MAX: case VALUE: case UNKNOWN: case ACTIVE_TASKS: return Stream.of(addDatapoint(meter, GAUGE, statSuffix, measurement.getValue())); } return Stream.empty(); }); }
Example #8
Source File: TelegrafStatsdLineBuilder.java From micrometer with Apache License 2.0 | 6 votes |
private void updateIfNamingConventionChanged() { NamingConvention next = config.namingConvention(); if (this.namingConvention != next) { synchronized (conventionTagsLock) { if (this.namingConvention == next) { return; } this.tags.clear(); this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ? id.getConventionTags(next).stream() .map(t -> telegrafEscape(t.getKey()) + "=" + telegrafEscape(t.getValue())) .collect(Collectors.joining(",")) : null; } this.name = telegrafEscape(next.name(id.getName(), id.getType(), id.getBaseUnit())); this.tagsNoStat = tags(null, conventionTags, "=", ","); this.namingConvention = next; } }
Example #9
Source File: GraphiteHierarchicalNameMapper.java From micrometer with Apache License 2.0 | 6 votes |
@Override public String toHierarchicalName(Meter.Id id, NamingConvention convention) { StringBuilder hierarchicalName = new StringBuilder(); for (String tagKey : tagsAsPrefix) { String tagValue = id.getTag(tagKey); if (tagValue != null) { hierarchicalName.append(convention.tagValue(tagValue)).append("."); } } hierarchicalName.append(id.getConventionName(convention)); for (Tag tag : id.getTagsAsIterable()) { if (!tagsAsPrefix.contains(tag.getKey())) { hierarchicalName.append('.').append(convention.tagKey(tag.getKey())) .append('.').append(convention.tagValue(tag.getValue())); } } return hierarchicalName.toString(); }
Example #10
Source File: MicrometerCollectorTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void sameValuesDifferentOrder() { Meter.Id id = Metrics.counter("my.counter").getId(); MicrometerCollector collector = new MicrometerCollector(id, NamingConvention.dot, PrometheusConfig.DEFAULT); Collector.MetricFamilySamples.Sample sample = new Collector.MetricFamilySamples.Sample("my_counter", asList("k", "k2"), asList("v1", "v2"), 1.0); Collector.MetricFamilySamples.Sample sample2 = new Collector.MetricFamilySamples.Sample("my_counter", asList("k", "k2"), asList("v2", "v1"), 1.0); collector.add(asList("v1", "v2"), (conventionName, tagKeys) -> Stream.of(new MicrometerCollector.Family(Collector.Type.COUNTER, "my_counter", sample))); collector.add(asList("v2", "v1"), (conventionName, tagKeys) -> Stream.of(new MicrometerCollector.Family(Collector.Type.COUNTER, "my_counter", sample2))); assertThat(collector.collect().get(0).samples).hasSize(2); }
Example #11
Source File: DatadogStatsdLineBuilderTest.java From micrometer with Apache License 2.0 | 5 votes |
@Issue("#1998") @Test void allowColonsInTagValues() { Counter c = registry.counter("my:counter", "my:tag", "my:value", "other_tag", "some:value:", "123.another.tag", "123:value"); DatadogStatsdLineBuilder lb = new DatadogStatsdLineBuilder(c.getId(), registry.config()); registry.config().namingConvention(NamingConvention.dot); assertThat(lb.line("1", Statistic.COUNT, "c")) .isEqualTo("my_counter:1|c|#statistic:count,m.123.another.tag:123:value,my_tag:my:value,other_tag:some:value_"); }
Example #12
Source File: StatsdMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
private static NamingConvention namingConventionFromFlavor(StatsdFlavor flavor) { switch (flavor) { case DATADOG: case SYSDIG: return NamingConvention.dot; case TELEGRAF: return NamingConvention.snakeCase; default: return NamingConvention.camelCase; } }
Example #13
Source File: SysdigStatsdLineBuilderTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void changingNamingConvention() { Counter c = registry.counter("my.counter", "my.tag", "value"); SysdigStatsdLineBuilder lb = new SysdigStatsdLineBuilder(c.getId(), registry.config()); registry.config().namingConvention(NamingConvention.dot); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my.counter#statistic=count,my.tag=value:1|c"); registry.config().namingConvention(NamingConvention.camelCase); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("myCounter#statistic=count,myTag=value:1|c"); }
Example #14
Source File: CustomNamingConvention.java From eventeum with Apache License 2.0 | 5 votes |
public String tagKey(String key) { String conventionKey = NamingConvention.snakeCase.tagKey(key); String sanitized = tagKeyChars.matcher(conventionKey).replaceAll("_"); if (!Character.isLetter(sanitized.charAt(0))) { sanitized = "m_" + sanitized; } return sanitized; }
Example #15
Source File: Configuration.java From azure-cosmosdb-java with MIT License | 5 votes |
@SuppressWarnings("UnstableApiUsage") private synchronized MeterRegistry graphiteMeterRegistry(String serviceAddress) { if (this.graphiteMeterRegistry == null) { HostAndPort address = HostAndPort.fromString(serviceAddress); String host = address.getHost(); int port = address.getPortOrDefault(DEFAULT_GRAPHITE_SERVER_PORT); boolean enabled = !Boolean.getBoolean("cosmos.monitoring.graphite.disabled"); Duration step = Duration.ofSeconds(Integer.getInteger("cosmos.monitoring.graphite.step", this.printingInterval)); final GraphiteConfig config = new GraphiteConfig() { private String[] tagNames = { "source" }; @Override @Nullable public String get(@Nullable String key) { return null; } @Override public boolean enabled() { return enabled; } @Override @Nullable public String host() { return host; } @Override @Nullable public int port() { return port; } @Override @Nullable public Duration step() { return step; } @Override @Nullable public String[] tagsAsPrefix() { return this.tagNames; } }; this.graphiteMeterRegistry = new GraphiteMeterRegistry(config, Clock.SYSTEM); String source; try { PercentEscaper escaper = new PercentEscaper("_-", false); source = escaper.escape(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException error) { source = "unknown-host"; } this.graphiteMeterRegistry.config() .namingConvention(NamingConvention.dot) .commonTags("source", source); } return this.graphiteMeterRegistry; }
Example #16
Source File: DropwizardMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
public DropwizardMeterRegistry(DropwizardConfig config, MetricRegistry registry, HierarchicalNameMapper nameMapper, Clock clock) { super(clock); config.requireValid(); this.dropwizardConfig = config; this.dropwizardClock = new DropwizardClock(clock); this.registry = registry; this.nameMapper = nameMapper; config() .namingConvention(NamingConvention.camelCase) .onMeterRemoved(this::onMeterRemoved); }
Example #17
Source File: LoggingMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
private LoggingMeterRegistry(LoggingRegistryConfig config, Clock clock, ThreadFactory threadFactory, Consumer<String> loggingSink, @Nullable Function<Meter, String> meterIdPrinter) { super(config, clock); this.config = config; this.loggingSink = loggingSink; this.meterIdPrinter = meterIdPrinter != null ? meterIdPrinter : defaultMeterIdPrinter(); config().namingConvention(NamingConvention.dot); start(threadFactory); }
Example #18
Source File: NewRelicMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void canChangeNamingConventionThroughConfig() { NamingConvention namingConvention1 = mock(NamingConvention.class); NamingConvention namingConvention2 = mock(NamingConvention.class); NewRelicMeterRegistry meterRegistry = NewRelicMeterRegistry.builder(insightsApiConfig).namingConvention(namingConvention1).build(); assertThat(meterRegistry.config().namingConvention()).isEqualTo(namingConvention1); assertThat(meterRegistry.clientProvider).isInstanceOf(NewRelicInsightsApiClientProvider.class); assertThat(((NewRelicInsightsApiClientProvider) meterRegistry.clientProvider).namingConvention).isEqualTo(namingConvention1); meterRegistry.config().namingConvention(namingConvention2); assertThat(meterRegistry.config().namingConvention()).isEqualTo(namingConvention2); assertThat(((NewRelicInsightsApiClientProvider) meterRegistry.clientProvider).namingConvention).isEqualTo(namingConvention2); }
Example #19
Source File: NewRelicMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void succeedsConfigInsightsAgentClientProviderAndCustomNamingConvention() { NamingConvention customNamingConvention = mock(NewRelicNamingConvention.class); NewRelicMeterRegistry registry = new NewRelicMeterRegistry(insightsAgentConfig, null, customNamingConvention, clock, new NamedThreadFactory("new-relic-test")); assertThat(registry.clientProvider).isInstanceOf(NewRelicInsightsAgentClientProvider.class); assertThat(((NewRelicInsightsAgentClientProvider) registry.clientProvider).namingConvention) .isSameAs(customNamingConvention); assertThat(registry.config().namingConvention()).isSameAs(customNamingConvention); }
Example #20
Source File: AtlasNamingConvention.java From micrometer with Apache License 2.0 | 5 votes |
@Override public String tagKey(String key) { if (key.equals("name")) { key = "name.tag"; } else if (key.equals("statistic")) { key = "statistic.tag"; } return NamingConvention.camelCase.tagKey(key); }
Example #21
Source File: DatadogStatsdLineBuilderTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void interpretEmptyTagValuesAsValuelessTags() { Counter c = registry.counter("my:counter", "my:tag", ""); DatadogStatsdLineBuilder lb = new DatadogStatsdLineBuilder(c.getId(), registry.config()); registry.config().namingConvention(NamingConvention.dot); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my_counter:1|c|#statistic:count,my_tag"); }
Example #22
Source File: DatadogStatsdLineBuilderTest.java From micrometer with Apache License 2.0 | 5 votes |
@Issue("#739") @Test void sanitizeColonsInTagKeys() { Counter c = registry.counter("my:counter", "my:tag", "my_value"); DatadogStatsdLineBuilder lb = new DatadogStatsdLineBuilder(c.getId(), registry.config()); registry.config().namingConvention(NamingConvention.dot); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my_counter:1|c|#statistic:count,my_tag:my_value"); }
Example #23
Source File: DatadogStatsdLineBuilderTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void changingNamingConvention() { Counter c = registry.counter("my.counter", "my.tag", "value"); DatadogStatsdLineBuilder lb = new DatadogStatsdLineBuilder(c.getId(), registry.config()); registry.config().namingConvention(NamingConvention.dot); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my.counter:1|c|#statistic:count,my.tag:value"); registry.config().namingConvention(NamingConvention.camelCase); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("myCounter:1|c|#statistic:count,myTag:value"); }
Example #24
Source File: TelegrafStatsdLineBuilderTest.java From micrometer with Apache License 2.0 | 5 votes |
@Issue("#739") @Test void sanitizeColons() { Counter c = registry.counter("my:counter", "my:tag", "my:value"); TelegrafStatsdLineBuilder lb = new TelegrafStatsdLineBuilder(c.getId(), registry.config()); registry.config().namingConvention(NamingConvention.dot); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my_counter,statistic=count,my_tag=my_value:1|c"); }
Example #25
Source File: TelegrafStatsdLineBuilderTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void changingNamingConvention() { Counter c = registry.counter("my.counter", "my.tag", "value"); TelegrafStatsdLineBuilder lb = new TelegrafStatsdLineBuilder(c.getId(), registry.config()); registry.config().namingConvention(NamingConvention.dot); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my.counter,statistic=count,my.tag=value:1|c"); registry.config().namingConvention(NamingConvention.camelCase); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("myCounter,statistic=count,myTag=value:1|c"); }
Example #26
Source File: SysdigStatsdLineBuilderTest.java From micrometer with Apache License 2.0 | 5 votes |
@Issue("#739") @Test void sanitizeColons() { Counter c = registry.counter("my:counter", "my:tag", "my:value"); SysdigStatsdLineBuilder lb = new SysdigStatsdLineBuilder(c.getId(), registry.config()); registry.config().namingConvention(NamingConvention.dot); assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my_counter#statistic=count,my_tag=my_value:1|c"); }
Example #27
Source File: NewRelicClientProvider.java From micrometer with Apache License 2.0 | 5 votes |
default String getEventType(Meter.Id id, NewRelicConfig config, NamingConvention namingConvention) { if (config.meterNameEventTypeEnabled()) { //meter/metric name event type return id.getConventionName(namingConvention); } else { //static eventType "category" return config.eventType(); } }
Example #28
Source File: EtsyStatsdLineBuilder.java From micrometer with Apache License 2.0 | 5 votes |
private void updateIfNamingConventionChanged() { NamingConvention next = config.namingConvention(); if (this.namingConvention != next) { this.namingConvention = next; this.nameNoStat = null; this.names.clear(); } }
Example #29
Source File: NewRelicInsightsAgentClientProvider.java From micrometer with Apache License 2.0 | 5 votes |
NewRelicInsightsAgentClientProvider(NewRelicConfig config, Agent newRelicAgent, NamingConvention namingConvention) { config.requireValid(); this.config = config; this.newRelicAgent = newRelicAgent; this.namingConvention = namingConvention; }
Example #30
Source File: NewRelicInsightsApiClientProvider.java From micrometer with Apache License 2.0 | 5 votes |
NewRelicInsightsApiClientProvider(NewRelicConfig config, HttpSender httpClient, NamingConvention namingConvention) { config.validateForInsightsApi().orThrow(); this.config = config; this.httpClient = httpClient; this.namingConvention = namingConvention; this.insightsEndpoint = config.uri() + "/v1/accounts/" + config.accountId() + "/events"; }