Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose StompSubProtocolWebSocketHandler metrics #22807

Closed
krm1312 opened this issue Apr 16, 2019 · 1 comment
Closed

Expose StompSubProtocolWebSocketHandler metrics #22807

krm1312 opened this issue Apr 16, 2019 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@krm1312
Copy link

krm1312 commented Apr 16, 2019

Currently WebSocketMessageBrokerStats hides the actual metrics behind nested toString()s. This makes it difficult to expose these metrics (for example with micrometer) without resorting to brittle access to private fields.

ie:

    @PostConstruct
    public void init() {
        webSocketMessageBrokerStats.setLoggingPeriod(statsIntervalMs);

        // https://github.com/spring-projects/spring-framework/issues/22807
        Object handler = new DirectFieldAccessor(webSocketMessageBrokerStats).getPropertyValue("webSocketHandler");
        Object stats = new DirectFieldAccessor(handler).getPropertyValue("stats");
        DirectFieldAccessor statsAccessor = new DirectFieldAccessor(stats);
        Gauge.builder("sockjs.connection", () ->
            ((AtomicInteger)statsAccessor.getPropertyValue("webSocket")).get()).tags("protocol", "WS")
            .register(meterRegistry);
        Gauge.builder("sockjs.connection", () ->
            ((AtomicInteger)statsAccessor.getPropertyValue("httpStreaming")).get()).tags("protocol", "HttpStream")
            .register(meterRegistry);
        Gauge.builder("sockjs.connection", () ->
            ((AtomicInteger)statsAccessor.getPropertyValue("httpPolling")).get()).tags("protocol", "HttpPoll")
            .register(meterRegistry);
    }```
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 16, 2019
@rstoyanchev
Copy link
Contributor

Yes we could expose the Stats object from SubProtocolWebSocketHandler.

You can get the SubProtocolWebSocketHandler directly from the ApplicationContext. It's declared in WebSocketMessageBrokerConfigurationSupport as a bean named "subProtocolWebSocketHandler".

@rstoyanchev rstoyanchev added this to the 5.2 M2 milestone Apr 17, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 17, 2019
@rstoyanchev rstoyanchev self-assigned this Apr 19, 2019
@rstoyanchev rstoyanchev changed the title Expose WebSocketMessageBrokerStats metrics Expose StompSubProtocolWebSocketHandler metrics Apr 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants