Search in sources :

Example 1 with MetricsServiceConfiguration

use of fish.payara.microprofile.metrics.admin.MetricsServiceConfiguration in project Payara by payara.

the class MetricsServiceImpl method init.

@PostConstruct
public void init() {
    metricsServiceConfiguration = serviceLocator.getService(MetricsServiceConfiguration.class);
    // Only start if metrics are enabled
    if (isEnabled()) {
        PayaraExecutorService payaraExecutor = serviceLocator.getService(PayaraExecutorService.class, new Annotation[0]);
        payaraExecutor.submit(this::bootstrap);
    }
}
Also used : MetricsServiceConfiguration(fish.payara.microprofile.metrics.admin.MetricsServiceConfiguration) PayaraExecutorService(fish.payara.nucleus.executorservice.PayaraExecutorService) PostConstruct(javax.annotation.PostConstruct)

Example 2 with MetricsServiceConfiguration

use of fish.payara.microprofile.metrics.admin.MetricsServiceConfiguration in project Payara by payara.

the class MetricsServletContainerInitializer method onStartup.

@Override
public void onStartup(Set<Class<?>> set, ServletContext ctx) throws ServletException {
    MetricsServiceConfiguration configuration = Globals.getDefaultBaseServiceLocator().getService(MetricsServiceConfiguration.class);
    if (!"".equals(ctx.getContextPath())) {
        return;
    }
    // Check if there is already a servlet for metrics
    Map<String, ? extends ServletRegistration> registrations = ctx.getServletRegistrations();
    for (ServletRegistration reg : registrations.values()) {
        if (reg.getClass().equals(MetricsResource.class)) {
            return;
        }
    }
    String virtualServers = configuration.getVirtualServers();
    if (!isEmpty(virtualServers) && !asList(virtualServers.split(",")).contains(ctx.getVirtualServerName())) {
        return;
    }
    // Register a servlet with url patterns of metrics handlers
    ServletRegistration.Dynamic reg = ctx.addServlet("microprofile-metrics-resource", MetricsResource.class);
    reg.addMapping("/" + configuration.getEndpoint() + "/*");
    if (Boolean.parseBoolean(configuration.getSecurityEnabled())) {
        String[] roles = configuration.getRoles().split(",");
        reg.setServletSecurity(new ServletSecurityElement(new HttpConstraintElement(CONFIDENTIAL, roles)));
        ctx.declareRoles(roles);
        if (Boolean.getBoolean(CREATE_INSECURE_ENDPOINT_TEST)) {
            ServletRegistration.Dynamic insecureReg = ctx.addServlet("microprofile-metrics-resource-insecure", MetricsResource.class);
            insecureReg.addMapping("/" + configuration.getEndpoint() + "-insecure/*");
        }
    }
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) MetricsServiceConfiguration(fish.payara.microprofile.metrics.admin.MetricsServiceConfiguration) HttpConstraintElement(javax.servlet.HttpConstraintElement) ServletSecurityElement(javax.servlet.ServletSecurityElement)

Aggregations

MetricsServiceConfiguration (fish.payara.microprofile.metrics.admin.MetricsServiceConfiguration)2 PayaraExecutorService (fish.payara.nucleus.executorservice.PayaraExecutorService)1 PostConstruct (javax.annotation.PostConstruct)1 HttpConstraintElement (javax.servlet.HttpConstraintElement)1 ServletRegistration (javax.servlet.ServletRegistration)1 ServletSecurityElement (javax.servlet.ServletSecurityElement)1