Example usage for org.springframework.boot.actuate.health Health down

List of usage examples for org.springframework.boot.actuate.health Health down

Introduction

In this page you can find the example usage for org.springframework.boot.actuate.health Health down.

Prototype

public static Builder down(Exception ex) 

Source Link

Document

Create a new Builder instance with an Status#DOWN status and the specified exception details.

Usage

From source file:com.ninjas.movietime.health.MongoDbHealth.java

@Override
public Health health() {
    try {/*from  ww w  .  ja v  a  2  s.com*/
        Preconditions.checkNotNull(mongoTemplate, "mongoTemplate is null");
        DBObject ping = new BasicDBObject("ping", "1");
        final CommandResult pingCommandResult = mongoTemplate.getDb().command(ping);
        pingCommandResult.throwOnError();
        //ping worked, now getting version
        DBObject serverStatus = new BasicDBObject("serverStatus", "1");
        final CommandResult serverStatusCommandResult = mongoTemplate.getDb().command(serverStatus);
        serverStatusCommandResult.throwOnError();

        final String server = pingCommandResult.getServerUsed().toString();
        final String version = serverStatusCommandResult.get("version").toString();

        Preconditions.checkNotNull(server, "Mongo DB Server address is null");
        Preconditions.checkNotNull(version, "Mongo DB version is null");

        return Health.up().withDetail("database", "mongodb").withDetail("server", server)
                .withDetail("version", version).build();
    } catch (Exception ex) {
        return Health.down(ex).build();
    }
}