io.micrometer.graphite.GraphiteMeterRegistry Java Examples

The following examples show how to use io.micrometer.graphite.GraphiteMeterRegistry. 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: MonitoringConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
@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 #2
Source File: MonitoringConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
@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 vote down vote up
@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: MicrometerMetricsExamples.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
public void setupWithCompositeRegistry() {
  CompositeMeterRegistry myRegistry = new CompositeMeterRegistry();
  myRegistry.add(new JmxMeterRegistry(s -> null, Clock.SYSTEM));
  myRegistry.add(new GraphiteMeterRegistry(s -> null, Clock.SYSTEM));

  Vertx vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setMicrometerRegistry(myRegistry)
      .setEnabled(true)));
}
 
Example #5
Source File: MonitoringConfigurationIntegrationTest.java    From waggle-dance with Apache License 2.0 6 votes vote down vote up
@Test
public void graphiteReporterAllMetricsAreLoggedWhenPollNotCalled() throws Exception {
  String graphitePrefix = "graphitePrefix";

  graphiteConfiguration.setHost("localhost");
  graphiteConfiguration.setPort(graphite.port());
  graphiteConfiguration.setPrefix(graphitePrefix);

  // Using a very long poll interval so it won't actually poll in the test, this is because we want to test that the
  // GraphiteReporter (ScheduledReporter) report() method is called to flush the remaining metrics before closing.
  long longPollInterval = 1000000;
  graphiteConfiguration.setPollInterval(longPollInterval);
  graphiteConfiguration.init();

  MonitoringConfiguration monitoringConfiguration = new MonitoringConfiguration();
  GraphiteMeterRegistry graphiteMeterRegistry = monitoringConfiguration.graphiteMeterRegistry(graphiteConfiguration);

  graphiteMeterRegistry.counter("test-counter").increment();
  graphiteMeterRegistry.close();

  Set<String> metrics = new TreeSet<>(Arrays.asList(new String(graphite.getOutput()).split("\n")));
  assertMetricContainsPrefix(metrics, graphitePrefix + ".test-counter");
}
 
Example #6
Source File: Configuration.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
@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 #7
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public static GraphiteMeterRegistry graphite() {
    return new GraphiteMeterRegistry(new GraphiteConfig() {
        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }
    }, Clock.SYSTEM);
}
 
Example #8
Source File: MicrometerBasedMetricsTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Gets the Micrometer registries that the tests should be run against.
 *
 * @return The registries.
 */
public static Stream<MeterRegistry> registries() {
    return Stream.of(new MeterRegistry[] {
                            new PrometheusMeterRegistry(PrometheusConfig.DEFAULT),
                            new GraphiteMeterRegistry(GraphiteConfig.DEFAULT, Clock.SYSTEM)
                            });
}