简体   繁体   English

如何在 reactor.netty 服务器的 Spring Webflux 中监控仪表

[英]How to monitor meters in Spring Webflux for a reactor-netty server

I am new to Spring Boot and Spring Webflux.我是 Spring Boot 和 Spring Webflux 的新手。 I am working on a Spring Webflux reactor.netty server to handle WebSocket connections.我正在使用 Spring Webflux reactor.netty 服务器来处理 WebSocket 连接。 In the simplest sense, this is how the server looks like:在最简单的意义上,这就是服务器的样子:

...
@Component
public class ServerWebSocketHandler implements WebSocketHandler {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public Mono<Void> handle(WebSocketSession session) {
        String sessionId = session.getId();
        Sinks.Many<String> unicastSink = Sinks.many().unicast().onBackpressureError();
        // save the unicastSink in cache so that on demand messages can be sent to the sink
        Mono<Void> receiver =
                session
                    .receive()
                    .map(WebSocketMessage::getPayloadAsText)
                    .doOnNext(message -> this.handleIncomingMessage(sessionId, message))
                    .doOnError(error -> {
                        logger.info("Error occurred in the session - Session: '{}'; Error: '{}'", sessionId, error);
                    })
                    .doFinally(s -> {
                        this.cleanUp(sessionId, s);
                    })
                    .then();

        Mono<Void> sender =
                session
                    .send(unicastSink.asFlux().map(session::textMessage));

        return Mono.zip(receiver, sender).then();
    }
    // handleIncomingMessage, cleanUp, and other private methods to handle business logic
}

Now, I want to monitor the meters, specifically meters that can help in identifying back pressure or memory leak like reactor.netty.eventloop.pending.tasks , reactor.netty.bytebuf.allocator.used.direct.memory , reactor.netty.bytebuf.allocator.used.heap.memory .现在,我想监控仪表,特别是可以帮助识别背压或 memory 泄漏的仪表,如reactor.netty.eventloop.pending.tasksreactor.netty.bytebuf.allocator.used.direct.memory 、reactor.netty reactor.netty.bytebuf.allocator.used.heap.memory I read about these meters in Reactor Netty Reference Guide https://projectreactor.io/docs.netty/1.1.0-SNAPSHOT/reference/index.html#_metrics .我在 Reactor Netty 参考指南https://projectreactor.io/docs.netty/1.1.0-SNAPSHOT/reference/index.html#_metrics中读到了这些仪表。 The example of how to enable it is done on the server creation, but in Webflux, all these are abstracted out.如何启用它的示例是在服务器创建时完成的,但在 Webflux 中,所有这些都被抽象出来了。 So, my question is, in this case, how can I enable monitoring the meters and how to consume the meter.所以,我的问题是,在这种情况下,我如何启用对仪表的监控以及如何使用仪表。 A small example code which shows how to do it would be greatly useful.显示如何执行此操作的小示例代码将非常有用。

You can use Spring Boot API for configuring the web server https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.webserver.configure您可以使用 Spring Boot API 配置 web 服务器https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.webserver.configure

@Component
public class MyNettyWebServerCustomizer
        implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
    @Override
    public void customize(NettyReactiveWebServerFactory factory) {
        factory.addServerCustomizers(httpServer -> httpServer.metrics(...));
    }
}

These built-in Reactor Netty metrics use Micrometer so you can consume them with everything that has integration with Micrometer.这些内置的 Reactor Netty 指标使用 Micrometer,因此您可以将它们与与 Micrometer 集成的所有内容一起使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何处理 reactor-netty 在 spring-webflux 中终止请求? - How to handle reactor-netty terminating a request in spring-webflux? 当服务器提前响应时,Spring WebClient / Reactor-netty 坏了? - Spring WebClient / Reactor-netty broken when a server responds early? 使用 spring HATEOAS 和 spring webflux 功能 Web 框架 (reactor.netty) - Using spring HATEOAS with spring webflux Functional Web Framework (reactor-netty) Reactor Netty 中的线性化(Spring Boot Webflux) - Linearization in Reactor Netty (Spring Boot Webflux) Spring Webflux Reactor Netty:HTTP请求/响应十六进制转储? - Spring Webflux Reactor Netty: HTTP Request/Response Hex Dump? 为spring-webflux WebClient配置具有reactor netty的HostnameVerifier - Configure HostnameVerifier with reactor netty for spring-webflux WebClient 人们如何在生产中的 Reactor Netty 上使用 WebFlux 托管 Spring Boot 应用程序? - How do people host Spring Boot apps with WebFlux on Reactor Netty in production? 如何在 Spring Webflux / Reactor Netty Web 应用程序中执行阻塞调用 - How to execute blocking calls within a Spring Webflux / Reactor Netty web application 在 reactor.netty WebSocketSession 中发送更多数据之前如何确保前面的 session.send() 完成 - How to make sure the previous session.send() is complete before sending more data in reactor-netty WebSocketSession 无法在 reactor-netty 版本 0.9.10 上设置 WriteTimeout - Unable to set WriteTimeout on reactor-netty version 0.9.10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM