How can i calculate total response time taken per request?
If you are asking in general then you can either use time curl or curl with -w parameter like below:
time curl [http://www.google.com](http://www.google.com) -o /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 19924 0 19924 0 0 112k 0 --:--:-- --:--:-- --:--:-- 113k
real 0m0.179s
user 0m0.004s
sys 0m0.004s
curl -s -w "%{time_total}\n" -o /dev/null [http://www.google.com](http://www.google.com)
If your question is specific to apigee, then there are a few ways for you to get that information:
- Trace UI: The transaction panel on the left hand side of the trace UI provides you the response time for each api call.
See attached screenshot
- You can also get this information from Apigee Analytics. Go to Analytics menu option in the Edge UI and select Proxy Performance. You will get the average response times for your selected apis for a selected time range. You can break it down to minute, hour, week level. Note that this is just going to show you the average response time and not the response time for each call. See screenshot attached:
Hope this answers your question. if you have any specific question, please post them here so that we can address them correctly.
Here is a same Javascript policy code. I should be self explanatory
var client_start_time = context.getVariable('client.received.start.timestamp');
var target_start_time = context.getVariable('target.sent.start.timestamp');
var client_end_time = context.getVariable('system.timestamp');
var target_end_time = context.getVariable('target.received.end.timestamp');
if(target_start_time!=null && target_start_time != "" && target_end_time !=null && target_end_time!="" ){
context.setVariable("total_request_time",(client_end_time-client_start_time)+'');
context.setVariable("total_target_time", (target_end_time-target_start_time)+'');
}
Hi Arghya Das,Thanks for your response.but my question was how to calculate response time taken per request. after that we have to put this value in Header.
i used a JS as the last execution policy in the target endpoint to find the difference between the (current timestamp - client.received.start.timestamp) and used it in the response.

