首先,我是 Spring Boot 框架的新手。我已经在执行器上工作了几天,并且能够设置端点来监视系统。然而,当我为了安全性而集成 JWT 时,我的所有执行器端点都坏了。
如何禁用位于 Spring Boot 安全之上的执行器端点的 JWT 安全?以下是我的 application.yml 文件属性。
management:
endpoint:
metrics:
enabled: true
endpoints:
web:
exposure:
include: health, metrics
Run Code Online (Sandbox Code Playgroud) 我有一个可以延伸的过滤器OncePerRequestFilter。当我management.port=8081和server.port=8080(或任何不同的端口)时,我的过滤器不会在任何 8081 URL 上调用。
仅在 8080 URL 上调用该过滤器。
如何让它在所有 URL 上调用,包括 8081 上的 URL?
筛选:
@Order( Ordered.LOWEST_PRECEDENCE )
public class TestFilter extends OncePerRequestFilter
{
public TestFilter()
{
System.out.println( "Started" );
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException
{
System.out.println( "Checked should not filter" );
return false;
}
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException
{
System.out.println( "Filtering" );
// continue the processing
filterChain.doFilter( request, response );
} …Run Code Online (Sandbox Code Playgroud) java spring servlet-filters spring-boot spring-boot-actuator
这里是 Spring Boot RESTful Web 服务和 Swagger 2。我有以下@Configuration类设置来为我的服务配置 Swagger:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
我启动我的服务,然后转到http://localhost:8080/v2/api-docs(Swagger 的服务来源),然后将该 JSON 粘贴到jsonlint.com,我看到 Spring Boot 自动添加大约 40 个端点,我不希望Swagger 记录这些端点。像/trace端点、 and /health、/envand/beans等东西。这些都是 Spring Boot Actuator 创建的东西,但我不想将其包含在我的公共 API 文档中。
有没有办法将 Swagger 配置为不记录这些框架级端点?
我正在运行 Spring Boot 2 应用程序并添加了执行器 spring boot starter 依赖项。我启用了所有 Web 端点,然后调用:
http://localhost:8080/actuator/metrics
结果是:
{
"names": ["jdbc.connections.active",
"jdbc.connections.max",
"jdbc.connections.min",
"hikaricp.connections.idle",
"hikaricp.connections.pending",
"hikaricp.connections",
"hikaricp.connections.active",
"hikaricp.connections.creation",
"hikaricp.connections.max",
"hikaricp.connections.min",
"hikaricp.connections.usage",
"hikaricp.connections.timeout",
"hikaricp.connections.acquire"]
}
Run Code Online (Sandbox Code Playgroud)
但我缺少所有 JVM 统计信息和其他内置指标。我在这里缺少什么?我读到的所有内容都表明这些指标应该随时可用。
感谢您的任何提示。
java spring-boot spring-boot-actuator micrometer spring-micrometer
只是想从 SpringBoot 2.3.1 执行器指标端点获得有关 system.cpu.count 指标和 system.cpu.usage 指标之间关系的一些说明。
例如,就我而言:
/actuator/metrics/system.cpu.count 的值为:2
/actuator/metrics/system.cpu.usage 的值为:0.024765603908878
这是否意味着我的CPU利用率是:0.024765603908878 / 2 * 100 = 1.24% ?
有关使用 Spring Boot Actuator 进行服务发现的问题,请结合 Spring Cloud Kubernetes。
目前,我有一个 Web 应用程序,它同时具有执行器和 Spring Boot kubernetes 依赖项。我也在使用 kubernetes 提供的发现客户端,一切正常。
然而,当我卷曲我的健康终点时,我确实看到了那些奇怪的陈述:
discoveryComposite":{"description":"Discovery Client not initialized","status":"UNKNOWN","components":{"discoveryClient":{"description":"Discovery Client not initialized","status":"UNKNOWN"}}
"reactiveDiscoveryClients":{"description":"Discovery Client not initialized","status":"UNKNOWN","components":{"Kubernetes Reactive Discovery Client":{"description":"Discovery Client not initialized","status":"UNKNOWN"}
Simple Reactive Discovery Client":{"description":"Discovery Client not initialized","status":"UNKNOWN"}}}
"readinessState":{"status":"UP"},"refreshScope":{"status":"UP"}},"groups":["liveness","readiness"]}*
Run Code Online (Sandbox Code Playgroud)
请问为什么是“未知”?我预计这里的三个中至少有一个会出现问题,并且绝对不是“发现客户端未初始化”。
我是否忘记初始化某些东西?注册一些东西?配置一些东西?
顺便说一句,这确实是一个关于 kubernetes 发现的问题。与Eureka无关,与Consul等无关。
非常感谢
我发现 Spring Cloud Bus在version上不支持对/actuator/bus-refresh 的POST 请求。当我尝试发送它时,我收到 405“方法不允许”。有没有办法在不使用/monitor和 git webhooks 或降级 Spring Cloud 版本的情况下自动刷新所有客户端服务的配置?Spring Cloud2020.0.0
我已经包含了spring-cloud-starter-bus-amqp依赖spring-boot-starter-actuator项,bus-refresh端点已公开。RabbitMQ 已启动并正在运行,在我的服务启动时创建了 springCloudBus 主题并添加了队列。当我向/actuator/bus-refresh发出 GET 请求时,它会将属性源获取到我的配置服务器,但我的客户端服务属性文件不会刷新,消息也不会添加到队列中。
spring-cloud spring-boot-actuator spring-cloud-config spring-cloud-bus
我已经创建了一个像这样的PostgreSQL运行状况指示器:
@Component
public class PostgresHealthIndicator extends AbstractHealthIndicator {
@Autowired
DataSource postgresDataSource;
public DataSourceHealthIndicator dbHealthIndicator() {
DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(postgresDataSource);
return indicator;
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Health h = dbHealthIndicator().health();
Status status = h.getStatus();
if (status != null && "DOWN".equals(status.getCode())) {
builder.down();
} else {
builder.up();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的Application.java中,我正在为此组件扫描此包:
@ComponentScan({"com.bp.health"})
Run Code Online (Sandbox Code Playgroud)
在我的application.properties中,我有以下设置:
endpoints.health.sensitive=false
endpoints.health.id=health
endpoints.health.enabled=true
Run Code Online (Sandbox Code Playgroud)
当我点击{url}/health时,我看到:
{ "地位": "DOWN"}
我需要做什么才能显示自定义健康指标?
我正在寻找重启弹簧启动应用程序,所以使用Spring Actuator/restart端点正在使用curl,但我想在应用程序内部使用java代码调用相同的函数,我已经尝试过这段代码了,但它是不工作:
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
RestartEndpoint p = new RestartEndpoint();
p.invoke();
}
});
thread.setDaemon(false);
thread.start();
Run Code Online (Sandbox Code Playgroud) 我最近在1.4到1.5.1的应用程序中更新了Spring Boot的版本,我注意到在部署到AWS上的Elastic Beanstalk后,healtch检查开始失败.
在我们的AWS环境中,所有通信都通过HTTPS进行,包括运行状况,并且它曾经与Spring Boot和Actuator 1.4一起正常工作,但我们开始在第1.5节中的执行器运行状况端点上获得401.
有没有人有同样的问题?不确定此版本中有关此主题的更改,但我没有通过阅读发行说明找到任何解决方案.很高兴得到任何帮助.
java spring-boot amazon-elastic-beanstalk spring-boot-actuator
spring-boot ×8
java ×6
spring ×3
micrometer ×2
spring-cloud ×2
actuator ×1
jwt ×1
swagger-2.0 ×1