如何测量API调用的响应时间?

如何测量API调用的响应时间?

问题描述:

我已经在Spring Boot中实现了一个可以成功完成所有RESTful调用的API。如何测量API调用的响应时间?

作为作业的额外信用部分,我需要跟踪对RESTful服务的所有调用的响应时间,并且能够将线图上的数据可视化。

他们建议使用我已经下载的grafana。

我只是不知道如何,我将能够跟踪每个呼叫

响应时间的响应时间,可以很容易地使用Chrome调试器进行跟踪。 enter image description here

如果你想计算的响应时间编程那么它可以通过使用 System.currentTimeMillis()方法来实现。

以下伪代码可能会有帮助。

long beginTime = System.currentTimeMillis();

//your code to call the rest api

long responseTime = System.currentTimeMillis() - beginTime;