org.eclipse.jetty.server.handler.StatisticsHandler Java Examples
The following examples show how to use
org.eclipse.jetty.server.handler.StatisticsHandler.
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: JettyStatisticsCollectorTest.java From client_java with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { server.addConnector(connector); HandlerCollection handlers = new HandlerCollection(); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); handlers.setHandlers(new Handler[]{context}); StatisticsHandler stats = new StatisticsHandler(); stats.setHandler(handlers); server.setHandler(stats); // register collector new JettyStatisticsCollector(stats).register(); server.setHandler(stats); server.start(); }
Example #2
Source File: ApplicationServer.java From rest-utils with Apache License 2.0 | 6 votes |
private void finalizeHandlerCollection(HandlerCollection handlers, HandlerCollection wsHandlers) { /* DefaultHandler must come last eo ensure all contexts * have a chance to handle a request first */ handlers.addHandler(new DefaultHandler()); /* Needed for graceful shutdown as per `setStopTimeout` documentation */ StatisticsHandler statsHandler = new StatisticsHandler(); statsHandler.setHandler(handlers); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[]{ statsHandler, wsHandlers }); super.setHandler(wrapWithGzipHandler(contexts)); }
Example #3
Source File: JettyHttpServer.java From vespa with Apache License 2.0 | 6 votes |
@Override public void run() { HttpResponseStatisticsCollector statisticsCollector = ((AbstractHandlerContainer) server.getHandler()) .getChildHandlerByClass(HttpResponseStatisticsCollector.class); if (statisticsCollector != null) { setServerMetrics(statisticsCollector); } // reset statisticsHandler to preserve earlier behavior StatisticsHandler statisticsHandler = ((AbstractHandlerContainer) server.getHandler()) .getChildHandlerByClass(StatisticsHandler.class); if (statisticsHandler != null) { statisticsHandler.statsReset(); } for (Connector connector : server.getConnectors()) { setConnectorMetrics((JDiscServerConnector)connector); } }
Example #4
Source File: RegisterExporters.java From Patterdale with Apache License 2.0 | 6 votes |
/** * @param registry Prometheus CollectorRegistry to register the default exporters. * @param httpPort The port the Server runs on. * @return a Jetty Server with Prometheus' default exporters registered. */ public static Server serverWithStatisticsCollection(CollectorRegistry registry, int httpPort) { Server server = new Server(httpPort); new StandardExports().register(registry); new MemoryPoolsExports().register(registry); new GarbageCollectorExports().register(registry); new ThreadExports().register(registry); new ClassLoadingExports().register(registry); new VersionInfoExports().register(registry); HandlerCollection handlers = new HandlerCollection(); StatisticsHandler statisticsHandler = new StatisticsHandler(); statisticsHandler.setServer(server); handlers.addHandler(statisticsHandler); new JettyStatisticsCollector(statisticsHandler).register(registry); server.setHandler(handlers); return server; }
Example #5
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 5 votes |
private void buildStatusCounter(MeterRegistry registry, String status, ToDoubleFunction<StatisticsHandler> consumer) { FunctionCounter.builder("jetty.responses", statisticsHandler, consumer) .tags(tags) .description("Number of requests with response status") .tags("status", status) .register(registry); }
Example #6
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 5 votes |
private void bindStatusCounters(MeterRegistry registry) { buildStatusCounter(registry, "1xx", StatisticsHandler::getResponses1xx); buildStatusCounter(registry, "2xx", StatisticsHandler::getResponses2xx); buildStatusCounter(registry, "3xx", StatisticsHandler::getResponses3xx); buildStatusCounter(registry, "4xx", StatisticsHandler::getResponses4xx); buildStatusCounter(registry, "5xx", StatisticsHandler::getResponses5xx); }
Example #7
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 5 votes |
@Override public void bindTo(MeterRegistry registry) { bindTimer(registry, "jetty.requests", "Request duration", StatisticsHandler::getRequests, StatisticsHandler::getRequestTimeTotal); bindTimer(registry, "jetty.dispatched", "Dispatch duration", StatisticsHandler::getDispatched, StatisticsHandler::getDispatchedTimeTotal); bindCounter(registry, "jetty.async.requests", "Total number of async requests", StatisticsHandler::getAsyncRequests); bindCounter(registry, "jetty.async.dispatches", "Total number of requests that have been asynchronously dispatched", StatisticsHandler::getAsyncDispatches); bindCounter(registry, "jetty.async.expires", "Total number of async requests that have expired", StatisticsHandler::getExpires); FunctionCounter.builder("jetty.responses.size", statisticsHandler, StatisticsHandler::getResponsesBytesTotal) .description("Total number of bytes across all responses") .baseUnit(BaseUnits.BYTES) .tags(tags) .register(registry); bindGauge(registry, "jetty.requests.active", "Number of requests currently active", StatisticsHandler::getRequestsActive); bindGauge(registry, "jetty.dispatched.active", "Number of dispatches currently active", StatisticsHandler::getDispatchedActive); bindGauge(registry, "jetty.dispatched.active.max", "Maximum number of active dispatches being handled", StatisticsHandler::getDispatchedActiveMax); bindTimeGauge(registry, "jetty.dispatched.time.max", "Maximum time spent in dispatch handling", StatisticsHandler::getDispatchedTimeMax); bindGauge(registry, "jetty.async.requests.waiting", "Currently waiting async requests", StatisticsHandler::getAsyncRequestsWaiting); bindGauge(registry, "jetty.async.requests.waiting.max", "Maximum number of waiting async requests", StatisticsHandler::getAsyncRequestsWaitingMax); bindTimeGauge(registry, "jetty.request.time.max", "Maximum time spent handling requests", StatisticsHandler::getRequestTimeMax); bindTimeGauge(registry, "jetty.stats", "Time stats have been collected for", StatisticsHandler::getStatsOnMs); bindStatusCounters(registry); }
Example #8
Source File: JettyHttpServer.java From vespa with Apache License 2.0 | 4 votes |
private HandlerCollection getHandlerCollection( ServerConfig serverConfig, ServletPathsConfig servletPathsConfig, List<JDiscServerConnector> connectors, ServletHolder jdiscServlet, ComponentRegistry<ServletHolder> servletHolders, FilterHolder jDiscFilterInvokerFilter) { ServletContextHandler servletContextHandler = createServletContextHandler(); servletHolders.allComponentsById().forEach((id, servlet) -> { String path = getServletPath(servletPathsConfig, id); servletContextHandler.addServlet(servlet, path); servletContextHandler.addFilter(jDiscFilterInvokerFilter, path, EnumSet.allOf(DispatcherType.class)); }); servletContextHandler.addServlet(jdiscServlet, "/*"); List<ConnectorConfig> connectorConfigs = connectors.stream().map(JDiscServerConnector::connectorConfig).collect(toList()); var secureRedirectHandler = new SecuredRedirectHandler(connectorConfigs); secureRedirectHandler.setHandler(servletContextHandler); var proxyHandler = new HealthCheckProxyHandler(connectors); proxyHandler.setHandler(secureRedirectHandler); var authEnforcer = new TlsClientAuthenticationEnforcer(connectorConfigs); authEnforcer.setHandler(proxyHandler); GzipHandler gzipHandler = newGzipHandler(serverConfig); gzipHandler.setHandler(authEnforcer); HttpResponseStatisticsCollector statisticsCollector = new HttpResponseStatisticsCollector(serverConfig.metric().monitoringHandlerPaths()); statisticsCollector.setHandler(gzipHandler); StatisticsHandler statisticsHandler = newStatisticsHandler(); statisticsHandler.setHandler(statisticsCollector); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.setHandlers(new Handler[] { statisticsHandler }); return handlerCollection; }
Example #9
Source File: RestServer.java From DataLink with Apache License 2.0 | 4 votes |
public void start() { log.info("Starting REST server"); ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.register(DataxResource.class); ServletContainer servletContainer = new ServletContainer(resourceConfig); ServletHolder servletHolder = new ServletHolder(servletContainer); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); String allowedOrigins = System.getProperty(ACCESS_CONTROL_ALLOW_ORIGIN_CONFIG); if (allowedOrigins != null && !allowedOrigins.trim().isEmpty()) { FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter()); filterHolder.setName("cross-origin"); filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, allowedOrigins); String allowedMethods = System.getProperty(ACCESS_CONTROL_ALLOW_METHODS_CONFIG); if (allowedMethods != null && !allowedOrigins.trim().isEmpty()) { filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, allowedMethods); } context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); } RequestLogHandler requestLogHandler = new RequestLogHandler(); Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setLoggerName(RestServer.class.getCanonicalName()); requestLog.setLogLatency(true); requestLogHandler.setRequestLog(requestLog); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[]{context, new DefaultHandler(), requestLogHandler}); /* Needed for graceful shutdown as per `setStopTimeout` documentation */ StatisticsHandler statsHandler = new StatisticsHandler(); statsHandler.setHandler(handlers); jettyServer.setHandler(statsHandler); jettyServer.setStopTimeout(GRACEFUL_SHUTDOWN_TIMEOUT_MS); jettyServer.setStopAtShutdown(true); try { jettyServer.start(); } catch (Exception e) { throw new RuntimeException("Unable to start REST server", e); } log.info("REST server listening at " + jettyServer.getURI() + ", advertising URL " + advertisedUrl()); }
Example #10
Source File: JettyStatisticsCollector.java From client_java with Apache License 2.0 | 4 votes |
public JettyStatisticsCollector(StatisticsHandler statisticsHandler) { this.statisticsHandler = statisticsHandler; }
Example #11
Source File: JettyHttpTransport.java From cougar with Apache License 2.0 | 4 votes |
public void initialiseStaticJettyConfig() throws Exception { server.initialiseConnectors(); ErrorHandler errorHandler = new CougarErrorHandler(); wsdlStaticHandler = new StaticContentServiceHandler( wsdlContextPath, wsdlRegex, wsdlMediaType, uuidHeader, uuidParentsHeader, deserializer, geoIPLocator, requestLogger, true); wsdlStaticHandler.setUnknownCipherKeyLength(unknownCipherKeyLength); htmlStaticHandler = new StaticContentServiceHandler( htmlContextPath, htmlRegex, htmlMediaType, uuidHeader, uuidParentsHeader, deserializer, geoIPLocator, requestLogger, suppressCommasInAccessLogForStaticHtml); htmlStaticHandler.setUnknownCipherKeyLength(unknownCipherKeyLength); StatisticsHandler statisticsHandler = new StatisticsHandler(); statisticsHandler.setServer(server.getJettyServer()); handlerCollection.setServer(server.getJettyServer()); JettyHandler defaultJettyServiceHandler = new AliasHandler(defaultCommandProcessor, suppressCommasInAccessLogForCalls, pathAliases); ContextHandler context = new ContextHandler(); context.setContextPath(""); context.setResourceBase("."); context.setHandler(defaultJettyServiceHandler); handlerCollection.addHandler(context); handlerCollection.addHandler(wsdlStaticHandler); handlerCollection.addHandler(htmlStaticHandler); // handlerCollection.addHandler(aliasHandler); statisticsHandler.setHandler(handlerCollection); // Register the errorhandler with the server itself server.addBean(errorHandler); server.setHandler(statisticsHandler); }
Example #12
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 4 votes |
public JettyStatisticsMetrics(StatisticsHandler statisticsHandler, Iterable<Tag> tags) { this.tags = tags; this.statisticsHandler = statisticsHandler; }
Example #13
Source File: JettyServerFactory.java From gravitee-management-rest-api with Apache License 2.0 | 4 votes |
@Override public Server getObject() throws Exception { // Setup ThreadPool QueuedThreadPool threadPool = new QueuedThreadPool( jettyConfiguration.getPoolMaxThreads(), jettyConfiguration.getPoolMinThreads(), jettyConfiguration.getPoolIdleTimeout(), new ArrayBlockingQueue<Runnable>(jettyConfiguration.getPoolQueueSize()) ); threadPool.setName("gravitee-listener"); Server server = new Server(threadPool); // Extra options server.setDumpAfterStart(false); server.setDumpBeforeStop(false); server.setStopAtShutdown(true); // Setup JMX if (jettyConfiguration.isJmxEnabled()) { MBeanContainer mbContainer = new MBeanContainer( ManagementFactory.getPlatformMBeanServer()); server.addBean(mbContainer); } // HTTP Configuration HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setOutputBufferSize(32768); httpConfig.setRequestHeaderSize(8192); httpConfig.setResponseHeaderSize(8192); httpConfig.setSendServerVersion(false); httpConfig.setSendDateHeader(false); // Setup Jetty HTTP or HTTPS Connector if (jettyConfiguration.isSecured()) { httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(jettyConfiguration.getHttpPort()); // SSL Context Factory SslContextFactory sslContextFactory = new SslContextFactory.Server(); if (jettyConfiguration.getKeyStorePath() != null) { sslContextFactory.setKeyStorePath(jettyConfiguration.getKeyStorePath()); sslContextFactory.setKeyStorePassword(jettyConfiguration.getKeyStorePassword()); if (KEYSTORE_TYPE_PKCS12.equalsIgnoreCase(jettyConfiguration.getKeyStoreType())) { sslContextFactory.setKeyStoreType(KEYSTORE_TYPE_PKCS12); } } if (jettyConfiguration.getTrustStorePath() != null) { sslContextFactory.setTrustStorePath(jettyConfiguration.getTrustStorePath()); sslContextFactory.setTrustStorePassword(jettyConfiguration.getTrustStorePassword()); if (KEYSTORE_TYPE_PKCS12.equalsIgnoreCase(jettyConfiguration.getTrustStoreType())) { sslContextFactory.setTrustStoreType(KEYSTORE_TYPE_PKCS12); } } HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig)); https.setHost(jettyConfiguration.getHttpHost()); https.setPort(jettyConfiguration.getHttpPort()); server.addConnector(https); } else { ServerConnector http = new ServerConnector(server, jettyConfiguration.getAcceptors(), jettyConfiguration.getSelectors(), new HttpConnectionFactory(httpConfig)); http.setHost(jettyConfiguration.getHttpHost()); http.setPort(jettyConfiguration.getHttpPort()); http.setIdleTimeout(jettyConfiguration.getIdleTimeout()); server.addConnector(http); } // Setup Jetty statistics if (jettyConfiguration.isStatisticsEnabled()) { StatisticsHandler stats = new StatisticsHandler(); stats.setHandler(server.getHandler()); server.setHandler(stats); } if (jettyConfiguration.isAccessLogEnabled()) { CustomRequestLog requestLog = new CustomRequestLog( new AsyncRequestLogWriter(jettyConfiguration.getAccessLogPath()), CustomRequestLog.EXTENDED_NCSA_FORMAT); server.setRequestLog(requestLog); } return server; }
Example #14
Source File: JettyHttpServer.java From vespa with Apache License 2.0 | 4 votes |
private StatisticsHandler newStatisticsHandler() { StatisticsHandler statisticsHandler = new StatisticsHandler(); statisticsHandler.statsReset(); return statisticsHandler; }
Example #15
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 4 votes |
public static void monitor(MeterRegistry meterRegistry, StatisticsHandler statisticsHandler, String... tags) { monitor(meterRegistry, statisticsHandler, Tags.of(tags)); }
Example #16
Source File: JettyHttpServer.java From vespa with Apache License 2.0 | 4 votes |
private boolean isGracefulShutdownEnabled() { return server.getChildHandlersByClass(StatisticsHandler.class).length > 0 && server.getStopTimeout() > 0; }
Example #17
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 4 votes |
public static void monitor(MeterRegistry meterRegistry, StatisticsHandler statisticsHandler, Iterable<Tag> tags) { new JettyStatisticsMetrics(statisticsHandler, tags).bindTo(meterRegistry); }
Example #18
Source File: JettyStatisticsCollector.java From Patterdale with Apache License 2.0 | 4 votes |
public JettyStatisticsCollector(StatisticsHandler statisticsHandler) { this.statisticsHandler = statisticsHandler; }
Example #19
Source File: RestServer.java From DataLink with Apache License 2.0 | 4 votes |
public void start(Keeper keeper) { log.info("Starting REST server"); ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.packages("com.ucar.datalink.worker.core.runtime.rest.resources"); resourceConfig.register(new FastJsonProvider()); resourceConfig.register(RootResource.class); resourceConfig.register(new TasksResource(keeper)); resourceConfig.register(RestExceptionMapper.class); resourceConfig.register(FlushResource.class); resourceConfig.register(HBaseMetaResource.class); resourceConfig.register(WorkerResource.class); ServletContainer servletContainer = new ServletContainer(resourceConfig); ServletHolder servletHolder = new ServletHolder(servletContainer); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); String allowedOrigins = config.getString(WorkerConfig.ACCESS_CONTROL_ALLOW_ORIGIN_CONFIG); if (allowedOrigins != null && !allowedOrigins.trim().isEmpty()) { FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter()); filterHolder.setName("cross-origin"); filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, allowedOrigins); String allowedMethods = config.getString(WorkerConfig.ACCESS_CONTROL_ALLOW_METHODS_CONFIG); if (allowedMethods != null && !allowedOrigins.trim().isEmpty()) { filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, allowedMethods); } context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); } RequestLogHandler requestLogHandler = new RequestLogHandler(); Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setLoggerName(RestServer.class.getCanonicalName()); requestLog.setLogLatency(true); requestLogHandler.setRequestLog(requestLog); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[]{context, new DefaultHandler(), requestLogHandler}); /* Needed for graceful shutdown as per `setStopTimeout` documentation */ StatisticsHandler statsHandler = new StatisticsHandler(); statsHandler.setHandler(handlers); jettyServer.setHandler(statsHandler); jettyServer.setStopTimeout(GRACEFUL_SHUTDOWN_TIMEOUT_MS); jettyServer.setStopAtShutdown(true); try { jettyServer.start(); } catch (Exception e) { throw new DatalinkException("Unable to start REST server", e); } log.info("REST server listening at " + jettyServer.getURI() + ", advertising URL " + advertisedUrl()); }
Example #20
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 4 votes |
private void bindCounter(MeterRegistry registry, String name, String desc, ToDoubleFunction<StatisticsHandler> consumer) { FunctionCounter.builder(name, statisticsHandler, consumer) .tags(tags) .description(desc) .register(registry); }
Example #21
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 4 votes |
private void bindTimeGauge(MeterRegistry registry, String name, String desc, ToDoubleFunction<StatisticsHandler> consumer) { TimeGauge.builder(name, statisticsHandler, TimeUnit.MILLISECONDS, consumer) .tags(tags) .description(desc) .register(registry); }
Example #22
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 4 votes |
private void bindTimer(MeterRegistry registry, String name, String desc, ToLongFunction<StatisticsHandler> countFunc, ToDoubleFunction<StatisticsHandler> consumer) { FunctionTimer.builder(name, statisticsHandler, countFunc, consumer, TimeUnit.MILLISECONDS) .tags(tags) .description(desc) .register(registry); }
Example #23
Source File: JettyStatisticsMetrics.java From micrometer with Apache License 2.0 | 4 votes |
private void bindGauge(MeterRegistry registry, String name, String description, ToDoubleFunction<StatisticsHandler> valueFunction) { Gauge.builder(name, statisticsHandler, valueFunction) .tags(tags) .description(description) .register(registry); }