服务实例数:10个,期望每分钟续约数:10 * 2=20,期望阈值:20*0.85=17,自我保护少于17时 触发。

剔除:

AbstractInstanceRegistry

public void evict(long additionalLeaseMs) {

logger.debug(“Running the evict task”);

if (!isLeaseExpirationEnabled()) {

logger.debug(“DS: lease expiration is currently disabled.”);

return;

}

此代码意思:if中判断为true,不走此逻辑,走下面的剔除。如果if为false。走此逻辑,不剔除。

PeerAwareInstanceRegistryImpl

@Override

public boolean isLeaseExpirationEnabled() {

if (!isSelfPreservationModeEnabled()) {

//如果打开自我保护,不进入此逻辑。

// The self preservation mode is disabled, hence allowing the instances to expire.

return true;

}

return numberOfRenewsPerMinThreshold > 0 && getNumOfRenewsInLastMin() > numberOfRenewsPerMinThreshold;

}

关闭


eureka.server.enable-self-preservation=false

关闭后会提示

清理时间

默认60秒

eureka.server.eviction-interval-timer-in-ms=3000

使用Spring Boot2.x Actuator监控应用

=============================

开启监控

org.springframework.boot

spring-boot-starter-actuator

实现:


在服务提供方的provider中,加入上面的依赖

![](https://img-blog.csdnimg.cn/20 《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 210321200835418.png)

访问端点信息:


[http://localhost:8088//actuator](()

{

“_links”: {

“self”: {

“href”: “http://localhost:8080//actuator”,

“templated”: false

},

“health”: {

“href”: “http://localhost:8080//actuator/health”,

“templated”: false

},

“health-path”: {

“href”: “http://localhost:8080//actuator/health/{*path}”,

“templated”: true

},

“info”: {

“href”: “http://localhost:8080//actuator/info”,

“templated”: false

}

}

}

[ttp://localhost:8088//actuator/health](()

{

“status”: “UP”

}

默认端点

Spring Boot 2.0 的Actuator只暴露了health和info端点,提供的监控信息无法满足我们的需求

在1.x中有n多可供我们监控的节点,官方的回答是为了安全….

如果想开启所有的端点信息:

management.endpoints.web.exposure.include=*

再次访问:[http://localhost:8088//actuator](()

{

“_links”: {

“self”: {

“href”: “http://localhost:8088//actuator”,

“templated”: false

},

“archaius”: {

“href”: “http://localhost:8088//actuator/archaius”,

“templated”: false

},

“beans”: {

“href”: “http://localhost:8088//actuator/beans”,

“templated”: false

},

“caches”: {

“href”: “http://localhost:8088//actuator/caches”,

“templated”: false

},

“caches-cache”: {

“href”: “http://localhost:8088//actuator/caches/{cache}”,

“templated”: true

},

“health-path”: {

“href”: “http://localhost:8088//actuator/health/{*path}”,

“templated”: true

},

“health”: {

“href”: “http://localhost:8088//actuator/health”,

“templated”: false

},

“info”: {

“href”: “http://localhost:8088//actuator/info”,

“templated”: false

},

“conditions”: {

“href”: “http://localhost:8088//actuator/conditions”,

“templated”: false

},

“configprops”: {

“href”: “http://localhost:8088//actuator/configprops”,

“templated”: false

},

“env-toMatch”: {

“href”: “http://localhost:8088//actuator/env/{toMatch}”,

“templated”: true

},

“env”: {

“href”: “http://localhost:8088//actuator/env”,

“templated”: false

},

“loggers-name”: {

“href”: “http://localhost:8088//actuator/loggers/{name}”,

“templated”: true

},

“loggers”: {

“href”: “http://localhost:8088//actuator/loggers”,

“templated”: false

},

“heapdump”: {

“href”: “http://localhost:8088//actuator/heapdump”,

“templated”: false

},

“threaddump”: {

“href”: “http://localhost:8088//actuator/threaddump”,

“templated”: false

},

“metrics”: {

“href”: “http://localhost:8088//actuator/metrics”,

“templated”: false

},

“metrics-requiredMetricName”: {

“href”: “http://localhost:8088//actuator/metrics/{requiredMetricName}”,

“templated”: true

},

“scheduledtasks”: {

“href”: “http://localhost:8088//actuator/scheduledtasks”,

“templated”: false

},

“mappings”: {

“href”: “http://localhost:8088//actuator/mappings”,

“templated”: false

},

“refresh”: {

“href”: “http://localhost:8088//actuator/refresh”,

“templated”: false

},

“features”: {

“href”: “http://localhost:8088//actuator/features”,

“templated”: false

},

“service-registry”: {

“href”: “http://localhost:8088//actuator/service-registry”,

“templated”: false

}

}

}

api端点功能


Health

会显示系统状态

{“status”:“UP”}

shutdown

用来关闭节点

开启远程关闭功能


版权声明:本文为AK774S原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/AK774S/article/details/124472439