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