Which variable will have the total time elapsed ?

surekapoppy
Participant II

How can I get the total elapsed time using java script which is highlighted in the pic below . I have tried

var totalElapsedTime = (context.getVariable("system.timestamp")-context.getVariable("client.received.start.timestamp")). This is not working "system.timestamp" is empty.

4097-capture.png

Solved Solved
1 2 1,000
1 ACCEPTED SOLUTION

Hmm, it's strange that "system.timestamp" is empty. that variable is always defined. Something else is wrong there. I think perhaps your arithmetic is not quite right.

Sometimes I add a JS policy into my Apigee Edge proxies that collects this information. Here's what I use.

// emitElapsed.js
// ------------------------------------------------------------------
//
// emit the elapsed time into response headers
//

var start, end, delta;

start = context.getVariable('target.sent.start.timestamp');
end = context.getVariable('target.received.end.timestamp');
delta = Math.floor(end - start);
context.proxyResponse.headers['X-time-target-elapsed'] = delta;


start = context.getVariable('client.received.start.timestamp');
end = context.getVariable('system.timestamp');
delta = Math.floor(end - start);
context.proxyResponse.headers['X-time-total-elapsed'] = delta;

This JS needs to be attached to the proxy response flow, ideally in postflow.

View solution in original post

2 REPLIES 2

Hmm, it's strange that "system.timestamp" is empty. that variable is always defined. Something else is wrong there. I think perhaps your arithmetic is not quite right.

Sometimes I add a JS policy into my Apigee Edge proxies that collects this information. Here's what I use.

// emitElapsed.js
// ------------------------------------------------------------------
//
// emit the elapsed time into response headers
//

var start, end, delta;

start = context.getVariable('target.sent.start.timestamp');
end = context.getVariable('target.received.end.timestamp');
delta = Math.floor(end - start);
context.proxyResponse.headers['X-time-target-elapsed'] = delta;


start = context.getVariable('client.received.start.timestamp');
end = context.getVariable('system.timestamp');
delta = Math.floor(end - start);
context.proxyResponse.headers['X-time-total-elapsed'] = delta;

This JS needs to be attached to the proxy response flow, ideally in postflow.

Thanks @Dino