Java Code Examples for org.springframework.boot.actuate.health.Health.Builder#down()

The following examples show how to use org.springframework.boot.actuate.health.Health.Builder#down() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefreshScopeHealthIndicator.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Override
protected void doHealthCheck(Builder builder) throws Exception {
	RefreshScope refreshScope = this.scope.getIfAvailable();
	if (refreshScope != null) {
		Map<String, Exception> errors = new HashMap<>(refreshScope.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));
				}
			}
		}
	}
}
 
Example 2
Source File: TimeoutsHealthIndicator.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
protected void doHealthCheck(Builder builder) throws Exception {
	try {
		// Get the statistical parameter (min/max/avg/latest) etc.
		TimesWrapper wrap = this.getLargestMessage();
		if (logger.isDebugEnabled()) {
			logger.debug("TimeoutsHealth message={}", objectMapper.writeValueAsString(wrap));
		}
		if (wrap == null) {
			HealthUtil.up(builder, "Healthy");
			return;
		} else if (wrap.getMax() < conf.getTimeoutsThreshold()) {
			HealthUtil.up(builder, "Healthy");
		} else {
			HealthUtil.down(builder, "Method " + wrap.getMetricsName() + " executes " + wrap.getLatest()
					+ "ms with a response exceeding the threshold value of `" + conf.getTimeoutsThreshold() + "`ms.");
			// When the timeout exception is detected, the exception record
			// is cleared.
			this.postPropertiesReset(wrap);
		}
		builder.withDetail("Method", wrap.getMetricsName()).withDetail("Least", wrap.getMin())
				.withDetail("Largest", wrap.getMax()).withDetail("Avg", wrap.getAvg()).withDetail("Latest", wrap.getLatest())
				.withDetail("Samples", wrap.getSamples()).withDetail("Threshold", conf.getTimeoutsThreshold() + "ms");

	} catch (Exception e) {
		builder.down(e);
		logger.error("Analysis timeouts message failed.", e);
	}

}
 
Example 3
Source File: JobExecutorHealthIndicator.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 4
Source File: JobExecutorHealthIndicator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 5
Source File: AbstractAdvancedHealthIndicator.java    From super-cloudops with Apache License 2.0 4 votes vote down vote up
@Override
protected void doHealthCheck(Builder builder) throws Exception {
	int index = 0;
	StringBuffer desc = new StringBuffer();
	for (String name : this.eventStores.keySet()) {
		try {
			EventStore<Partition> store = this.eventStores.get(name);
			Partition latestPart = store.latest();
			if (logger.isDebugEnabled())
				logger.debug("Health performance:{}", mapper.writeValueAsString(latestPart));

			if (latestPart == null) {
				builder.up();
				return;
			}

			// Get partition configuration by current partition.
			Partition confPart = this.conf.getPartitions().get(name);
			if (confPart == null)
				throw new Error("It should not come here. " + name);

			// Check threshold.
			long threshold = confPart.getValue();
			long curVal = latestPart.getValue();
			if (this.compare(curVal, threshold) < 0) { // Trigger event.
				if (desc.length() > 0) {
					desc.append("<br/>");
				}
				desc.append(name).append(":").append(formatValue(curVal)).append(" exceed the threshold:")
						.append(formatValue(confPart.getValue()));
			}
			// Meaningful field name prefix.
			String p = this.compareFieldName();
			builder.withDetail("AcqPosition_" + index, name).withDetail("AcqSamples_" + index, latestPart.getSamples())
					.withDetail("AcqTime_" + index, latestPart.getFormatTimestamp())
					.withDetail(p + "Avg_" + index, formatValue(store.average()))
					.withDetail(p + "Lgt_" + index, formatValue(store.largest().getValue()))
					.withDetail(p + "Let_" + index, formatValue(store.least().getValue()))
					.withDetail(p + "Lat_" + index, formatValue(store.latest().getValue()))
					.withDetail(p + "Threshold_" + index, formatValue(threshold));
			// All the checks are normal.
			if (desc.length() > 0) {
				HealthUtil.down(builder, desc.toString());
				desc.setLength(0); // Reset.
			} else {
				builder.up();
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Acquisition unhealthy description:{}", desc);
			}

		} catch (Exception e) {
			builder.down(e);
			logger.error("Advanced health check failed.", e);
		} finally {
			// Increase by 1
			++index;
		}
	}

}