io.micrometer.prometheus.PrometheusMeterRegistry Java Examples

The following examples show how to use io.micrometer.prometheus.PrometheusMeterRegistry. 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: CentralDogma.java    From centraldogma with Apache License 2.0 7 votes vote down vote up
private void configureMetrics(ServerBuilder sb, PrometheusMeterRegistry registry) {
    sb.meterRegistry(registry);
    sb.service(METRICS_PATH, new PrometheusExpositionService(registry.getPrometheusRegistry()));
    sb.decorator(MetricCollectingService.newDecorator(MeterIdPrefixFunction.ofDefault("api")));

    // Bind system metrics.
    new FileDescriptorMetrics().bindTo(registry);
    new ProcessorMetrics().bindTo(registry);
    new ClassLoaderMetrics().bindTo(registry);
    new UptimeMetrics().bindTo(registry);
    new DiskSpaceMetrics(cfg.dataDir()).bindTo(registry);
    new JvmGcMetrics().bindTo(registry);
    new JvmMemoryMetrics().bindTo(registry);
    new JvmThreadMetrics().bindTo(registry);

    // Bind global thread pool metrics.
    ExecutorServiceMetrics.monitor(registry, ForkJoinPool.commonPool(), "commonPool");
}
 
Example #2
Source File: CoreModule.java    From EDDI with Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
public PrometheusMeterRegistry providePrometheusMeterRegistry(ExecutorService executorService,
                                                              @Named("systemRuntime.projectName") String projectName) {
    PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    new LogbackMetrics().bindTo(registry);
    new ClassLoaderMetrics().bindTo(registry);
    new ExecutorServiceMetrics(executorService,
            projectName + "-ExecutorService",
            () -> Tags.of(projectName, "ExecutorService").iterator()).bindTo(registry);
    new JvmMemoryMetrics().bindTo(registry);
    new JvmGcMetrics().bindTo(registry);
    new JvmThreadMetrics().bindTo(registry);
    new ProcessorMetrics().bindTo(registry);
    new ProcessMemoryMetrics().bindTo(registry);
    new ProcessThreadMetrics().bindTo(registry);
    new FileDescriptorMetrics().bindTo(registry);
    new DiskSpaceMetrics(new File("/")).bindTo(registry);
    new UptimeMetrics().bindTo(registry);

    registry.config().commonTags("instance", projectName);
    registry.config().commonTags("application", projectName);
    registry.config().commonTags("service", projectName);

    return registry;
}
 
Example #3
Source File: CustomMicrometerMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPublishQuantilesWithProvidedRegistry(TestContext context) throws Exception {
  PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)
        .setPublishQuantiles(true)
        .setStartEmbeddedServer(true)
        .setEmbeddedServerOptions(new HttpServerOptions().setPort(9090)))
      .setMicrometerRegistry(registry)
      .setEnabled(true)));

  Async async = context.async();
  // Dummy connection to trigger some metrics
  PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", r1 -> {
    // Delay to make "sure" metrics are populated
    vertx.setTimer(500, l -> {
      assertThat(registry.scrape()).contains("vertx_http_client_responseTime_seconds_bucket{code=\"200\"");
      async.complete();
    });
  });
  async.awaitSuccess(10000);
}
 
Example #4
Source File: DropwizardMeterRegistriesTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Test
void filteredGaugesDoNotAffectOthers() {
    final CompositeMeterRegistry micrometer = new CompositeMeterRegistry();
    final PrometheusMeterRegistry prometheus = PrometheusMeterRegistries.newRegistry();
    final DropwizardMeterRegistry dropwizard = DropwizardMeterRegistries.newRegistry();
    micrometer.add(prometheus).add(dropwizard);
    final DistributionSummary summary = DistributionSummary.builder("summary")
                                                           .publishPercentiles(0.5, 0.99)
                                                           .register(micrometer);
    summary.record(42);

    // Make sure Dropwizard registry does not have unwanted gauges.
    assertThat(dropwizard.getDropwizardRegistry().getMetrics()).containsOnlyKeys("summary");

    // Make sure Prometheus registry collects all samples.
    final MetricFamilySamples prometheusSamples = findPrometheusSample(prometheus, "summary");
    assertThat(prometheusSamples.samples).containsExactly(
            new Sample("summary", ImmutableList.of("quantile"), ImmutableList.of("0.5"), 42),
            new Sample("summary", ImmutableList.of("quantile"), ImmutableList.of("0.99"), 42),
            new Sample("summary_count", ImmutableList.of(), ImmutableList.of(), 1),
            new Sample("summary_sum", ImmutableList.of(), ImmutableList.of(), 42));
}
 
