Support & information center

Custom metrics commands

testRTC enables users to create custom metrics for test results. Since we can’t collect everything you have in mind, you can add your own metrics as custom ones. These will get collected, aggregated and reported as part of the test result and be accessible to you similar to all the other metrics that testRTC is already collecting.

There are a few interesting things you can do with custom metrics:

  1. Set metrics from timers you set in your test
  2. Use metrics as part of your test expectations
  3. Inject metrics through our integration API

rtcSetMetric()

Create a metric that will be collected by the testRTC server or updated its value. The metric will be placed as part of the aggregated test result report.

During the test, the metric’s value will be calculated and stored per agent.

At the end of the test, the last metric value will be presented in the single agent’s report and an aggregated value, of all agents in the test, will be presented in the summary report page.

Arguments

NameTypeDescription
keystringThe name of the metric to set
operationstringCan be one of the following operations:   “set” – set a new value for the metric “add” – add to the current value of the metric “sub” – subtract from the current value of the metric
valuenumberThe value that will be used for the operation
 aggregate (optional)stringThe type of aggregation to use for this custom metric across agents in the same test run:   “sum” – Sum the metric’s value across all agents “avg” – Calculate the average of this metric’s value across all agents If this argument is missing, “sum” will be used by default.

Code example

The code below adds an additional connected call to the custom metric named “connected-calls”.

client.rtcSetMetric("connected-calls", "add", 1);Code language: JavaScript (javascript)

The code below sets the value of the custom metric “life-universe-everything” to 42.

client.rtcSetMetric("live-universe-everything", "set", 42);Code language: JavaScript (javascript)

rtcSetMetricFromTimer()

Create a metric that will hold the time elapsed from the timer start time. The metric will be placed as part of the aggregated test result report.

During the test, the metric’s value will be calculated and stored per agent.

At the end of the test, the last metric value will be presented in the single agent’s report and an aggregated value, of all agents in the test, will be presented in the summary report page.

For more about times, check the timer commands available in testRTC.

Arguments

NameTypeDescription
metric namestringThe name of the metric to set
timer keystringThe name of the timer

Code example

client
    .rtcStartTimer('myTimer')

    .rtcGetTimer('myTimer', function(timer) {
	client.rtcInfo('Time: %d', timer)
    })

    .rtcSetMetricFromTimer('tmetric', 'myTimer');Code language: JavaScript (javascript)

The code snippet above would result the following:

  • time=100; .rtcStartTimer(‘myTimer’)
  • time=150; .rtcGetTimer(‘myTimer’, …); timer=50
  • time=180; .rtcSetMetricFromTimer(‘tmetric’, ‘myTimer’) tmetric=80

Was this article helpful?

Related Articles