Search in sources :

Example 1 with Result

use of com.codahale.metrics.health.HealthCheck.Result in project HikariCP by brettwooldridge.

the class TestMetrics method testHealthChecks.

@Test
public void testHealthChecks() throws Exception {
    MetricRegistry metricRegistry = new MetricRegistry();
    HealthCheckRegistry healthRegistry = new HealthCheckRegistry();
    HikariConfig config = newHikariConfig();
    config.setMaximumPoolSize(10);
    config.setMetricRegistry(metricRegistry);
    config.setHealthCheckRegistry(healthRegistry);
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    config.addHealthCheckProperty("connectivityCheckTimeoutMs", "1000");
    config.addHealthCheckProperty("expected99thPercentileMs", "100");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        quietlySleep(TimeUnit.SECONDS.toMillis(2));
        try (Connection connection = ds.getConnection()) {
        // close immediately
        }
        try (Connection connection = ds.getConnection()) {
        // close immediately
        }
        SortedMap<String, Result> healthChecks = healthRegistry.runHealthChecks();
        Result connectivityResult = healthChecks.get("testHealthChecks.pool.ConnectivityCheck");
        assertTrue(connectivityResult.isHealthy());
        Result slaResult = healthChecks.get("testHealthChecks.pool.Connection99Percent");
        assertTrue(slaResult.isHealthy());
    }
}
Also used : TestElf.newHikariDataSource(com.zaxxer.hikari.pool.TestElf.newHikariDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) MetricRegistry(com.codahale.metrics.MetricRegistry) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Result(com.codahale.metrics.health.HealthCheck.Result) Test(org.junit.Test)

Example 2 with Result

use of com.codahale.metrics.health.HealthCheck.Result in project metrics by dropwizard.

the class HealthCheckRegistry method runHealthChecks.

/**
     * Runs the registered health checks and returns a map of the results.
     *
     * @return a map of the health check results
     */
public SortedMap<String, HealthCheck.Result> runHealthChecks() {
    final SortedMap<String, HealthCheck.Result> results = new TreeMap<String, HealthCheck.Result>();
    for (Map.Entry<String, HealthCheck> entry : healthChecks.entrySet()) {
        final Result result = entry.getValue().execute();
        results.put(entry.getKey(), result);
    }
    return Collections.unmodifiableSortedMap(results);
}
Also used : TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Result(com.codahale.metrics.health.HealthCheck.Result)

Example 3 with Result

use of com.codahale.metrics.health.HealthCheck.Result in project jstorm by alibaba.

the class JStormHealthReporter method run.

@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(), ErrorConstants.WARN, ErrorConstants.CODE_QUEUE_FULL, ErrorConstants.DURATION_SECS_QUEUE_FULL);
                    cnt++;
                } catch (Exception e) {
                    LOG.error("Failed to update health data in ZK for topo-{} task-{}.", topologyId, taskId, e);
                }
            }
        }
    }
    if (cnt > 0) {
        LOG.info("Successfully updated {} health data to ZK for topology:{}", cnt, topologyId);
    }
}
Also used : StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Map(java.util.Map) Result(com.codahale.metrics.health.HealthCheck.Result)

Aggregations

Result (com.codahale.metrics.health.HealthCheck.Result)3 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)2 Map (java.util.Map)2 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)1 TestElf.newHikariDataSource (com.zaxxer.hikari.pool.TestElf.newHikariDataSource)1 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Test (org.junit.Test)1