Example #5
Source File: BackendRegistries.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new backend registry, containing a micrometer registry, initialized with the provided options.
 * If a registry already exists with the associated name, it is just returned without any effect.
 * @param options micrometer options, including configuration related to the backend.
 *                Should be a subclass of {@link MicrometerMetricsOptions} (ex: {@link VertxInfluxDbOptions}, {@link VertxPrometheusOptions}).
 *                If the class is not recognized, a {@link NoopBackendRegistry} will be returned.
 * @return the created (or existing) {@link BackendRegistry}
 */
public static BackendRegistry setupBackend(MicrometerMetricsOptions options) {
  return REGISTRIES.computeIfAbsent(options.getRegistryName(), k -> {
    final BackendRegistry reg;
    if (options.getMicrometerRegistry() != null) {
      if (options.getPrometheusOptions() != null && options.getMicrometerRegistry() instanceof PrometheusMeterRegistry) {
        // If a Prometheus registry is provided, extra initialization steps may have to be performed
        reg = new PrometheusBackendRegistry(options.getPrometheusOptions(), (PrometheusMeterRegistry) options.getMicrometerRegistry());
      } else {
        // Other backend registries have no special extra steps
        reg = options::getMicrometerRegistry;
      }
    } else if (options.getInfluxDbOptions() != null && options.getInfluxDbOptions().isEnabled()) {
      reg = new InfluxDbBackendRegistry(options.getInfluxDbOptions());
    } else if (options.getPrometheusOptions() != null && options.getPrometheusOptions().isEnabled()) {
      reg = new PrometheusBackendRegistry(options.getPrometheusOptions());
    } else if (options.getJmxMetricsOptions() != null && options.getJmxMetricsOptions().isEnabled()) {
      reg = new JmxBackendRegistry(options.getJmxMetricsOptions());
    } else {
      // No backend setup, use global registry
      reg = NoopBackendRegistry.INSTANCE;
    }
    registerMatchers(reg.getMeterRegistry(), options.getLabels(), options.getLabelMatches());
    return reg;
  });
}
 
Example #6
Source File: PrometheusScrapingHandlerImpl.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext rc) {
  MeterRegistry registry;
  if (registryName == null) {
    registry = BackendRegistries.getDefaultNow();
  } else {
    registry = BackendRegistries.getNow(registryName);
  }
  if (registry instanceof PrometheusMeterRegistry) {
    PrometheusMeterRegistry prometheusMeterRegistry = (PrometheusMeterRegistry) registry;
    rc.response()
      .putHeader(HttpHeaders.CONTENT_TYPE, TextFormat.CONTENT_TYPE_004)
      .end(prometheusMeterRegistry.scrape());
  } else {
    String statusMessage = "Invalid registry: " + (registry != null ? registry.getClass().getName() : null);
    rc.response()
      .setStatusCode(500).setStatusMessage(statusMessage)
      .end();
  }
}
 
Example #7
Source File: PrometheusMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBindExistingServer(TestContext context) {
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
      .setEnabled(true)));

  Router router = Router.router(vertx);
  router.route("/custom").handler(routingContext -> {
    PrometheusMeterRegistry prometheusRegistry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
    String response = prometheusRegistry.scrape();
    routingContext.response().end(response);
  });
  vertx.createHttpServer().requestHandler(router).exceptionHandler(context.exceptionHandler()).listen(8081);

  Async async = context.async();
  PrometheusTestHelper.tryConnect(vertx, context, 8081, "localhost", "/custom", body -> {
    context.verify(v -> assertThat(body.toString())
          .contains("vertx_http_"));
    async.complete();
  });
  async.awaitSuccess(10000);
}
 
