简体   繁体   中英

How to measure complete response time (request in to response received by client ) in Play! framework?

I'm a new user of playframework. In a project of mine, I want to measure how long it takes from when a HTTP request comes in until the last byte of the response has been received by the client. I'm calling this period of time "response time". In a netty log, I can see:

2016-11-17 10:32:00,712 [DEBUG] from io.netty.handler.logging.LoggingHandler in netty-event-loop-3 - [id: 0xb4fb943a, L:/127.0.0.1:9001 - R:/127.0.0.1:50871] WRITE: DefaultFullHttpResponse(decodeResult: success, version: HTTP/1.1, content: ReadOnlyByteBufferBuf(ridx: 0, widx: 655, cap: 655/655))

2016-11-17 10:32:00,713 [DEBUG] from io.netty.handler.logging.LoggingHandler in netty-event-loop-3 - [id: 0xb4fb943a, L:/127.0.0.1:9001 - R:/127.0.0.1:50871] FLUSH

2016-11-17 10:32:00,713 [DEBUG] from io.netty.handler.logging.LoggingHandler in netty-event-loop-3 - [id: 0xb4fb943a, L:/127.0.0.1:9001 - R:/127.0.0.1:50871] FLUSH

2016-11-17 10:37:19,311 [DEBUG] from io.netty.handler.logging.LoggingHandler in netty-event-loop-3 - [id: 0xb4fb943a, L:/127.0.0.1:9001 ! R:/127.0.0.1:50871] INACTIVE

2016-11-17 10:37:19,312 [DEBUG] from io.netty.handler.logging.LoggingHandler in netty-event-loop-3 - [id: 0xb4fb943a, L:/127.0.0.1:9001 ! R:/127.0.0.1:50871] UNREGISTERED

I can get the response time from the log (from WRITE to FLUSH?), but is there any way to get the "response time" more easily? What I need is to measure the "response time" as a metric and log it or send it to Grafana.

Thanks everyone!

You can either:

  • use a library that will collect the metrics from the framework and push them to a metric backend. Kamon is a nice library with a play integration
  • write your own code to record the metric. For this you will need to look into play filters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM