0
我正在追踪API调用的响应时间。 然后,我想绘制一个图形上的调用响应时间(GET,PUT,POST DELETE),然后比较时间差异。在springboot中跟踪API调用的响应时间
这是我目前正在做的,以找到GET调用的响应时间,但我不太确定它是否正确。
@RequestMapping(value="/Students", method = RequestMethod.GET)
public ResponseEntity<List<Students>> getStudents()
{
long beginTime = System.currentTimeMillis();
List<Students> students = (List<Students>) repository.findAll();
if(students.isEmpty())
{
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
long responseTime = System.currentTimeMillis() - beginTime;
logger.info("Response time for the call was "+responseTime);
return new ResponseEntity(students, HttpStatus.OK);
}
我相信我返回响应时间之前,我的数据实际上返回给客户端这是这整点,但我不能够把它return语句后,因为这将是无法访问码。
有没有更好的方法来追踪通话时间?
[如何记录Spring Boot中Rest服务所花的时间?](https://stackoverflow.com/questions/42857658/how-to-log-time-taken-by-rest-web-弹簧服务启动) – Vasan
使用Spring Boot Actuator,它将记录指标。你可以流到Grafana之类的东西(其他选项当然可用)。 –
嗨@ M.Deinum,谢谢你的回复。从春季出口指标的最佳方法是什么,以便我可以在grafana上将其可视化?我无法将其导出到influxdb中,我不确定这是否是最好的方法,或者是 – mvantastic