Search code examples
javaspring-bootnetflix-eureka

Eureka Server - list all registered instances


I have a Spring Boot application that is also a Eureka Server. I want to list all instances that have been registered to this Eureka Server. How do I do it?


Solution

  • Fetch the registry using EurekaServerContextHolder.getInstance().getServerContext().getRegistry() then use the registry to list all Applications

    PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry();
        Applications applications = registry.getApplications();
    
        applications.getRegisteredApplications().forEach((registeredApplication) -> {
            registeredApplication.getInstances().forEach((instance) -> {
                System.out.println(instance.getAppName() + " (" + instance.getInstanceId() + ") ");
            });
        });