@ Scheduled ( fixedDelay = "${micronaut.health.monitor.interval:1m}" , initialDelay = "${micronaut.health.monitor.initial-delay:1m}" ) void monitor ( ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Starting health monitor check" ) ; } List < Publisher < HealthResult > > healthResults = healthIndicators . stream ( ) . map ( HealthIndicator :: getResult ) . collect ( Collectors . toList ( ) ) ; Flowable < HealthResult > resultFlowable = Flowable . merge ( healthResults ) . filter ( healthResult -> { HealthStatus status = healthResult . getStatus ( ) ; return status . equals ( HealthStatus . DOWN ) || ! status . getOperational ( ) . orElse ( true ) ; } ) ; resultFlowable . firstElement ( ) . subscribe ( new MaybeObserver < HealthResult > ( ) { @ Override public void onSubscribe ( Disposable d ) { } @ Override public void onSuccess ( HealthResult healthResult ) { HealthStatus status = healthResult . getStatus ( ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Health monitor check failed with status {}" , status ) ; } currentHealthStatus . update ( status ) ; } @ Override public void onError ( Throwable e ) { if ( LOG . isErrorEnabled ( ) ) { LOG . error ( "Health monitor check failed with exception: " + e . getMessage ( ) , e ) ; } currentHealthStatus . update ( HealthStatus . DOWN . describe ( "Error occurred running health check: " + e . getMessage ( ) ) ) ; } @ Override public void onComplete ( ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Health monitor check passed." ) ; } currentHealthStatus . update ( HealthStatus . UP ) ; } } ) ; }
Start the continuous health monitor .