当前位置: 首页>>代码示例>>Java>>正文


Java HealthCheckRegistry类代码示例

本文整理汇总了Java中com.codahale.metrics.health.HealthCheckRegistry的典型用法代码示例。如果您正苦于以下问题:Java HealthCheckRegistry类的具体用法?Java HealthCheckRegistry怎么用?Java HealthCheckRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HealthCheckRegistry类属于com.codahale.metrics.health包,在下文中一共展示了HealthCheckRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMetricsHandler

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的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;
}
 
开发者ID:flipkart-incubator,项目名称:Poseidon,代码行数:19,代码来源:Poseidon.java

示例2: healthCheckHandler

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
public static Handler healthCheckHandler(
    HealthCheckRegistry healthCheckRegistry, ObjectMapper mapper) {
  Preconditions.checkState(healthCheckRegistry != null);
  Preconditions.checkState(mapper != null);

  SortedMap<String, HealthCheck.Result> healthChecks = healthCheckRegistry.runHealthChecks();

  return xrpcRequest ->
      Recipes.newResponseOk(
          xrpcRequest
              .getAlloc()
              .directBuffer()
              .writeBytes(
                  mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(healthChecks)),
          Recipes.ContentType.Application_Json);
}
 
开发者ID:Nordstrom,项目名称:xrpc,代码行数:17,代码来源:AdminHandlers.java

