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());
}
}
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);
}
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);
}
}
Aggregations