k6

Get the count of VU per profile

Hi I have a requirement to get VU per on different profile per given time.
My scenario is this.I want to show VU count on Gauge metricx, how many VUs for a particulate profile in given time. But problem in given code, value didn’t share between VUs.

Is that make sense ?

var profiles = recordings.map(function(r) {
    return { profile : r.key, count : 0};
});

 export default function() {
  var profile = profiles.find(x=>x.profile == recording.key);

  let recording = recordings[Math.floor(Math.random()*recordings.length)];

 profile.count+=1;
 profile_vu_gauge.add(profile.count,{ profile: recording.key})

  console.log('FILE :'+recording.key);
  console.log(`VU: ${__VU}  -  ITER: ${__ITER}`);

    group('profile-'+recording.key, function() {
      let st = Date.now();
      recording.method();
      myTrend.add(Date.now() - st, { profile: recording.key});
      //recordingTrends[i].add(Date.now() - st, { profile: x.key});
      profile_trend.add(Date.now() - st, { profile: recording.key});
    });

  profile.count -=1;
  profile_vu_gauge.add(profile.count,{ profile: recording.key});

    group('idle-time', function() {
      sleep(Math.floor(Math.random() * 30 + 10));
    });
}

I don’t understand what exactly are you trying to accomplish, but you might be better served by a Counter metric that you .add(+1) (with the appropriate tag) at the start of the scenario in a given VU and remove (i.e. .add(-1)) when the scenario ends.

1 Like