示例3: getDataSourceFromConfig

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
public static HikariDataSource getDataSourceFromConfig(
    Config conf
    , MetricRegistry metricRegistry
    , HealthCheckRegistry healthCheckRegistry) {

    HikariConfig jdbcConfig = new HikariConfig();
    jdbcConfig.setPoolName(conf.getString("poolName"));
    jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize"));
    jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle"));
    jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl"));
    jdbcConfig.setUsername(conf.getString("username"));
    jdbcConfig.setPassword(conf.getString("password"));

    jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit"));
    jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts"));

    // Add HealthCheck
    jdbcConfig.setHealthCheckRegistry(healthCheckRegistry);

    // Add Metrics
    jdbcConfig.setMetricRegistry(metricRegistry);
    return new HikariDataSource(jdbcConfig);
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:26,代码来源:ConnectionPool.java

示例4: loadDimensionDictionary

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
@Override
public void loadDimensionDictionary(DimensionDictionary dimensions) {
    HealthCheckRegistry healthCheckRegistry = HealthCheckRegistryFactory.getRegistry();
    for (DimensionConfig dimension : configSource) {
        dimensions.add(new KeyValueStoreDimension(dimension));

        //Register KeyValueStore Health Check
        healthCheckRegistry.register(
            dimension.getApiName() + " keyValueStore check",
            new KeyValueStoreHealthCheck(dimension.getKeyValueStore())
        );

        //Register SearchProvider Health Check
        healthCheckRegistry.register(
            dimension.getApiName() + " searchProvider check",
            new SearchProviderHealthCheck(dimension.getSearchProvider())
        );
    }
}
 
开发者ID:yahoo,项目名称:fili,代码行数:20,代码来源:KeyValueStoreDimensionLoader.java

示例5: activateService

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
@Override
public void activateService() {
    metricRegistry = new MetricRegistry();
    healthCheckRegistry = new HealthCheckRegistry();
    CodahaleMetricsDeclaration declaration = descriptor.metaInfo( CodahaleMetricsDeclaration.class );
    prefix = declaration.prefix() != null ? declaration.prefix() : app.name();
    fqcn = declaration.fqcn();
    if( declaration.jmx() )
    {
        JmxReporter jmxReporter = JmxReporter.forRegistry( metricRegistry ).build();
        jmxReporter.start();
        reporters.add( jmxReporter );
    }
    for( Function<MetricRegistry, Reporter> reporterFactory : declaration.reportersFactories())
    {
        reporters.add( reporterFactory.apply( metricRegistry ) );
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:19,代码来源:CodahaleMetricsMixin.java

示例6: main

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
public static void main(String[] args) {
	SpringApplication.run(MonetaSpringBootApplication.class, args);

	// Find and read application configuration
	MonetaConfiguration config = new MonetaConfiguration();

	// Install all health checks
	HealthCheckRegistry registry = new HealthCheckRegistry();
	for (String checkName : MonetaEnvironment.getConfiguration()
			.getHealthChecks()
			.keySet()) {
		registry.register(checkName, MonetaEnvironment.getConfiguration()
				.getHealthChecks()
				.get(checkName));
	}
	ActuatorHealthIndicator.setHealthCheckRegistry(registry);

	// Install metrics and JMX
	MetricRegistry metricRegistry = new MetricRegistry();
	final JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry)
			.build();
	jmxReporter.start();
}
 
开发者ID:Derek-Ashmore,项目名称:moneta,代码行数:24,代码来源:MonetaSpringBootApplication.java

示例7: testRegisteringSameHealthcheckMultipleTimes

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
/**
 * Shows that that when the 2 healthchecks with the same name are registered, then the latest one will replace the previous one.
 */
@Test
public void testRegisteringSameHealthcheckMultipleTimes() {
    final HealthCheckRegistry registry = new HealthCheckRegistry();
    final String healthCheckName = "health-check";
    final HealthCheck healthCheck1 = new HealthCheck() {

        @Override
        protected HealthCheck.Result check() throws Exception {
            return HealthCheck.Result.healthy();
        }
    };
    final HealthCheck healthCheck2 = new HealthCheck() {

        @Override
        protected HealthCheck.Result check() throws Exception {
            return HealthCheck.Result.healthy();
        }
    };
    registry.register(healthCheckName, healthCheck1);
    registry.register(healthCheckName, healthCheck2);

    assertThat(registry.getNames().size(), is(1));
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:27,代码来源:QuickTest.java

示例8: shouldRegisterHealthCheck

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
@Test
public void shouldRegisterHealthCheck() throws Exception {
    //GIVEN
    AmazonSQS sqs = mock(AmazonSQS.class);

    SqsBundle spiedBundle = spy(bundle);
    doReturn(sqs).when(spiedBundle).getAmazonSQS();

    LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class);
    doNothing().when(lifecycle).manage((Managed) anyObject());
    when(environment.lifecycle()).thenReturn(lifecycle);

    HealthCheckRegistry healthChecks = mock(HealthCheckRegistry.class);
    doNothing().when(healthChecks).register(anyObject(), anyObject());
    when(environment.healthChecks()).thenReturn(healthChecks);

    //WHEN
    spiedBundle.run(configurationHolder, environment);

    //THEN
    verify(healthChecks, times(1)).register(eq("SqsBundle"), any(SqsBundleHealthCheck.class));
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:23,代码来源:SqsBundleTest.java

示例9: run

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
@Override
public void run() {
    StormClusterState clusterState = workerData.getZkCluster();
    String topologyId = workerData.getTopologyId();

    Map<Integer, HealthCheckRegistry> taskHealthCheckMap = JStormHealthCheck.getTaskhealthcheckmap();
    int cnt = 0;
    for (Map.Entry<Integer, HealthCheckRegistry> entry : taskHealthCheckMap.entrySet()) {
        Integer taskId = entry.getKey();
        Map<String, Result> results = entry.getValue().runHealthChecks();

        for (Map.Entry<String, Result> result : results.entrySet()) {
            if (!result.getValue().isHealthy()) {
                try {
                    clusterState.report_task_error(topologyId, taskId, result.getValue().getMessage(), null);
                    cnt++;
                } catch (Exception e) {
                    LOG.error("Failed to update health data in ZK for topo-{} task-{}.", topologyId, taskId, e);
                }
            }
        }
    }
    LOG.info("Successfully updated {} health data to ZK for topology:{}", cnt, topologyId);
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:25,代码来源:JStormHealthReporter.java

示例10: onActivate

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
@Override
public void onActivate( Application application )
    throws ActivationException
{
    application.plugin( JSON.class ).mapper()
        .registerModule( new MetricsModule( SECONDS, MILLISECONDS, true ) )
        .registerModule( new HealthCheckModule() );
    MetricRegistry metrics = new MetricRegistry();
    HealthCheckRegistry healthChecks = new HealthCheckRegistry();

    registerMetrics( application, metrics );
    registerMetricsReporters( application, metrics );
    registerHealthChecks( application, healthChecks );

    api = new Metrics( metrics, healthChecks );
}
 
开发者ID:werval,项目名称:werval,代码行数:17,代码来源:MetricsPlugin.java

示例11: HealthChecksThreadPool

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
public HealthChecksThreadPool(HealthCheckRegistry healthCheckRegistry) {
    super(MAX_THREAD_POOL_SIZE, MAX_THREAD_POOL_SIZE, 5L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(), //
            new ExceptionCatchingThreadFactory(new DaemonThreadFactory(new ThreadFactory() {
                private final AtomicInteger number = new AtomicInteger();

                public Thread newThread(Runnable r) {
                    return new Thread(r, "Metrics-HealthChecks-" + number.incrementAndGet());
                }
            })), new MetricsRejectedExecutionHandler(healthCheckRegistry));
    this.allowCoreThreadTimeOut(true); // allow stopping all threads if idle
    this.healthCheckRegistry = healthCheckRegistry;
    LOGGER.log(Level.FINE,
            "Created thread pool with a max of {0} threads (plus {1} in queue) for {2} health checks",
            new Object[] { getMaximumPoolSize(),
                           Math.max(0, healthCheckRegistry.getNames().size() + 1 - getMaximumPoolSize()),
                           healthCheckRegistry.getNames().size() });
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:19,代码来源:HealthChecksThreadPool.java

示例12: dropOldestInQueue

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
/**
 * Drop the oldest health check in executor queue and cancel it
 */
static void dropOldestInQueue(ThreadPoolExecutor executor, HealthCheckRegistry healthCheckRegistry) {
    // capture the state up front
    Object[] params = {
            executor, executor.getQueue().size(), healthCheckRegistry.getNames(),
            healthCheckRegistry.getNames().size(), Arrays.asList(executor.getQueue().toArray())
    };

    Runnable discarded = executor.getQueue().poll();
    // if there are two workers taking jobs concurrently, the queue will be empty by the time we get here
    if (discarded != null) {
        LOGGER.log(Level.WARNING,
                "Too many health check executions queued, dropping oldest one. This may mean some health checks "
                        + "are taking too long to execute:"
                        + " {0}, queue size={1}, health checks={2} ({3}) {4}",
                params);
        cancelQueuedHealthCheck(discarded);
    }
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:22,代码来源:HealthChecksThreadPool.java

示例13: handle

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
@Override
public void handle(final Request req, final Response rsp) throws Throwable {
  HealthCheckRegistry registry = req.require(HealthCheckRegistry.class);
  SortedMap<String, Result> checks = req.param("name").toOptional().map(name -> {
    SortedMap<String, Result> set = ImmutableSortedMap.of(name, registry.runHealthCheck(name));
    return set;
  }).orElseGet(() -> registry.runHealthChecks());

  final Status status;
  if (checks.isEmpty()) {
    status = Status.NOT_IMPLEMENTED;
  } else {
    status = checks.values().stream()
        .filter(it -> !it.isHealthy())
        .findFirst()
        .map(it -> Status.SERVER_ERROR)
        .orElse(Status.OK);
  }
  rsp.status(status)
      .header("Cache-Control", "must-revalidate,no-cache,no-store")
      .send(checks);
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:23,代码来源:HealthCheckHandler.java

示例14: StatisticsController

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
public StatisticsController(final DelegatingAuditTrailManager auditTrailManager,
                            final CentralAuthenticationService centralAuthenticationService,
                            final MetricRegistry metricsRegistry,
                            final HealthCheckRegistry healthCheckRegistry,
                            final CasConfigurationProperties casProperties) {
    super("casstats", "/stats", casProperties.getMonitor().getEndpoints().getStatistics(), casProperties);
    this.auditTrailManager = auditTrailManager;
    this.centralAuthenticationService = centralAuthenticationService;
    this.metricsRegistry = metricsRegistry;
    this.healthCheckRegistry = healthCheckRegistry;
    this.casProperties = casProperties;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:13,代码来源:StatisticsController.java

示例15: HealthCheckResource

import com.codahale.metrics.health.HealthCheckRegistry; //导入依赖的package包/类
@Inject
public HealthCheckResource(Set<HealthCheck> healthChecks) {
  this.healthCheckRegistry = new HealthCheckRegistry();
  for (HealthCheck healthCheck : healthChecks) {
    healthCheckRegistry.register(healthCheck.getClass().getSimpleName(), healthCheck);
  }
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:8,代码来源:HealthCheckResource.java


注:本文中的com.codahale.metrics.health.HealthCheckRegistry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。