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);
}
}
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/*");
}
}
}
Aggregations