Example #8
Source File: PrometheusMetricsReporterConfiguration.java    From java-metrics with Apache License 2.0 6 votes vote down vote up
@Bean
public MetricsReporter prometheusMetricsReporter(PrometheusMeterRegistry prometheusMeterRegistry) {
    Metrics.addRegistry(prometheusMeterRegistry);

    MicrometerMetricsReporter.Builder builder = MicrometerMetricsReporter.newMetricsReporter();
    if (metricsName != null && !metricsName.isEmpty()) {
        builder.withName(metricsName);
    }

    if (metricLabels != null && !metricLabels.isEmpty()) {
        for (MetricLabel label : metricLabels) {
            builder.withCustomLabel(label);
        }
    }
    return builder.build();
}
 
Example #9
Source File: SimpleMetricsPublishingService.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
@Override
public void start(MetricsSession session) {
  registry = new PrometheusMeterRegistry(DEFAULT);
  session.addSubregistry(registry);

  InetSocketAddress address = new InetSocketAddress(HOSTNAME, port);
  server = null;
  try {
    server = HttpServer.create(address, 0);

    HttpContext context = server.createContext("/");
    context.setHandler(this::requestHandler);
    server.start();

    int boundPort = server.getAddress().getPort();
    LOG.info("Started {} http://{}:{}/", getClass().getSimpleName(), HOSTNAME, boundPort);
  } catch (IOException thrown) {
    LOG.error("Exception while starting " + getClass().getSimpleName(), thrown);
  }
}
 
Example #10
Source File: SimpleMetricsPublishingService.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
@Override
public void start(MetricsSession session) {
  registry = new PrometheusMeterRegistry(DEFAULT);
  session.addSubregistry(registry);

  InetSocketAddress address = new InetSocketAddress(HOSTNAME, port);
  server = null;
  try {
    server = HttpServer.create(address, 0);

    HttpContext context = server.createContext("/");
    context.setHandler(this::requestHandler);
    server.start();

    int boundPort = server.getAddress().getPort();
    LOG.info("Started {} http://{}:{}/", getClass().getSimpleName(), HOSTNAME, boundPort);
  } catch (IOException thrown) {
    LOG.error("Exception while starting " + getClass().getSimpleName(), thrown);
  }
}
 
Example #11
Source File: ClusterOperator.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
/**
 * Start an HTTP health server
 */
private Future<HttpServer> startHealthServer() {
    Promise<HttpServer> result = Promise.promise();
    this.vertx.createHttpServer()
            .requestHandler(request -> {

                if (request.path().equals("/healthy")) {
                    request.response().setStatusCode(200).end();
                } else if (request.path().equals("/ready")) {
                    request.response().setStatusCode(200).end();
                } else if (request.path().equals("/metrics")) {
                    PrometheusMeterRegistry metrics = (PrometheusMeterRegistry) metricsProvider.meterRegistry();
                    request.response().setStatusCode(200)
                            .end(metrics.scrape());
                }
            })
            .listen(HEALTH_SERVER_PORT, ar -> {
                if (ar.succeeded()) {
                    log.info("ClusterOperator is now ready (health server listening on {})", HEALTH_SERVER_PORT);
                } else {
                    log.error("Unable to bind health server on {}", HEALTH_SERVER_PORT, ar.cause());
                }
                result.handle(ar);
            });
    return result.future();
}
 
Example #12
Source File: ServerBuilderTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test
void monitorBlockingTaskExecutorAndSchedulersTogetherWithPrometheus() {
    final PrometheusMeterRegistry registry = PrometheusMeterRegistries.newRegistry();
    Metrics.addRegistry(registry);
    Server.builder()
          .meterRegistry(registry)
          .service("/", (ctx, req) -> HttpResponse.of(200))
          .build();
    Schedulers.enableMetrics();
    Schedulers.decorateExecutorService(Schedulers.single(), Executors.newSingleThreadScheduledExecutor());
}
 
Example #13
Source File: DeployKonduitOrchestration.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInferenceClustered(InferenceConfiguration inferenceConfiguration, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInferenceClustered(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            new DeploymentOptions().setConfig(new JsonObject(inferenceConfiguration.toJson())), eventHandler);
}
 
