Java Code Examples for com.linecorp.armeria.server.ServerBuilder#meterRegistry()

The following examples show how to use com.linecorp.armeria.server.ServerBuilder#meterRegistry() . 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: PrometheusMetricsIntegrationTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.meterRegistry(registry);

    final THttpService helloService = THttpService.of((Iface) name -> {
        if ("world".equals(name)) {
            return "success";
        }
        throw new IllegalArgumentException("bad argument");
    });

    sb.service("/foo", helloService.decorate(
            MetricCollectingService.newDecorator(new MeterIdPrefixFunctionImpl("server", "Foo"))));

    sb.service("/bar", helloService.decorate(
            MetricCollectingService.newDecorator(new MeterIdPrefixFunctionImpl("server", "Bar"))));

    sb.service("/internal/prometheus/metrics",
               new PrometheusExpositionService(prometheusRegistry));
}
 
Example 3
Source File: ArmeriaServerFactory.java    From armeria with Apache License 2.0 5 votes vote down vote up
private ServerBuilder buildServerBuilder(Server server, MetricRegistry metricRegistry) {
    final ServerBuilder serverBuilder = com.linecorp.armeria.server.Server.builder();
    serverBuilder.meterRegistry(DropwizardMeterRegistries.newRegistry(metricRegistry));

    if (armeriaSettings != null) {
        ArmeriaConfigurationUtil.configureServer(serverBuilder, armeriaSettings);
    } else {
        logger.warn("Armeria configuration was null. ServerBuilder is not customized from it.");
    }

    return serverBuilder.blockingTaskExecutor(newBlockingTaskExecutor(), true)
                        .serviceUnder("/", JettyService.of(server));
}
 
Example 4
Source File: GrpcMetricsIntegrationTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.meterRegistry(registry);
    sb.service(GrpcService.builder()
                          .addService(new TestServiceImpl())
                          .enableUnframedRequests(true)
                          .build(),
               MetricCollectingService.newDecorator(MeterIdPrefixFunction.ofDefault("server")),
               LoggingService.newDecorator());
}
 
Example 5
Source File: DropwizardMetricsIntegrationTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.meterRegistry(registry);
    sb.service("/helloservice", THttpService.of((Iface) name -> {
        if ("world".equals(name)) {
            return "success";
        }
        throw new IllegalArgumentException("bad argument");
    }).decorate(MetricCollectingService.newDecorator(
            MeterIdPrefixFunction.ofDefault("armeria.server.hello.service"))));
}
 
Example 6
Source File: CompositeServiceTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.meterRegistry(PrometheusMeterRegistries.newRegistry());
    sb.serviceUnder("/qux/", composite);

    // Should not hit the following services
    sb.serviceUnder("/foo/", otherService);
    sb.serviceUnder("/bar/", otherService);
    sb.service(Route.builder().glob("/*").build(), otherService);
}
 
Example 7
Source File: ArmeriaConfigurationUtil.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Sets graceful shutdown timeout, health check services and {@link MeterRegistry} for the specified
 * {@link ServerBuilder}.
 */
public static void configureServerWithArmeriaSettings(ServerBuilder server, ArmeriaSettings settings,
                                                      MeterRegistry meterRegistry,
                                                      List<HealthChecker> healthCheckers) {
    requireNonNull(server, "server");
    requireNonNull(settings, "settings");
    requireNonNull(meterRegistry, "meterRegistry");
    requireNonNull(healthCheckers, "healthCheckers");

    if (settings.getGracefulShutdownQuietPeriodMillis() >= 0 &&
        settings.getGracefulShutdownTimeoutMillis() >= 0) {
        server.gracefulShutdownTimeoutMillis(settings.getGracefulShutdownQuietPeriodMillis(),
                                             settings.getGracefulShutdownTimeoutMillis());
        logger.debug("Set graceful shutdown timeout: quiet period {} ms, timeout {} ms",
                     settings.getGracefulShutdownQuietPeriodMillis(),
                     settings.getGracefulShutdownTimeoutMillis());
    }

    final String healthCheckPath = settings.getHealthCheckPath();
    if (!Strings.isNullOrEmpty(healthCheckPath)) {
        server.service(healthCheckPath, HealthCheckService.of(healthCheckers));
    }

    server.meterRegistry(meterRegistry);

    if (settings.isEnableMetrics() && !Strings.isNullOrEmpty(settings.getMetricsPath())) {
        final boolean hasPrometheus = hasAllClasses(
                "io.micrometer.prometheus.PrometheusMeterRegistry",
                "io.prometheus.client.CollectorRegistry");

        final boolean addedPrometheusExposition;
        if (hasPrometheus) {
            addedPrometheusExposition = PrometheusSupport.addExposition(settings, server, meterRegistry);
        } else {
            addedPrometheusExposition = false;
        }

        if (!addedPrometheusExposition) {
            final boolean hasDropwizard = hasAllClasses(
                    "io.micrometer.core.instrument.dropwizard.DropwizardMeterRegistry",
                    "com.codahale.metrics.MetricRegistry",
                    "com.codahale.metrics.json.MetricsModule");
            if (hasDropwizard) {
                DropwizardSupport.addExposition(settings, server, meterRegistry);
            }
        }
    }

    if (settings.getSsl() != null) {
        configureTls(server, settings.getSsl());
    }

    final ArmeriaSettings.Compression compression = settings.getCompression();
    if (compression != null && compression.isEnabled()) {
        final int minBytesToForceChunkedAndEncoding =
                Ints.saturatedCast(parseDataSize(compression.getMinResponseSize()));
        server.decorator(contentEncodingDecorator(compression.getMimeTypes(),
                                                  compression.getExcludedUserAgents(),
                                                  minBytesToForceChunkedAndEncoding));
    }
}