springCloud学习三之Eureka健康检查

自我保护机制的触发条件: (当每分钟心跳次数( renewsLastMin ) 小于 numberOfRenewsPerMinThreshold 时,并且开启自动保护模式开关( eureka.server.enable-self-preservation = true ) 时,触发自我保护机制,不再自动过期租约。) numberOfRenewsPerMinThreshold = expectedNumberOfRenewsPerMin * 续租百分比( eureka.server.renewalPercentThreshold, 默认0.85 ) expectedNumberOfRenewsPerMin = 当前注册的应用实例数 x 2

为什么乘以 2:

默认情况下,注册的应用实例每半分钟续租一次,那么一分钟心跳两次,因此 x 2 。

服务实例数: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中,加入上面的依赖

访问端点信息:


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”}

最后

文章中涉及到的知识点我都已经整理成了资料,录制了视频供大家下载学习,诚意满满,希望可以帮助在这个行业发展的朋友,在论坛博客等地方少花些时间找资料,把有限的时间,真正花在学习上,所以我把这些资料,分享出来。相信对于已经工作和遇到技术瓶颈的朋友们,在这份资料中一定都有你需要的内容。

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 27
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Cloud Eureka是一个用于服务注册和发现的组件,它简化了在微服务架构中的服务管理和通信。 首先,Spring Cloud Eureka由两个核心角色组成:Eureka Server和Eureka Client。 Eureka Server主要负责服务注册和发现。它是一个集中式的服务注册中心,负责管理所有服务的状态和元数据。每个服务在启动时会向Eureka Server注册自己的实例信息,包括服务名称、IP地址和端口等,Eureka Server会维护一个服务注册表来跟踪所有已注册的服务。 Eureka Client则是各个微服务应用程序的客户端。它在服务启动时会向Eureka Server注册自己,并定期发送心跳来更新自己的状态。同时,它也会从Eureka Server获取其他服务的注册信息,并将其缓存在本地。这样,当需要使用其他服务时,Eureka Client可以直接从缓存中获取服务的访问地址,而不需要向注册中心发送请求。 此外,Eureka Server和Eureka Client之间也会进行心跳和故障检测。Eureka Client会定时发送心跳给Eureka Server,以通知自己的状态仍然健康;而Eureka Server则会周期性地检查各个服务的心跳,并从注册表中删除超时没有心跳的服务。 总的来说,Spring Cloud Eureka通过Eureka Server作为中心化的服务注册中心,实现了微服务的注册和发现。它可以根据客户端的需求,动态地维护服务的可用性和负载均衡。这样,微服务架构中的各个服务可以方便地相互调用,并实现高可用的分布式系统。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值