當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。