io.micrometer.core.instrument.util.HierarchicalNameMapper Java Examples

The following examples show how to use io.micrometer.core.instrument.util.HierarchicalNameMapper. 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: MoreNamingConventionsTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
private static DropwizardMeterRegistry newDropwizardRegistry() {
    return new DropwizardMeterRegistry(new DropwizardConfig() {
        @Override
        public String prefix() {
            return "dropwizard";
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }
    }, new MetricRegistry(), HierarchicalNameMapper.DEFAULT, Clock.SYSTEM) {
        @Override
        protected Double nullGaugeValue() {
            return 0.0;
        }
    };
}
 
Example #2
Source File: DropwizardMeterRegistries.java    From armeria with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a newly-created {@link DropwizardMeterRegistry} instance with the specified
 * {@link MetricRegistry}, {@link HierarchicalNameMapper} and {@link Clock}.
 */
public static DropwizardMeterRegistry newRegistry(MetricRegistry registry,
                                                  HierarchicalNameMapper nameMapper,
                                                  Clock clock) {
    final DropwizardMeterRegistry meterRegistry = new DropwizardMeterRegistry(
            DEFAULT_DROPWIZARD_CONFIG,
            requireNonNull(registry, "registry"),
            requireNonNull(nameMapper, "nameMapper"),
            requireNonNull(clock, "clock")) {

        @Override
        protected Double nullGaugeValue() {
            return 0.0;
        }
    };

    return configureRegistry(meterRegistry);
}
 
Example #3
Source File: JHipsterLoggingMetricsExportConfiguration.java    From jhipster with Apache License 2.0 6 votes vote down vote up
/**
 * <p>consoleLoggingRegistry.</p>
 *
 * @param dropwizardRegistry a {@link com.codahale.metrics.MetricRegistry} object.
 * @return a {@link io.micrometer.core.instrument.MeterRegistry} object.
 */
@Bean
public MeterRegistry consoleLoggingRegistry(MetricRegistry dropwizardRegistry) {
    DropwizardConfig dropwizardConfig = new DropwizardConfig() {
        @Override
        public String prefix() {
            return "console";
        }

        @Override
        public String get(String key) {
            return null;
        }
    };

    return new DropwizardMeterRegistry(dropwizardConfig, dropwizardRegistry, HierarchicalNameMapper.DEFAULT, Clock.SYSTEM) {
        @Override
        protected Double nullGaugeValue() {
            return null;
        }
    };
}
 
Example #4
Source File: GangliaMeterRegistry.java    From micrometer with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: DropwizardMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: GraphiteMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new GraphiteMeterRegistry(new GraphiteConfig() {
        @Override
        public boolean enabled() {
            return false;
        }

        @Override
        @Nullable
        public String get(String key) {
            return null;
        }
    }, new MockClock(), HierarchicalNameMapper.DEFAULT);
}
 
Example #7
Source File: GraphiteMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public GraphiteMeterRegistry(GraphiteConfig config, Clock clock, HierarchicalNameMapper nameMapper,
                             MetricRegistry metricRegistry, GraphiteReporter reporter) {
    super(config, metricRegistry, nameMapper, clock);

    this.config = config;
    config().namingConvention(config.graphiteTagsEnabled() ? new GraphiteDimensionalNamingConvention() : new GraphiteHierarchicalNamingConvention());
    this.reporter = reporter;

    start();
}
 
Example #8
Source File: EtsyStatsdLineBuilderTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void changingNamingConvention() {
    Counter c = registry.counter("my.counter", "my.tag", "value");
    EtsyStatsdLineBuilder lb = new EtsyStatsdLineBuilder(c.getId(), registry.config(), HierarchicalNameMapper.DEFAULT);

    registry.config().namingConvention(NamingConvention.dot);
    assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my.counter.my.tag.value.statistic.count:1|c");

    registry.config().namingConvention(NamingConvention.camelCase);
    assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("myCounter.myTag.value.statistic.count:1|c");
}
 