Example #14
Source File: TracingConfig.java    From Mastering-Distributed-Tracing with MIT License 5 votes vote down vote up
@Bean
public PrometheusMeterRegistry micrometerRegistry(CollectorRegistry collector) {
    PrometheusMeterRegistry registry = new PrometheusMeterRegistry( //
            PrometheusConfig.DEFAULT, collector, Clock.SYSTEM);
    io.micrometer.core.instrument.Metrics.addRegistry(registry);
    return registry;
}
 
Example #15
Source File: SimpleMetricsPublishingServiceTest.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void stop_removesRegistryFromMetricsSession() {
  subject.start(metricsSession);
  subject.stop(metricsSession);

  verify(metricsSession).removeSubregistry(any(PrometheusMeterRegistry.class));
}
 
Example #16
Source File: MetricsModule.java    From dolphin-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final ServerCoreComponents coreComponents) {
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);

    if(!configuration.getBooleanProperty(METRICS_NOOP_PROPERTY, true)) {

        final PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);

        final List<Tag> tagList = TagUtil.convertTags(ContextManagerImpl.getInstance().getGlobalContexts());

        new ClassLoaderMetrics(tagList).bindTo(prometheusRegistry);
        new JvmMemoryMetrics(tagList).bindTo(prometheusRegistry);
        new JvmGcMetrics(tagList).bindTo(prometheusRegistry);
        new ProcessorMetrics(tagList).bindTo(prometheusRegistry);
        new JvmThreadMetrics(tagList).bindTo(prometheusRegistry);

        servletContext.addFilter(METRICS_SERVLET_FILTER_NAME, new RequestMetricsFilter())
                .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ALL_URL_MAPPING);

        servletContext.addListener(new MetricsHttpSessionListener());

        servletContext.addServlet(METRICS_SERVLET_NAME, new MetricsServlet(prometheusRegistry))
                .addMapping(configuration.getProperty(METRICS_ENDPOINT_PROPERTY));

        MetricsImpl.getInstance().init(prometheusRegistry);
    }
}
 
Example #17
Source File: MetricsReporter.java    From strimzi-kafka-bridge with Apache License 2.0 5 votes vote down vote up
/**
 * Scrape metrics on the provided registries returning them in the Prometheus format
 *
 * @return metrics in Prometheus format as String
 */
public String scrape() {
    StringBuilder sb = new StringBuilder();
    if (jmxCollectorRegistry != null) {
        sb.append(jmxCollectorRegistry.scrape());
    }
    if (meterRegistry instanceof PrometheusMeterRegistry) {
        sb.append(((PrometheusMeterRegistry) meterRegistry).scrape());
    }
    return sb.toString();
}
 
Example #18
Source File: UserOperator.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
public UserOperator(String namespace,
                    UserOperatorConfig config,
                    KubernetesClient client,
                    KafkaUserOperator kafkaUserOperator) {
    log.info("Creating UserOperator for namespace {}", namespace);
    this.namespace = namespace;
    this.reconciliationInterval = config.getReconciliationIntervalMs();
    this.client = client;
    this.kafkaUserOperator = kafkaUserOperator;
    this.metrics = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
}
 
Example #19
Source File: DeployKonduitServing.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInference(DeploymentOptions deploymentOptions, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInference(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            deploymentOptions, eventHandler);
}
 
Example #20
Source File: MetricsTest.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
@Test
void metrics() {
    assertThat(dogma.dogma().meterRegistry()).containsInstanceOf(PrometheusMeterRegistry.class);

    final AggregatedHttpResponse res = dogma.httpClient().get("/monitor/metrics").aggregate().join();
    logger.debug("Prometheus metrics:\n{}", res.contentUtf8());

    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThat(res.contentType()).isEqualTo(MediaType.parse(TextFormat.CONTENT_TYPE_004));
    assertThat(res.contentUtf8()).isNotEmpty();
}
 
Example #21
Source File: CompareHistogramsWithOtherLibraries.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Setup(Level.Iteration)
public void setup() {
    registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, new CollectorRegistry(),
            Clock.SYSTEM);
    summary = DistributionSummary.builder("summary")
            .publishPercentileHistogram()
            .register(registry);
}
 
Example #22
Source File: MonitoringConfiguration.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags(PrometheusConfiguration prometheusConfiguration) {
  return registry -> {
    if (registry instanceof PrometheusMeterRegistry) {
      registry.config().commonTags("application", prometheusConfiguration.getPrefix());
    }
  };
}
 
