本文整理汇总了Java中com.codahale.metrics.servlets.AdminServlet类的典型用法代码示例。如果您正苦于以下问题:Java AdminServlet类的具体用法?Java AdminServlet怎么用?Java AdminServlet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AdminServlet类属于com.codahale.metrics.servlets包,在下文中一共展示了AdminServlet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMetricsHandler
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
private ServletContextHandler getMetricsHandler() {
MetricRegistry registry = Metrics.getRegistry();
HealthCheckRegistry healthCheckRegistry = Metrics.getHealthCheckRegistry();
healthCheckRegistry.register("rotation", new Rotation(configuration.getRotationStatusFilePath()));
registry.registerAll(new GarbageCollectorMetricSet());
registry.registerAll(new MemoryUsageGaugeSet());
registry.registerAll(new ThreadStatesGaugeSet());
registry.registerAll(new JvmAttributeGaugeSet());
ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.setContextPath("/__metrics");
servletContextHandler.setAttribute(MetricsServlet.class.getCanonicalName() + ".registry", registry);
servletContextHandler.setAttribute(HealthCheckServlet.class.getCanonicalName() + ".registry", healthCheckRegistry);
servletContextHandler.addServlet(new ServletHolder(new AdminServlet()), "/*");
return servletContextHandler;
}
示例2: contextInitialized
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
ServletRegistration.Dynamic
servlet =
context.addServlet("VmInspectionServlet", VmInspectionServlet.class);
servlet.addMapping("/gondola/inspect");
servlet.setLoadOnStartup(1);
ServletRegistration.Dynamic
servlet2 =
context.addServlet("MetricsServlet", AdminServlet.class);
servlet2.addMapping("/gondola/metrics/*");
servlet2.setLoadOnStartup(0);
ServletRegistration.Dynamic servlet3 =
context.addServlet("static", DefaultWrapperServlet.class);
servlet3.setInitParameter("cacheControl", "max-age=0,no-cache");
servlet3.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
servlet3.setInitParameter("welcomeServlets", "false");
servlet3.addMapping("/static/*");
}
示例3: start
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
public void start() throws Exception {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
jettyServer.setHandler(context);
context.addEventListener(new HealthCheckServletContextListener(healthCheckRegistry));
context.addEventListener(new MetricsServletContextListener(metricRegistry));
context.addServlet(new ServletHolder(new AdminServlet()), "/*");
jettyServer.start();
}
示例4: LensServer
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
/**
* Instantiates a new lens server.
*
* @param conf the conf
* @throws IOException Signals that an I/O exception has occurred.
*/
private LensServer(HiveConf conf) throws IOException {
startServices(conf);
String baseURI = conf.get(LensConfConstants.SERVER_BASE_URL, LensConfConstants.DEFAULT_SERVER_BASE_URL);
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(UriBuilder.fromUri(baseURI).build(), getApp(),
false);
int corePoolSize = conf.getInt(LensConfConstants.GRIZZLY_CORE_POOL_SIZE,
LensConfConstants.DEFAULT_GRIZZLY_CORE_POOL_SIZE);
int maxPoolSize = conf.getInt(LensConfConstants.GRIZZLY_MAX_POOL_SIZE,
LensConfConstants.DEFAULT_GRIZZLY_MAX_POOL_SIZE);
ThreadPoolConfig config = ThreadPoolConfig.defaultConfig();
config.setPoolName("lensserver-pool");
config.setCorePoolSize(corePoolSize);
config.setMaxPoolSize(maxPoolSize);
config.setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d")
.setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());
NetworkListener listener = server.getListeners().iterator().next();
listener.getTransport().setWorkerThreadPoolConfig(config);
serverList.add(server);
WebappContext adminCtx = new WebappContext("admin", "");
MetricsServiceImpl metricsService = LensServices.get().getService(MetricsService.NAME);
adminCtx
.setAttribute("com.codahale.metrics.servlets.MetricsServlet.registry", (metricsService.getMetricRegistry()));
adminCtx.setAttribute("com.codahale.metrics.servlets.HealthCheckServlet.registry", metricsService.getHealthCheck());
final ServletRegistration sgMetrics = adminCtx.addServlet("admin", new AdminServlet());
sgMetrics.addMapping("/admin/*");
adminCtx.deploy(server);
}
示例5: buildDeploymentInfo
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
private DeploymentInfo buildDeploymentInfo(JbootServerClassloader classloader) {
DeploymentInfo deploymentInfo = Servlets.deployment()
.setClassLoader(classloader)
.setResourceManager(new ClassPathResourceManager(classloader))
.setContextPath(config.getContextPath())
.setDeploymentName("jboot" + StringUtils.uuid())
.setEagerFilterInit(true); //设置启动的时候,初始化servlet或filter
JbootShiroConfig shiroConfig = Jboot.config(JbootShiroConfig.class);
if (shiroConfig.isConfigOK()) {
deploymentInfo.addListeners(Servlets.listener(EnvironmentLoaderListener.class));
deploymentInfo.addFilter(
Servlets.filter("shiro", ShiroFilter.class))
.addFilterUrlMapping("shiro", "/*", DispatcherType.REQUEST);
}
deploymentInfo.addFilter(
Servlets.filter("jfinal", JFinalFilter.class)
.addInitParam("configClass", Jboot.me().getJbootConfig().getJfinalConfig()))
.addFilterUrlMapping("jfinal", "/*", DispatcherType.REQUEST);
JbootHystrixConfig hystrixConfig = Jboot.config(JbootHystrixConfig.class);
if (StringUtils.isNotBlank(hystrixConfig.getUrl())) {
deploymentInfo.addServlets(
Servlets.servlet("HystrixMetricsStreamServlet", HystrixMetricsStreamServlet.class)
.addMapping(hystrixConfig.getUrl()));
}
JbootMetricConfig metricsConfig = Jboot.config(JbootMetricConfig.class);
if (StringUtils.isNotBlank(metricsConfig.getUrl())) {
deploymentInfo.addServlets(
Servlets.servlet("MetricsAdminServlet", AdminServlet.class)
.addMapping(metricsConfig.getUrl()));
deploymentInfo.addListeners(Servlets.listener(JbootMetricServletContextListener.class));
deploymentInfo.addListeners(Servlets.listener(JbootHealthCheckServletContextListener.class));
}
io.jboot.server.Servlets jbootServlets = new io.jboot.server.Servlets();
ContextListeners listeners = new ContextListeners();
JbootAppListenerManager.me().onJbootDeploy(jbootServlets, listeners);
for (Map.Entry<String, io.jboot.server.Servlets.ServletInfo> entry : jbootServlets.getServlets().entrySet()) {
ServletInfo servletInfo = Servlets.servlet(entry.getKey(), entry.getValue().getServletClass()).addMappings(entry.getValue().getUrlMapping());
deploymentInfo.addServlet(servletInfo);
}
for (Class<? extends ServletContextListener> listenerClass : listeners.getListeners()) {
deploymentInfo.addListeners(Servlets.listener(listenerClass));
}
deploymentInfo.addServlets(
Servlets.servlet("JbootResourceServlet", JbootResourceServlet.class)
.addMapping("/*"));
return deploymentInfo;
}
示例6: initJettyServer
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
private void initJettyServer() {
InetSocketAddress address = new InetSocketAddress(config.getHost(), config.getPort());
jettyServer = new Server(address);
handler = new ServletContextHandler();
handler.setContextPath(config.getContextPath());
handler.setClassLoader(new JbootServerClassloader(JettyServer.class.getClassLoader()));
handler.setResourceBase(getRootClassPath());
JbootShiroConfig shiroConfig = Jboot.config(JbootShiroConfig.class);
if (shiroConfig.isConfigOK()) {
handler.addEventListener(new EnvironmentLoaderListener());
handler.addFilter(ShiroFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
}
//JFinal
FilterHolder jfinalFilter = handler.addFilter(JFinalFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
jfinalFilter.setInitParameter("configClass", Jboot.me().getJbootConfig().getJfinalConfig());
JbootHystrixConfig hystrixConfig = Jboot.config(JbootHystrixConfig.class);
if (StringUtils.isNotBlank(hystrixConfig.getUrl())) {
handler.addServlet(HystrixMetricsStreamServlet.class, hystrixConfig.getUrl());
}
JbootMetricConfig metricsConfig = Jboot.config(JbootMetricConfig.class);
if (StringUtils.isNotBlank(metricsConfig.getUrl())) {
handler.addEventListener(new JbootMetricServletContextListener());
handler.addEventListener(new JbootHealthCheckServletContextListener());
handler.addServlet(AdminServlet.class, metricsConfig.getUrl());
}
io.jboot.server.Servlets jbootServlets = new io.jboot.server.Servlets();
ContextListeners listeners = new ContextListeners();
JbootAppListenerManager.me().onJbootDeploy(jbootServlets, listeners);
for (Map.Entry<String, io.jboot.server.Servlets.ServletInfo> entry : jbootServlets.getServlets().entrySet()) {
for (String path : entry.getValue().getUrlMapping()) {
handler.addServlet(entry.getValue().getServletClass(), path);
}
}
for (Class<? extends ServletContextListener> listenerClass : listeners.getListeners()) {
handler.addEventListener(ClassKits.newInstance(listenerClass));
}
jettyServer.setHandler(handler);
}
示例7: registerMetricsServlets
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
private void registerMetricsServlets(final ServletContextHandler context) {
context.addEventListener(new ExampleHealthCheckServletContextListener());
context.addEventListener(new ExampleMetricsServletContextListener());
context.addServlet(AdminServlet.class, "/admin");
context.addServlet(HealthCheckServlet.class, "/admin/healthcheck");
context.addServlet(MetricsServlet.class, "/admin/metrics");
context.addServlet(PingServlet.class, "/admin/ping");
context.addServlet(ThreadDumpServlet.class, "/admin/threads");
}
示例8: main
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
/**
* Run the Wikipedia application.
*
* @param args command line arguments
* @throws Exception if the server fails to start or crashes
*/
public static void main(String[] args) throws Exception {
int port = 9998;
Server server = new Server(port);
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
servletContextHandler.addEventListener(new MetricServletContextListener());
servletContextHandler.addEventListener(new HealthCheckServletContextListener());
servletContextHandler.setContextPath("/");
servletContextHandler.setResourceBase("src/main/webapp");
//Activate codahale metrics
FilterHolder instrumentedFilterHolder = new FilterHolder(InstrumentedFilter.class);
instrumentedFilterHolder.setName("instrumentedFilter");
instrumentedFilterHolder.setAsyncSupported(true);
servletContextHandler.addFilter(instrumentedFilterHolder, "/*", EnumSet.noneOf(DispatcherType.class));
// Static resource handler
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setResourceBase("src/main/webapp");
// Add the handlers to the server
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resourceHandler, servletContextHandler });
server.setHandler(handlers);
ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/v1/*");
servletHolder.setInitOrder(1);
servletHolder.setInitParameter(
"javax.ws.rs.Application",
"com.yahoo.bard.webservice.application.ResourceConfig");
servletHolder.setInitParameter(
"jersey.config.server.provider.packages",
"com.yahoo.bard.webservice.web.endpoints");
servletContextHandler.addServlet(AdminServlet.class, "/*");
server.start();
markDimensionCacheHealthy(port);
}
示例9: main
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
/**
* Run a generic setup which mirrors all information from druid into fili configuration.
*
* @param args Command line arguments.
*
* @throws Exception if the server fails to start or crashes.
*/
public static void main(String[] args) throws Exception {
int port = SYSTEM_CONFIG.getIntProperty(FILI_PORT);
Server server = new Server(port);
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
servletContextHandler.addEventListener(new MetricServletContextListener());
servletContextHandler.addEventListener(new HealthCheckServletContextListener());
servletContextHandler.setContextPath("/");
servletContextHandler.setResourceBase("src/main/webapp");
//Activate codahale metrics
FilterHolder instrumentedFilterHolder = new FilterHolder(InstrumentedFilter.class);
instrumentedFilterHolder.setName("instrumentedFilter");
instrumentedFilterHolder.setAsyncSupported(true);
servletContextHandler.addFilter(instrumentedFilterHolder, "/*", EnumSet.noneOf(DispatcherType.class));
// Static resource handler
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setResourceBase("src/main/webapp");
// Add the handlers to the server
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] {resourceHandler, servletContextHandler});
server.setHandler(handlers);
ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/v1/*");
servletHolder.setInitOrder(1);
servletHolder.setInitParameter(
"javax.ws.rs.Application",
"com.yahoo.bard.webservice.application.ResourceConfig"
);
servletHolder.setInitParameter(
"jersey.config.server.provider.packages",
"com.yahoo.bard.webservice.web.endpoints"
);
servletContextHandler.addServlet(AdminServlet.class, "/*");
server.start();
}
示例10: adminServer
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
@Bean(initMethod="start", destroyMethod="stop")
@Order(0)
public Server adminServer(
@Value("${admin.hostname}") String hostname,
@Value("${admin.port}") int port) {
// set up servlets
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
context.setErrorHandler(null);
context.setWelcomeFiles(new String[] { "/" });
// enable gzip
context.addFilter(GzipFilter.class, "/*", null);
// add common admin servlets
context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck");
context.addServlet(new ServletHolder(new ClasspathResourceServlet("com/kixeye/chassis/transport/admin", "/admin/", "index.html")), "/admin/*");
context.addServlet(new ServletHolder(new PropertiesServlet()), "/admin/properties");
context.addServlet(new ServletHolder(new ClasspathDumpServlet()), "/admin/classpath");
// add websocket servlets if WebSockets have been initialized
if (mappingRegistry != null && messageRegistry != null) {
context.addServlet(new ServletHolder(new ProtobufMessagesDocumentationServlet(appName, mappingRegistry, messageRegistry)), "/schema/messages/protobuf");
context.addServlet(new ServletHolder(new ProtobufEnvelopeDocumentationServlet()), "/schema/envelope/protobuf");
}
// add metric servlets if Metric has been initialized
if (metricRegistry != null && healthCheckRegistry != null) {
context.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
context.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry);
ServletHolder holder = new ServletHolder(new AdminServlet());
holder.setInitParameter("service-name", System.getProperty("app.name"));
context.addServlet(holder, "/metrics/*");
}
// create the server
InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);
Server server = new Server();
JettyConnectorRegistry.registerHttpConnector(server, address);
server.setHandler(context);
return server;
}
示例11: metricsServlet
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
@Produces
public ServletDescriptor metricsServlet() {
String[] uris = new String[]{metricsConfig.getBaseUri()};
WebInitParam[] params = null;
return new ServletDescriptor("Metrics", uris, uris, 1, params, false, AdminServlet.class);
}
示例12: metricServer
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
@Provides
@Singleton
private Server metricServer(final MetricRegistry metricRegistry) throws Exception {
metricRegistry.registerAll(new GarbageCollectorMetricSet());
metricRegistry.registerAll(new MemoryUsageGaugeSet());
metricRegistry.registerAll(new ThreadStatesGaugeSet());
final HealthCheckRegistry notUsed = new HealthCheckRegistry();
AdminServletContextListener ascl = new AdminServletContextListener() {
@Override
protected MetricRegistry getMetricRegistry() {
return metricRegistry;
}
@Override
protected HealthCheckRegistry getHealthCheckRegistry() {
return notUsed;
}
};
final Server server = new Server(7070);
ServletContextHandler context = new ServletContextHandler();
context.addEventListener(ascl);
context.setContextPath("/");
context.setInitParameter(MetricsServlet.DURATION_UNIT, TimeUnit.MILLISECONDS.toString());
context.setInitParameter(MetricsServlet.RATE_UNIT, TimeUnit.SECONDS.toString());
server.setHandler(context);
ServletHolder holder = new ServletHolder(new AdminServlet());
context.addServlet(holder, "/*");
server.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
server.stop();
} catch (Exception e) {
throw new AssertionError(e);
}
}
});
return server;
}
示例13: StartReportingMetricsToHTTP
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
public StartReportingMetricsToHTTP(CommandBuilder builder, Config config, Command parent,
Command child, final MorphlineContext context) {
super(builder, config, parent, child, context);
this.port = getConfigs().getInt(config, "port", 8080);
final TimeUnit defaultDurationUnit = getConfigs().getTimeUnit(config, "defaultDurationUnit", TimeUnit.MILLISECONDS);
final TimeUnit defaultRateUnit = getConfigs().getTimeUnit(config, "defaultRateUnit", TimeUnit.SECONDS);
validateArguments();
synchronized (SERVERS) {
Server server = SERVERS.get(port);
if (server == null) {
ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.addServlet(AdminServlet.class, "/*");
servletContextHandler.addEventListener(new MetricsServlet.ContextListener() {
@Override
protected MetricRegistry getMetricRegistry() {
return context.getMetricRegistry();
}
@Override
protected TimeUnit getRateUnit() {
return defaultRateUnit;
}
@Override
protected TimeUnit getDurationUnit() {
return defaultDurationUnit;
}
});
servletContextHandler.addEventListener(new HealthCheckServlet.ContextListener() {
@Override
protected HealthCheckRegistry getHealthCheckRegistry() {
return context.getHealthCheckRegistry();
}
});
server = new Server(port);
server.setHandler(servletContextHandler);
try {
server.start();
} catch (Exception e) {
throw new MorphlineRuntimeException(e);
}
SERVERS.put(port, server);
}
}
}
示例14: SentryWebServer
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
public SentryWebServer(List<EventListener> listeners, int port, Configuration conf) {
this.port = port;
server = new Server(port);
ServletContextHandler servletContextHandler = new ServletContextHandler();
ServletHolder servletHolder = new ServletHolder(AdminServlet.class);
servletContextHandler.addServlet(servletHolder, "/*");
for(EventListener listener:listeners) {
servletContextHandler.addEventListener(listener);
}
ServletHolder confServletHolder = new ServletHolder(ConfServlet.class);
servletContextHandler.addServlet(confServletHolder, "/conf");
servletContextHandler.getServletContext()
.setAttribute(ConfServlet.CONF_CONTEXT_ATTRIBUTE, conf);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
URL url = this.getClass().getResource(RESOURCE_DIR);
try {
resourceHandler.setBaseResource(Resource.newResource(url.toString()));
} catch (IOException e) {
LOGGER.error("Got exception while setBaseResource for Sentry Service web UI", e);
}
resourceHandler.setWelcomeFiles(new String[]{WELCOME_PAGE});
ContextHandler contextHandler= new ContextHandler();
contextHandler.setHandler(resourceHandler);
ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
contextHandlerCollection.setHandlers(new Handler[]{contextHandler, servletContextHandler});
String authMethod = conf.get(ServerConfig.SENTRY_WEB_SECURITY_TYPE);
if (!ServerConfig.SENTRY_WEB_SECURITY_TYPE_NONE.equals(authMethod)) {
/**
* SentryAuthFilter is a subclass of AuthenticationFilter and
* AuthenticationFilter tagged as private and unstable interface:
* While there are not guarantees that this interface will not change,
* it is fairly stable and used by other projects (ie - Oozie)
*/
FilterHolder filterHolder = servletContextHandler.addFilter(SentryAuthFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
filterHolder.setInitParameters(loadWebAuthenticationConf(conf));
}
server.setHandler(contextHandlerCollection);
}
示例15: configureInternalServlets
import com.codahale.metrics.servlets.AdminServlet; //导入依赖的package包/类
protected void configureInternalServlets(ServletContextHandler handler) {
handler.addServlet(new ServletHolder(new AdminServlet()), "/*");
}