List of usage examples for org.springframework.boot.actuate.health Health outOfService
public static Builder outOfService()
From source file:com.netflix.genie.web.health.GenieMemoryHealthIndicator.java
/** * {@inheritDoc}/*from w w w . j ava 2 s . com*/ */ @Override public Health health() { final int usedMemory = this.jobMetricsService.getUsedMemory(); final JobsMemoryProperties memoryProperties = this.jobsProperties.getMemory(); final int availableMemory = memoryProperties.getMaxSystemMemory() - usedMemory; final int maxJobMemory = memoryProperties.getMaxJobMemory(); final int defaultJobMemory = memoryProperties.getDefaultJobMemory(); final Health.Builder builder; // If we can fit one more max job in we're still healthy if (availableMemory >= maxJobMemory) { builder = Health.up(); } else { builder = Health.outOfService(); } return builder.withDetail(NUMBER_RUNNING_JOBS_KEY, this.jobMetricsService.getNumActiveJobs()) .withDetail(USED_MEMORY_KEY, usedMemory).withDetail(AVAILABLE_MEMORY, availableMemory) .withDetail(AVAILABLE_DEFAULT_JOB_CAPACITY, (availableMemory >= 0 && defaultJobMemory > 0) ? (availableMemory / defaultJobMemory) : 0) .withDetail(AVAILABLE_MAX_JOB_CAPACITY, (availableMemory >= 0 && maxJobMemory > 0) ? (availableMemory / maxJobMemory) : 0) .build(); }
From source file:com.netflix.genie.web.health.GenieCpuHealthIndicator.java
@Override public Health health() { // Use the distribution summary to get an average of the cpu metrics. final long cpuCount = summaryCpuMetric.getCount(); final long cpuTotal = summaryCpuMetric.getTotalAmount(); final double currentCpuLoadPercent = cpuCount == 0 ? operatingSystemMXBean.getSystemCpuLoad() : (cpuTotal / (double) cpuCount); if (currentCpuLoadPercent > maxCpuLoadPercent) { cpuLoadConsecutiveOccurrences++; } else {/*from w w w.j a va 2s. c o m*/ cpuLoadConsecutiveOccurrences = 0; } // Mark the service down only after a consecutive number of cpu load occurrences. if (cpuLoadConsecutiveOccurrences >= maxCpuLoadConsecutiveOccurrences) { log.warn("CPU usage {} crossed the threshold of {}", currentCpuLoadPercent, maxCpuLoadPercent); return Health.outOfService().withDetail(CPU_LOAD, currentCpuLoadPercent).build(); } else { return Health.up().withDetail(CPU_LOAD, currentCpuLoadPercent).build(); } }