Example #23
Source File: MetricsModule.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  bind(MetricsServer.class).asEagerSingleton();
  bind(MetricsBinder.class).asEagerSingleton();
  bind(CollectorRegistry.class).toInstance(CollectorRegistry.defaultRegistry);
  bind(PrometheusMeterRegistry.class)
      .toProvider(PrometheusMeterRegistryProvider.class)
      .asEagerSingleton();
  bind(MeterRegistry.class).to(PrometheusMeterRegistry.class);

  Multibinder<MeterBinder> meterMultibinder =
      Multibinder.newSetBinder(binder(), MeterBinder.class);
  meterMultibinder.addBinding().to(ClassLoaderMetrics.class);
  meterMultibinder.addBinding().to(JvmMemoryMetrics.class);
  meterMultibinder.addBinding().to(JvmGcMetrics.class);
  meterMultibinder.addBinding().to(JvmThreadMetrics.class);
  meterMultibinder.addBinding().to(LogbackMetrics.class);
  meterMultibinder.addBinding().to(FileDescriptorMetrics.class);
  meterMultibinder.addBinding().to(ProcessorMetrics.class);
  meterMultibinder.addBinding().to(UptimeMetrics.class);
  meterMultibinder.addBinding().to(FileStoresMeterBinder.class);
  meterMultibinder.addBinding().to(ApiResponseCounter.class);
  meterMultibinder.addBinding().to(ProcessMemoryMetrics.class);
  meterMultibinder.addBinding().to(ProcessThreadMetrics.class);

  bind(EventListener.class).toProvider(OkHttpMetricsEventListenerProvider.class);
}
 
Example #24
Source File: SimpleMetricsPublishingServiceTest.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void stop_removesRegistryFromMetricsSession() {
  subject.start(metricsSession);
  subject.stop(metricsSession);

  verify(metricsSession).removeSubregistry(any(PrometheusMeterRegistry.class));
}
 
Example #25
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * To use pushgateway instead:
 * new PushGateway("localhost:9091").pushAdd(registry.getPrometheusRegistry(), "samples");
 *
 * @return A prometheus registry.
 */
public static PrometheusMeterRegistry prometheus() {
    PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(new PrometheusConfig() {
        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

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

    try {
        HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
        server.createContext("/prometheus", httpExchange -> {
            String response = prometheusRegistry.scrape();
            httpExchange.sendResponseHeaders(200, response.length());
            OutputStream os = httpExchange.getResponseBody();
            os.write(response.getBytes());
            os.close();
        });

        new Thread(server::start).run();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return prometheusRegistry;
}
 
Example #26
Source File: KonduitServingLauncher.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeStartingVertx(VertxOptions options) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    options.setMetricsOptions(micrometerMetricsOptions);
    options.setMaxEventLoopExecuteTime(60);
    options.setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS);
}
 
Example #27
Source File: Session.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
public Session(KubernetesClient kubeClient, Config config) {
    this.kubeClient = kubeClient;
    this.config = config;
    StringBuilder sb = new StringBuilder(System.lineSeparator());
    for (Config.Value<?> v: Config.keys()) {
        sb.append("\t").append(v.key).append(": ").append(Util.maskPassword(v.key, config.get(v).toString())).append(System.lineSeparator());
    }
    LOGGER.info("Using config:{}", sb.toString());
    this.metricsRegistry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
}
 
Example #28
Source File: DropwizardMeterRegistriesTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static MetricFamilySamples findPrometheusSample(PrometheusMeterRegistry registry, String name) {
    for (final Enumeration<MetricFamilySamples> e = registry.getPrometheusRegistry().metricFamilySamples();
         e.hasMoreElements();) {
        final MetricFamilySamples samples = e.nextElement();
        if (name.equals(samples.name)) {
            return samples;
        }
    }

    fail("Could not find a Prometheus sample: " + name);
    throw new Error(); // Never reaches here.
}
 
Example #29
Source File: SimpleMetricsPublishingServiceTest.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void start_addsRegistryToMetricsSession() {
  subject.start(metricsSession);

  verify(metricsSession).addSubregistry(any(PrometheusMeterRegistry.class));

  subject.stop(metricsSession);
}
 
Example #30
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)
                            });
}