通过eureka中心获取所注册的服务的状态

@RestController
@RequestMapping("/getservices")
public class ServiceController {

    @Autowired
    private DiscoveryClient discoveryClient;


    @GetMapping("/getServicesList")
    public Object getServicesList() {
        List<List<ServiceInstance>> servicesList = new ArrayList<>();

        //获取服务名称
        List<String> serviceNames = discoveryClient.getServices();
        for (String serviceName : serviceNames) {
            //获取服务中的实例列表
            List<ServiceInstance> serviceInstances = discoveryClient.getInstances(serviceName);

            servicesList.add(serviceInstances);

        }

        JSONArray jsonArray = new JSONArray(Collections.singletonList(servicesList));

        System.out.println("------>"+jsonArray.toString());

        return servicesList;
    }

[

    [

        {

            "host": "192.168.3.55",

            "port": 8723,

            "metadata": {},

            "uri": "http://192.168.3.55:8723",

            "serviceId": "BASICDATA",

            "secure": false,

            "instanceInfo": {

                "instanceId": "192.168.3.55:8723",

                "app": "BASICDATA",

                "appGroupName": null,

                "ipAddr": "192.168.3.55",

                "sid": "na",

                "homePageUrl": "http://192.168.3.55:8723/",

                "statusPageUrl": "http://192.168.3.55:8723/info",

                "healthCheckUrl": "http://192.168.3.55:8723/health",

                "secureHealthCheckUrl": null,

                "vipAddress": "basicData",

                "secureVipAddress": "basicData",

                "countryId": 1,

                "dataCenterInfo": {

                    "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",

                    "name": "MyOwn"

                },

                "hostName": "192.168.3.55",

                "status": "UP",

                "leaseInfo": {

                    "renewalIntervalInSecs": 30,

                    "durationInSecs": 90,

                    "registrationTimestamp": 1627259738736,

                    "lastRenewalTimestamp": 1627302433437,

                    "evictionTimestamp": 0,

                    "serviceUpTimestamp": 1627259738736

                },

                "isCoordinatingDiscoveryServer": false,

                "metadata": {},

                "lastUpdatedTimestamp": 1627259738736,

                "lastDirtyTimestamp": 1627259738676,

                "actionType": "ADDED",

                "asgName": null,

                "overriddenStatus": "UNKNOWN"

            }

        }

    ],

    [

        {

            "host": "192.168.3.55",

            "port": 9090,

            "metadata": {},

            "uri": "http://192.168.3.55:9090",

            "serviceId": "SYSTEMLOG",

            "secure": false,

            "instanceInfo": {

                "instanceId": "192.168.3.55:9090",

                "app": "SYSTEMLOG",

                "appGroupName": null,

                "ipAddr": "192.168.3.55",

                "sid": "na",

                "homePageUrl": "http://192.168.3.55:9090/",

                "statusPageUrl": "http://192.168.3.55:9090/info",

                "healthCheckUrl": "http://192.168.3.55:9090/health",

                "secureHealthCheckUrl": null,

                "vipAddress": "systemLog",

                "secureVipAddress": "systemLog",

                "countryId": 1,

                "dataCenterInfo": {

                    "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",

                    "name": "MyOwn"

                },

                "hostName": "192.168.3.55",

                "status": "UP",

                "leaseInfo": {

                    "renewalIntervalInSecs": 30,

                    "durationInSecs": 90,

                    "registrationTimestamp": 1627259832596,

                    "lastRenewalTimestamp": 1627302437525,

                    "evictionTimestamp": 0,

                    "serviceUpTimestamp": 1627259832596

                },

                "isCoordinatingDiscoveryServer": false,

                "metadata": {},

                "lastUpdatedTimestamp": 1627259832596,

                "lastDirtyTimestamp": 1627259832563,

                "actionType": "ADDED",

                "asgName": null,

                "overriddenStatus": "UNKNOWN"

            }

        }

    ],

    [

        {

            "host": "192.168.3.55",

            "port": 9696,

            "metadata": {},

            "uri": "http://192.168.3.55:9696",

            "serviceId": "POLICEMESSAGE",

            "secure": false,

            "instanceInfo": {

                "instanceId": "192.168.3.55:9696",

                "app": "POLICEMESSAGE",

                "appGroupName": null,

                "ipAddr": "192.168.3.55",

                "sid": "na",

                "homePageUrl": "http://192.168.3.55:9696/",

                "statusPageUrl": "http://192.168.3.55:9696/info",

                "healthCheckUrl": "http://192.168.3.55:9696/health",

                "secureHealthCheckUrl": null,

                "vipAddress": "policeMessage",

                "secureVipAddress": "policeMessage",

                "countryId": 1,

                "dataCenterInfo": {

                    "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",

                    "name": "MyOwn"

                },

                "hostName": "192.168.3.55",

                "status": "UP",

                "leaseInfo": {

                    "renewalIntervalInSecs": 30,

                    "durationInSecs": 90,

                    "registrationTimestamp": 1627259815714,

                    "lastRenewalTimestamp": 1627302422239,

                    "evictionTimestamp": 0,

                    "serviceUpTimestamp": 1627259815714

                },

                "isCoordinatingDiscoveryServer": false,

                "metadata": {},

                "lastUpdatedTimestamp": 1627259815714,

                "lastDirtyTimestamp": 1627259815680,

                "actionType": "ADDED",

                "asgName": null,

                "overriddenStatus": "UNKNOWN"

            }

        }

    ],

    [

        {

            "host": "192.168.3.55",

            "port": 8082,

            "metadata": {},

            "uri": "http://192.168.3.55:8082",

            "serviceId": "WEBPRO",

            "secure": false,

            "instanceInfo": {

                "instanceId": "192.168.3.55:8082",

                "app": "WEBPRO",

                "appGroupName": null,

                "ipAddr": "192.168.3.55",

                "sid": "na",

                "homePageUrl": "http://192.168.3.55:8082/",

                "statusPageUrl": "http://192.168.3.55:8082/info",

                "healthCheckUrl": "http://192.168.3.55:8082/health",

                "secureHealthCheckUrl": null,

                "vipAddress": "WebPro",

                "secureVipAddress": "WebPro",

                "countryId": 1,

                "dataCenterInfo": {

                    "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",

                    "name": "MyOwn"

                },

                "hostName": "192.168.3.55",

                "status": "UP",

                "leaseInfo": {

                    "renewalIntervalInSecs": 30,

                    "durationInSecs": 90,

                    "registrationTimestamp": 1627302346148,

                    "lastRenewalTimestamp": 1627302346148,

                    "evictionTimestamp": 0,

                    "serviceUpTimestamp": 1627286514113

                },

                "isCoordinatingDiscoveryServer": false,

                "metadata": {},

                "lastUpdatedTimestamp": 1627302346148,

                "lastDirtyTimestamp": 1627302346113,

                "actionType": "ADDED",

                "asgName": null,

                "overriddenStatus": "UNKNOWN"

            }

        }

    ],

    [

        {

            "host": "192.168.3.55",

            "port": 9595,

            "metadata": {},

            "uri": "http://192.168.3.55:9595",

            "serviceId": "DICTIONARY",

            "secure": false,

            "instanceInfo": {

                "instanceId": "192.168.3.55:9595",

                "app": "DICTIONARY",

                "appGroupName": null,

                "ipAddr": "192.168.3.55",

                "sid": "na",

                "homePageUrl": "http://192.168.3.55:9595/",

                "statusPageUrl": "http://192.168.3.55:9595/info",

                "healthCheckUrl": "http://192.168.3.55:9595/health",

                "secureHealthCheckUrl": null,

                "vipAddress": "dictionary",

                "secureVipAddress": "dictionary",

                "countryId": 1,

                "dataCenterInfo": {

                    "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",

                    "name": "MyOwn"

                },

                "hostName": "192.168.3.55",

                "status": "UP",

                "leaseInfo": {

                    "renewalIntervalInSecs": 30,

                    "durationInSecs": 90,

                    "registrationTimestamp": 1627259782642,

                    "lastRenewalTimestamp": 1627302447755,

                    "evictionTimestamp": 0,

                    "serviceUpTimestamp": 1627259782642

                },

                "isCoordinatingDiscoveryServer": false,

                "metadata": {},

                "lastUpdatedTimestamp": 1627259782642,

                "lastDirtyTimestamp": 1627259782610,

                "actionType": "ADDED",

                "asgName": null,

                "overriddenStatus": "UNKNOWN"

            }

        }

    ],

    [

        {

            "host": "192.168.3.55",

            "port": 8726,

            "metadata": {},

            "uri": "http://192.168.3.55:8726",

            "serviceId": "COMMUNICATION",

            "secure": false,

            "instanceInfo": {

                "instanceId": "192.168.3.55:8726",

                "app": "COMMUNICATION",

                "appGroupName": null,

                "ipAddr": "192.168.3.55",

                "sid": "na",

                "homePageUrl": "http://192.168.3.55:8726/",

                "statusPageUrl": "http://192.168.3.55:8726/info",

                "healthCheckUrl": "http://192.168.3.55:8726/health",

                "secureHealthCheckUrl": null,

                "vipAddress": "communication",

                "secureVipAddress": "communication",

                "countryId": 1,

                "dataCenterInfo": {

                    "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",

                    "name": "MyOwn"

                },

                "hostName": "192.168.3.55",

                "status": "UP",

                "leaseInfo": {

                    "renewalIntervalInSecs": 30,

                    "durationInSecs": 90,

                    "registrationTimestamp": 1627259764225,

                    "lastRenewalTimestamp": 1627302428936,

                    "evictionTimestamp": 0,

                    "serviceUpTimestamp": 1627259764225

                },

                "isCoordinatingDiscoveryServer": false,

                "metadata": {},

                "lastUpdatedTimestamp": 1627259764225,

                "lastDirtyTimestamp": 1627259764193,

                "actionType": "ADDED",

                "asgName": null,

                "overriddenStatus": "UNKNOWN"

            }

        }

    ],

    [

        {

            "host": "192.168.3.55",

            "port": 8823,

            "metadata": {},

            "uri": "http://192.168.3.55:8823",

            "serviceId": "NETTYCOMMUNICATION",

            "secure": false,

            "instanceInfo": {

                "instanceId": "192.168.3.55:8823",

                "app": "NETTYCOMMUNICATION",

                "appGroupName": null,

                "ipAddr": "192.168.3.17",

                "sid": "na",

                "homePageUrl": "http://192.168.3.55:8823/",

                "statusPageUrl": "http://192.168.3.55:8823/info",

                "healthCheckUrl": "http://192.168.3.55:8823/health",

                "secureHealthCheckUrl": null,

                "vipAddress": "nettycommunication",

                "secureVipAddress": "nettycommunication",

                "countryId": 1,

                "dataCenterInfo": {

                    "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",

                    "name": "MyOwn"

                },

                "hostName": "192.168.3.55",

                "status": "UP",

                "leaseInfo": {

                    "renewalIntervalInSecs": 30,

                    "durationInSecs": 90,

                    "registrationTimestamp": 1627298054656,

                    "lastRenewalTimestamp": 1627302448684,

                    "evictionTimestamp": 0,

                    "serviceUpTimestamp": 1627287836443

                },

                "isCoordinatingDiscoveryServer": false,

                "metadata": {},

                "lastUpdatedTimestamp": 1627298054656,

                "lastDirtyTimestamp": 1627298055183,

                "actionType": "ADDED",

                "asgName": null,

                "overriddenStatus": "UNKNOWN"

            }

        }

    ]

]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值