Artillery: Feature: Route reports - log of routes and times

Created on 13 Dec 2016  路  8Comments  路  Source: artilleryio/artillery

Thank you for creating this stress test tool!

Would be great if I could see which route/s is taking the longest where.

Log of times and routes and other useful data in a report form.

Thank you!

http enhancement

Most helpful comment

Heres my code I am using to find averages.

var alltimes = 0
var count = 0;
var obj = {};

function recordStartTime(req, context, events, done) {
    context.vars._startTime = Date.now();
    if (obj[req.name] === undefined) {
        obj[req.name] = {};
        obj[req.name].count = 0;
        obj[req.name].alltimes = 0;
    }

    return done();
}
function reportLatency(req, res, context, events, done) {

    if (context.vars._startTime) {
        var delta = Date.now() - context.vars._startTime;
        // console.log(delta)
        obj[req.name].count++;
        obj[req.name].alltimes += delta;
        var averageTime = obj[req.name].alltimes / obj[req.name].count;
        obj[req.name].averageTimes = averageTime;
        if (obj[req.name].count === 10) { **//Here i'd like insert a value for arrivalRate * duration**
            console.log(" ")  
            console.log("****** Names            - ", req.name)
            console.log("****** Average Time     - ", obj[req.name].averageTimes)
            console.log("****** Count            - ", obj[req.name].count)
        }
        events.emit('customStat', { stat: `latency for ${req.name || req.url}`, value: delta });
    }
    return done();
}



md5-2ae3f27abe9da8d4c0c448dbc7a02141



module.exports = {
    recordStartTime: recordStartTime,
    reportLatency: reportLatency
}

All 8 comments

Definitely a useful feature that should be built in. 馃憤

In the meantime this can be accomplished with a little bit of custom JS:

- post:
    url: "/some/resource"
    json:
     some: "data"
    name: "Name the route for reports"
    beforeRequest: ["recordStartTime"]
    afterResponse: ["reportLatency"]
function recordStartTime(req, context, events, done) {
  context.vars._startTime = Date.now();
  return done();
}

function reportLatency(req, res, context, events, done) {
  if (context.vars._startTime) {
    var delta = Date.now() - context.vars._startTime;
    // this is undocumented but probably not going anywhere:
    events.emit('customStat', { stat: `latency for ${req.name || req.url}`, value: delta });
  }
  return done();
}

Untested, but should work.

Thank you so much hassy! It worked like a charm. Great stuff!

update:
Even shows up on the HTML Report! wow. amazing. Really great stuff hassy, thank you so much!

Heres my code I am using to find averages.

var alltimes = 0
var count = 0;
var obj = {};

function recordStartTime(req, context, events, done) {
    context.vars._startTime = Date.now();
    if (obj[req.name] === undefined) {
        obj[req.name] = {};
        obj[req.name].count = 0;
        obj[req.name].alltimes = 0;
    }

    return done();
}
function reportLatency(req, res, context, events, done) {

    if (context.vars._startTime) {
        var delta = Date.now() - context.vars._startTime;
        // console.log(delta)
        obj[req.name].count++;
        obj[req.name].alltimes += delta;
        var averageTime = obj[req.name].alltimes / obj[req.name].count;
        obj[req.name].averageTimes = averageTime;
        if (obj[req.name].count === 10) { **//Here i'd like insert a value for arrivalRate * duration**
            console.log(" ")  
            console.log("****** Names            - ", req.name)
            console.log("****** Average Time     - ", obj[req.name].averageTimes)
            console.log("****** Count            - ", obj[req.name].count)
        }
        events.emit('customStat', { stat: `latency for ${req.name || req.url}`, value: delta });
    }
    return done();
}



md5-2ae3f27abe9da8d4c0c448dbc7a02141



module.exports = {
    recordStartTime: recordStartTime,
    reportLatency: reportLatency
}

@hassy this is awesome!

This is great Hassy!!

Thanks for this - looks like there is a TODO to deprecate the customStat event. So you might want to use histogram instead, which takes to function args instead of an object.

ee.emit('histogram', `latency for ${req.uri}`, req.totalTimeInSeconds);

Duplicate of #92

Thanks for this - looks like there is a TODO to deprecate the customStat event. So you might want to use histogram instead, which takes to function args instead of an object.

ee.emit('histogram', `latency for ${req.uri}`, req.totalTimeInSeconds);

Does this mean that the recordStartTime method is unnecessary? Looks like the request object has everything it needs to report the elapsed time of each endpoint request, right?

I also assume there's no real way to ensure on individual endpoints either.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hassy picture hassy  路  4Comments

mrchief picture mrchief  路  3Comments

CaseyBurnsSv picture CaseyBurnsSv  路  4Comments

endrureza picture endrureza  路  5Comments

DanielMSchmidt picture DanielMSchmidt  路  4Comments