Example #9
Source File: EtsyStatsdLineBuilderTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Issue("#739")
@Test
void sanitizeColons() {
    Counter c = registry.counter("my:counter", "my:tag", "my:value");
    EtsyStatsdLineBuilder lb = new EtsyStatsdLineBuilder(c.getId(), registry.config(), HierarchicalNameMapper.DEFAULT);

    registry.config().namingConvention(NamingConvention.dot);
    assertThat(lb.line("1", Statistic.COUNT, "c")).isEqualTo("my_counter.my_tag.my_value.statistic.count:1|c");
}
 
Example #10
Source File: JmxMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public JmxMeterRegistry(JmxConfig config, Clock clock) {
    this(config, clock, HierarchicalNameMapper.DEFAULT);
}
 
Example #11
Source File: DropwizardMeterRegistries.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a newly-created {@link DropwizardMeterRegistry} instance with the specified
 * {@link MetricRegistry} and {@link HierarchicalNameMapper}.
 */
public static DropwizardMeterRegistry newRegistry(MetricRegistry registry,
                                                  HierarchicalNameMapper nameMapper) {
    return newRegistry(registry, nameMapper, Clock.SYSTEM);
}
 
Example #12
Source File: GraphiteMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public GraphiteMeterRegistry(GraphiteConfig config, Clock clock, HierarchicalNameMapper nameMapper,
                             MetricRegistry metricRegistry) {
    this(config, clock, nameMapper, metricRegistry, defaultGraphiteReporter(config, clock, metricRegistry));
}
 
Example #13
Source File: GraphiteMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public GraphiteMeterRegistry(GraphiteConfig config, Clock clock, HierarchicalNameMapper nameMapper) {
    this(config, clock, nameMapper, new MetricRegistry());
}
 
Example #14
Source File: StatsdMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
private StatsdMeterRegistry(StatsdConfig config,
                            HierarchicalNameMapper nameMapper,
                            NamingConvention namingConvention,
                            Clock clock,
                            @Nullable Function<Meter.Id, StatsdLineBuilder> lineBuilderFunction,
                            @Nullable Consumer<String> lineSink) {
    super(clock);

    config.requireValid();

    this.statsdConfig = config;
    this.nameMapper = nameMapper;
    this.lineBuilderFunction = lineBuilderFunction;
    this.lineSink = lineSink;

    config().namingConvention(namingConvention);

    config().onMeterRemoved(meter ->
            meter.use(
                    this::removePollableMeter,
                    c -> ((StatsdCounter) c).shutdown(),
                    t -> ((StatsdTimer) t).shutdown(),
                    d -> ((StatsdDistributionSummary) d).shutdown(),
                    this::removePollableMeter,
                    this::removePollableMeter,
                    this::removePollableMeter,
                    this::removePollableMeter,
                    m -> {
                        for (Measurement measurement : m.measure()) {
                            pollableMeters.remove(m.getId().withTag(measurement.getStatistic()));
                        }
                    })
    );

    if (config.enabled()) {
        FluxSink<String> fluxSink = processor.sink();

        try {
            Class.forName("ch.qos.logback.classic.turbo.TurboFilter", false, getClass().getClassLoader());
            this.fluxSink = new LogbackMetricsSuppressingFluxSink(fluxSink);
        } catch (ClassNotFoundException e) {
            this.fluxSink = fluxSink;
        }
        start();
    }
}
 
Example #15
Source File: StatsdMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public StatsdMeterRegistry(StatsdConfig config, Clock clock) {
    this(config, HierarchicalNameMapper.DEFAULT, clock);
}
 
Example #16
Source File: EtsyStatsdLineBuilder.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public EtsyStatsdLineBuilder(Meter.Id id, MeterRegistry.Config config, HierarchicalNameMapper nameMapper) {
    super(id, config);
    this.nameMapper = nameMapper;
}
 
Example #17
Source File: JmxMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new JmxMeterRegistry(JmxConfig.DEFAULT, new MockClock(), HierarchicalNameMapper.DEFAULT);
}
 
