Search code examples
javaspringspring-bootspring-boot-admin

Spring Boot Admin - Persist applications and events


I have a problem with Spring Boot Admin: after restarting the server instance, it loses all applications and events.

This is the schema and steps: server instance that monitor application A, B and C.

  1. Start server instance
  2. Start app A, B and C
  3. Stop app C and server instance
  4. Restart server instance
  5. At this point the event journal is cleared and the application C in not in the application list

How can I manage this situation? Maybe, I have to persist these information on db. But, I can't find anything useful.

Thanks


Solution

  • You can use Hazelcast for make apps and events persistent. Take a look at SBA documentation (clustering paragraph).

    Add Hazelcast dependency in pom.xml:

    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast</artifactId>
    </dependency>
    

    Then, in application.properties:

    spring.boot.admin.hazelcast.enabled=true
    spring.boot.admin.hazelcast.event-store=spring-boot-admin-event-store
    

    Instantiate a HazelcastConfig

        @Bean
    public Config config() {
        MapConfig eventStoreMap = new MapConfig("spring-boot-admin-event-store")
                .setInMemoryFormat(InMemoryFormat.OBJECT)
                .setBackupCount(1)
                .setEvictionPolicy(EvictionPolicy.NONE)
                .setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100))
                .setMapStoreConfig(new MapStoreConfig().setImplementation(new HazelcastEventImplementation()));
    
        Config config = new Config();
        config.addMapConfig(eventStoreMap);
        config.setProperty("hazelcast.jmx", "true");
    
        return config;
    }
    

    Finally, implement a MapStore< InstanceId, ArrayList > class with your preferred persistence method (in my example configuration HazelcastEventImplementation.java).