@Test public void testDoHealthCheckSingleQueueCheckMetricException() throws Exception { Queue queue = generateQueue("test"); healthIndicator.addQueueCheck(queue, 10000, 2); propertiesManager.request(queue); PowerMock.expectLastCall().andThrow(new RuntimeException()); PowerMock.replayAll(); Builder builder = new Builder(Status.OUT_OF_SERVICE); healthIndicator.doHealthCheck(builder); PowerMock.verifyAll(); Health health = builder.build(); Assert.assertEquals(Status.DOWN, health.getStatus()); Assert.assertNull(health.getDetails().get("test")); }
@Override public Health health() { try { VaultHealth vaultHealthResponse = vaultOperations.opsForSys().health(); Builder healthBuilder = getHealthBuilder(vaultHealthResponse); if (StringUtils.hasText(vaultHealthResponse.getVersion())) { healthBuilder = healthBuilder.withDetail("version", vaultHealthResponse.getVersion()); } return healthBuilder.build(); } catch (Exception e) { return Health.down(e).build(); } }
private Builder getHealthBuilder(VaultHealth vaultHealthResponse) { if (!vaultHealthResponse.isInitialized()) { return Health.down().withDetail("state", "Vault uninitialized"); } if (vaultHealthResponse.isSealed()) { return Health.down().withDetail("state", "Vault sealed"); } if (vaultHealthResponse.isStandby()) { return Health.up().withDetail("state", "Vault in standby"); } return Health.up(); }
/** 営業日チェック */ @Bean @ConditionalOnBean(BusinessDayHandler.class) HealthIndicator dayIndicator(final Timestamper time, final BusinessDayHandler day) { return new AbstractHealthIndicator() { @Override protected void doHealthCheck(Builder builder) throws Exception { builder.up(); builder.withDetail("day", day.day()) .withDetail("dayMinus1", day.day(-1)) .withDetail("dayPlus1", day.day(1)) .withDetail("dayPlus2", day.day(2)) .withDetail("dayPlus3", day.day(3)); } }; }
@Override protected void doHealthCheck(Builder builder) throws Exception { Map<String, Exception> errors = new HashMap<>(this.scope.getIfAvailable().getErrors()); errors.putAll(this.rebinder.getErrors()); if (errors.isEmpty()) { builder.up(); } else { builder.down(); if (errors.size() == 1) { builder.withException(errors.values().iterator().next()); } else { for (String name : errors.keySet()) { builder.withDetail(name, errors.get(name)); } } } }
@Override protected void doHealthCheck(Builder builder) throws Exception { List<String> openCircuitBreakers = new ArrayList<>(); // Collect all open circuit breakers from Hystrix for (HystrixCommandMetrics metrics : HystrixCommandMetrics.getInstances()) { HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory .getInstance(metrics.getCommandKey()); if (circuitBreaker != null && circuitBreaker.isOpen()) { openCircuitBreakers.add(metrics.getCommandGroup().name() + "::" + metrics.getCommandKey().name()); } } // If there is at least one open circuit report OUT_OF_SERVICE adding the command // group // and key name if (!openCircuitBreakers.isEmpty()) { builder.status(CIRCUIT_OPEN).withDetail("openCircuitBreakers", openCircuitBreakers); } else { builder.up(); } }
@Override protected void doHealthCheck(Builder builder) throws Exception { PropertySource<?> propertySource = getPropertySource(); builder.up(); if (propertySource instanceof CompositePropertySource) { List<String> sources = new ArrayList<>(); for (PropertySource<?> ps : ((CompositePropertySource) propertySource).getPropertySources()) { sources.add(ps.getName()); } builder.withDetail("propertySources", sources); } else if (propertySource!=null) { builder.withDetail("propertySources", propertySource.toString()); } else { builder.unknown().withDetail("error", "no property sources located"); } }
@Override protected void doHealthCheck(Builder builder) throws Exception { JestResult result = jestClient.execute(new Stats.Builder().addIndex(this.indices).build()); JsonObject map = result.getJsonObject(); if (result.isSucceeded()) { builder.up(); for (String indexName : this.indices) { fillStatsForIndex(indexName, map, builder); } } else { builder.down(); } }
/** 営業日チェック */ @Bean HealthIndicator dayIndicator(final Timestamper time, final BusinessDayHandler day) { return new AbstractHealthIndicator() { @Override protected void doHealthCheck(Builder builder) throws Exception { builder.up(); builder.withDetail("day", day.day()) .withDetail("dayMinus1", day.day(-1)) .withDetail("dayPlus1", day.day(1)) .withDetail("dayPlus2", day.day(2)) .withDetail("dayPlus3", day.day(3)); } }; }
@Override protected void doHealthCheck(Builder builder) throws Exception { int errorCode = new Random().nextInt(2); log.info("*************************** errorCode: {}", errorCode); if (errorCode != 0) { builder.down().withDetail("errorCode", errorCode).build(); } else { builder.up(); } }
@Override protected void doHealthCheck(Builder builder) throws Exception { log.info("Test geolocation service health - start."); long startTime = System.currentTimeMillis(); Mentor mentor = mentorRepository.findAll().iterator().next(); Point point = mentorUtils.getLocationOfMentor(mentor); if (point.getLatitude() != 0) { builder.withDetail("handle", point.toString()).up(); } else { builder.status("GeocodingError"); } log.info("Test geolocation service health - end. Duration: " + Long.toString(System.currentTimeMillis() - startTime) + "ms"); }
@Override protected void doHealthCheck(Builder builder) throws Exception { if (twitter.isAuthenticated()) { builder.withDetail("handle", twitter.getScreenName()).up(); } else { builder.status("NotAuthenticated"); } }
@Test public void testDoHealthCheckNoQueueChecks() throws Exception { Builder builder = new Builder(Status.OUT_OF_SERVICE); healthIndicator.doHealthCheck(builder); Assert.assertEquals(Status.UP, builder.build().getStatus()); }
@SuppressWarnings({ "unchecked", "boxing" }) @Test public void testDoHealthCheckSingleQueueCheckUp() throws Exception { Queue queue = generateQueue("test"); healthIndicator.addQueueCheck(queue, 10000, 2); RabbitQueueProperties properties = new RabbitQueueProperties(); properties.setConsumerCount(4); properties.setMessageCount(5883); propertiesManager.request(queue); PowerMock.expectLastCall().andReturn(properties); PowerMock.replayAll(); Builder builder = new Builder(Status.OUT_OF_SERVICE); healthIndicator.doHealthCheck(builder); PowerMock.verifyAll(); Health health = builder.build(); Assert.assertEquals(Status.UP, health.getStatus()); Assert.assertNotNull(health.getDetails().get("test")); Map<String, Object> details = (Map<String, Object>) health.getDetails().get("test"); Assert.assertEquals(Status.UP.getCode(), details.get("status")); Assert.assertEquals(5883, details.get("currentMessageCount")); Assert.assertEquals(10000, details.get("maxMessageCount")); Assert.assertEquals(4, details.get("currentConsumerCount")); Assert.assertEquals(2, details.get("minConsumerCount")); }
@SuppressWarnings({ "unchecked", "boxing" }) @Test public void testDoHealthCheckSingleQueueCheckQueueSizeDown() throws Exception { Queue queue = generateQueue("test"); healthIndicator.addQueueCheck(queue, 10000, 2); RabbitQueueProperties properties = new RabbitQueueProperties(); properties.setConsumerCount(4); properties.setMessageCount(15883); propertiesManager.request(queue); PowerMock.expectLastCall().andReturn(properties); PowerMock.replayAll(); Builder builder = new Builder(Status.OUT_OF_SERVICE); healthIndicator.doHealthCheck(builder); PowerMock.verifyAll(); Health health = builder.build(); Assert.assertEquals(Status.DOWN, health.getStatus()); Assert.assertNotNull(health.getDetails().get("test")); Map<String, Object> details = (Map<String, Object>) health.getDetails().get("test"); Assert.assertEquals(Status.DOWN.getCode(), details.get("status")); Assert.assertEquals(15883, details.get("currentMessageCount")); Assert.assertEquals(10000, details.get("maxMessageCount")); Assert.assertEquals(4, details.get("currentConsumerCount")); Assert.assertEquals(2, details.get("minConsumerCount")); }
@SuppressWarnings({ "unchecked", "boxing" }) @Test public void testDoHealthCheckSingleQueueCheckConsumerDown() throws Exception { Queue queue = generateQueue("test"); healthIndicator.addQueueCheck(queue, 10000, 2); RabbitQueueProperties properties = new RabbitQueueProperties(); properties.setConsumerCount(1); properties.setMessageCount(5883); propertiesManager.request(queue); PowerMock.expectLastCall().andReturn(properties); PowerMock.replayAll(); Builder builder = new Builder(Status.OUT_OF_SERVICE); healthIndicator.doHealthCheck(builder); PowerMock.verifyAll(); Health health = builder.build(); Assert.assertEquals(Status.DOWN, health.getStatus()); Assert.assertNotNull(health.getDetails().get("test")); Map<String, Object> details = (Map<String, Object>) health.getDetails().get("test"); Assert.assertEquals(Status.DOWN.getCode(), details.get("status")); Assert.assertEquals(5883, details.get("currentMessageCount")); Assert.assertEquals(10000, details.get("maxMessageCount")); Assert.assertEquals(1, details.get("currentConsumerCount")); Assert.assertEquals(2, details.get("minConsumerCount")); }
@Override protected void doHealthCheck(Builder builder) throws Exception { builder.withDetail("location", this.mailSender.getHost() + ":" + this.mailSender.getPort()); this.mailSender.testConnection(); builder.up(); }
@Override public final Health health() { Health.Builder builder = new Health.Builder(); try { doHealthCheck(builder); } catch (Exception ex) { builder.down(ex); } return builder.build(); }
@Override protected void doHealthCheck(Builder builder) throws Exception { boolean active = jobExecutor.isActive(); if (active) { builder = builder.up(); } else { builder = builder.down(); } builder.withDetail("jobExecutor", Details.from(jobExecutor)); }
@Override protected void doHealthCheck(Builder builder) throws Exception { //check dara health if (this.daraService.isDaraHealthy()) { builder.up(); builder.withDetail("location", this.daraService.getApiEndpoint()); } else { builder.down(); } }
@Override protected void doHealthCheck(Builder builder) throws Exception { JestResult result = jestClient.execute(new Stats.Builder().addIndex("_all").build()); JsonObject map = result.getJsonObject(); if (result.isSucceeded()) { builder.up(); fillStatsForIndex(map, builder); } else { builder.down(); } builder.withDetail("Number of Update Queue Items", elasticsearchUpdateQueueItemRepository.count()); }
/** * Fill statistics for all indices. * * @param map The json object for the _all index. * @param builder The spring boot builder. */ private void fillStatsForIndex(JsonObject map, Builder builder) { JsonObject indices = map.getAsJsonObject("indices"); indices.entrySet().forEach(entry -> { String indexName = entry.getKey(); JsonObject indexStats = entry.getValue().getAsJsonObject(); JsonObject primaries = indexStats.getAsJsonObject("primaries"); builder.withDetail(indexName + "." + "docs_count", primaries.getAsJsonObject("docs").get("count").getAsString()); }); }
@Override protected void doHealthCheck(Builder builder) throws Exception { if (env.acceptsProfiles(Constants.SPRING_PROFILE_LOCAL)) { builder.withDetail("Message Broker", "Simple (local)"); } else { builder.withDetail("Message Broker", "CloudAMQP (RabbitMQ)"); } builder.withDetail("Active Websocket Sessions", activeWebSocketSessionRepository.count()); messagingTemplate.convertAndSend("/topic", "Ping"); builder.up(); }
@Override protected void doHealthCheck(final Builder builder) throws Exception { try { feign.greet(In.builder().name(service).build()); builder.up(). withDetail("endpoint", "http://remote-hello/greet"); } catch (final Exception e) { builder.outOfService(). withDetail("endpoint", "http://remote-hello/greet"). withDetail("exception", e.getMessage()); } }
@Override public Health health() { Builder builder = Health.unknown(); Status status = getStatus(builder); return builder.status(status).withDetail("applications", getApplications()) .build(); }
private void fillStatsForIndex(String indexName, JsonObject map, Builder builder) { JsonObject indexStats = map.getAsJsonObject("indices").getAsJsonObject(indexName); if (indexStats != null) { JsonObject primaries = indexStats.getAsJsonObject("primaries"); builder.withDetail(indexName + "." + "docs_count", primaries.getAsJsonObject("docs").get("count").getAsString()); builder.withDetail(indexName + "." + "docs_deleted", primaries.getAsJsonObject("docs").get("deleted").getAsString()); builder.withDetail(indexName + "." + "store_size", primaries.getAsJsonObject("store").get("size_in_bytes").getAsString()); builder.withDetail(indexName + "." + "query_total", primaries.getAsJsonObject("search").get("query_total").getAsString()); } }
@Override protected void doHealthCheck(Builder builder) throws Exception { final MBeanServer server = getMBeanServer(); if (server != null) { final ObjectName on = new ObjectName("Q2:type=qbean,service=*"); final Set<ObjectName> names = server.queryNames(on, null); final Stream<ObjectName> s = names.stream(); final long muxInTransitCount = getMuxInTransitCount(server, names); final long tmInTransitCount = getTmInTransitCount(server, names); builder.withDetail("mux.in-transit", String.valueOf(muxInTransitCount)); builder.withDetail("tm.in-transit", String.valueOf(tmInTransitCount)); builder.withDetail("in-transit", String.valueOf(Math.max(muxInTransitCount, tmInTransitCount))); if (s.allMatch(name -> getStatus(server, name) == QBean.STARTED)) { builder.up(); } else if (s.anyMatch(name -> getStatus(server, name) == QBean.FAILED)) { long cnt = s.filter(name -> getStatus(server, name) == QBean.FAILED).count(); Set<String> objs = s.filter(name -> getStatus(server, name) == QBean.FAILED) .map(ObjectName::getCanonicalName) .collect(Collectors.toSet()); String failedServices = StringUtils.collectionToCommaDelimitedString(objs); builder.withDetail("failed-count", String.valueOf(cnt)); builder.withDetail("failed-services", failedServices); builder.status("failed"); } else if (s.allMatch(name -> getStatus(server, name) == QBean.DESTROYED)) { builder.outOfService(); } else if (s.allMatch(name -> getStatus(server, name) == QBean.STOPPED)) { builder.down(); } else { builder.unknown(); } } else { builder.unknown(); } }
@Override protected void doHealthCheck(Builder builder) throws Exception { builder.up(); for (QueueCheck queueCheck : queueChecks) { try { RabbitQueueProperties queueProperties = propertiesManager.request(queueCheck.getQueue()); String queueName = queueCheck.getQueue().getName(); int currentMessageCount = queueProperties.getMessageCount(); int maxMessageCount = queueCheck.getMaxMessageCount(); int currentConsumerCount = queueProperties.getConsumerCount(); int minConsumerCount = queueCheck.getMinConsumerCount(); Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("status", Status.UP.getCode()); details.put("currentMessageCount", Integer.valueOf(currentMessageCount)); details.put("maxMessageCount", Integer.valueOf(maxMessageCount)); details.put("currentConsumerCount", Integer.valueOf(currentConsumerCount)); details.put("minConsumerCount", Integer.valueOf(minConsumerCount)); builder.withDetail(queueName, details); if (currentMessageCount > maxMessageCount) { builder.down(); details.put("status", Status.DOWN.getCode()); log.warn(queueName + ": Too many messages ready (Current: " + currentMessageCount + ", " + "Max-Messages: " + queueCheck.getMaxMessageCount() + ")"); } if (currentConsumerCount < minConsumerCount) { builder.down(); details.put("status", Status.DOWN.getCode()); log.warn(queueName + ": Not enough consumers active (Current: " + currentConsumerCount + ", " + "Min-Consumers: " + queueCheck.getMinConsumerCount() + ")"); } } catch (Exception e) { log.error(e.getMessage(), e); builder.down(); } } }
@SuppressWarnings({ "unchecked", "boxing" }) @Test public void testDoHealthCheckMultipleQueueChecksOneUpOneDown() throws Exception { Queue queue1 = generateQueue("test1"); healthIndicator.addQueueCheck(queue1, 10000, 2); Queue queue2 = generateQueue("test2"); healthIndicator.addQueueCheck(queue2, 40000, 5); RabbitQueueProperties properties1 = new RabbitQueueProperties(); properties1.setConsumerCount(1); properties1.setMessageCount(15883); propertiesManager.request(queue1); PowerMock.expectLastCall().andReturn(properties1); RabbitQueueProperties properties2 = new RabbitQueueProperties(); properties2.setConsumerCount(10); properties2.setMessageCount(5883); propertiesManager.request(queue2); PowerMock.expectLastCall().andReturn(properties2); PowerMock.replayAll(); Builder builder = new Builder(Status.OUT_OF_SERVICE); healthIndicator.doHealthCheck(builder); PowerMock.verifyAll(); Health health = builder.build(); Assert.assertEquals(Status.DOWN, health.getStatus()); Assert.assertEquals(2, health.getDetails().size()); Assert.assertNotNull(health.getDetails().get("test1")); Map<String, Object> details1 = (Map<String, Object>) health.getDetails().get("test1"); Assert.assertEquals(Status.DOWN.getCode(), details1.get("status")); Assert.assertEquals(15883, details1.get("currentMessageCount")); Assert.assertEquals(10000, details1.get("maxMessageCount")); Assert.assertEquals(1, details1.get("currentConsumerCount")); Assert.assertEquals(2, details1.get("minConsumerCount")); Assert.assertNotNull(health.getDetails().get("test2")); Map<String, Object> details2 = (Map<String, Object>) health.getDetails().get("test2"); Assert.assertEquals(Status.UP.getCode(), details2.get("status")); Assert.assertEquals(5883, details2.get("currentMessageCount")); Assert.assertEquals(40000, details2.get("maxMessageCount")); Assert.assertEquals(10, details2.get("currentConsumerCount")); Assert.assertEquals(5, details2.get("minConsumerCount")); }
@Override protected void doHealthCheck(Builder builder) throws Exception { builder.up().withDetail("foo", "bar"); }
@Override protected void doHealthCheck(Builder builder) throws Exception { builder.status(this.up ? Status.UP : Status.DOWN); }
@Override protected void doHealthCheck(Builder builder) throws Exception { builder.up().withDetail("name", processEngine.getName()); }
@Override protected void doHealthCheck(Builder builder) throws Exception { builder.up().withDetail("author", "Arny"); }