Example #18
Source File: JmxMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public JmxMeterRegistry(JmxConfig config, Clock clock, HierarchicalNameMapper nameMapper, MetricRegistry metricRegistry,
                        JmxReporter jmxReporter) {
    super(config, metricRegistry, nameMapper, clock);
    this.reporter = jmxReporter;
    this.reporter.start();
}
 
Example #19
Source File: JmxMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public JmxMeterRegistry(JmxConfig config, Clock clock, HierarchicalNameMapper nameMapper, MetricRegistry metricRegistry) {
    this(config, clock, nameMapper, metricRegistry, defaultJmxReporter(config, metricRegistry));
}
 
Example #20
Source File: JmxMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public JmxMeterRegistry(JmxConfig config, Clock clock, HierarchicalNameMapper nameMapper) {
    this(config, clock, nameMapper, new MetricRegistry());
}
 
Example #21
Source File: GangliaMeterRegistry.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * @param config     The registry configuration.
 * @param clock      The clock to use for timings.
 * @param nameMapper The name mapper to use in converting dimensional metrics to hierarchical names.
 * @deprecated Use {@link #builder(GangliaConfig)} instead.
 */
@Deprecated
public GangliaMeterRegistry(GangliaConfig config, Clock clock, HierarchicalNameMapper nameMapper) {
    this(config, clock, nameMapper, DEFAULT_THREAD_FACTORY);
}
 
Example #22
Source File: GangliaMeterRegistry.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * @param config The registry configuration.
 * @param clock  The clock to use for timings.
 */
public GangliaMeterRegistry(GangliaConfig config, Clock clock) {
    this(config, clock, HierarchicalNameMapper.DEFAULT, DEFAULT_THREAD_FACTORY);
}
 
Example #23
Source File: GangliaMeterRegistry.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * @param config         The registry configuration.
 * @param clock          The clock to use for timings.
 * @param nameMapper     The name mapper to use in converting dimensional metrics to hierarchical names.
 * @param metricRegistry Ignored as of Micrometer 1.1.0.
 * @deprecated The Ganglia registry no longer uses Dropwizard as of Micrometer 1.1.0, because Dropwizard
 * dropped support for Ganglia in its 4.0.0 release. Use {@link #builder(GangliaConfig)} instead.
 */
@SuppressWarnings("unused")
@Deprecated
public GangliaMeterRegistry(GangliaConfig config, Clock clock, HierarchicalNameMapper nameMapper, MetricRegistry metricRegistry) {
    this(config, clock, nameMapper);
}
 
Example #24
Source File: StatsdMeterRegistry.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * Use this constructor for Etsy-flavored StatsD when you need to influence the way Micrometer's dimensional {@link Meter.Id}
 * is written to a flat hierarchical name.
 *
 * @param config     The StatsD configuration.
 * @param nameMapper A strategy for flattening dimensional IDs.
 * @param clock      The clock to use for timing and polling certain types of meters.
 */
public StatsdMeterRegistry(StatsdConfig config, HierarchicalNameMapper nameMapper, Clock clock) {
    this(config, nameMapper, namingConventionFromFlavor(config.flavor()), clock, null, null);
}
 
Example #25
Source File: DropwizardMeterRegistries.java    From armeria with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a newly-created {@link DropwizardMeterRegistry} instance with the specified
 * {@link HierarchicalNameMapper}.
 */
public static DropwizardMeterRegistry newRegistry(HierarchicalNameMapper nameMapper) {
    return newRegistry(new MetricRegistry(), nameMapper, Clock.SYSTEM);
}
 
Example #26
Source File: DropwizardMeterRegistries.java    From armeria with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a newly-created {@link DropwizardMeterRegistry} instance with the specified
 * {@link HierarchicalNameMapper} and {@link Clock}.
 */
public static DropwizardMeterRegistry newRegistry(HierarchicalNameMapper nameMapper, Clock clock) {
    return newRegistry(new MetricRegistry(), nameMapper, clock);
}