• /
  • EnglishEspañol日本語한국어Português
  • Inicia sesiónComenzar ahora

Use $har for custom timing details

Importante

To use custom timing details with your scripted API monitors, you need the Node.js 16.10 runtime or newer.

You can use the $har library to create monitors with custom timing capabilities that report on interactions between the monitors and application being monitored. These custom timing use both the default node.js module and importable node.js modules.

Creating monitors with custom timing capabilities also lets you:

  • Time a request's completion. For example, using the dns module to test DNS look-ups.
  • View custom timers with default timing details in the New Relic UI as part of the waterfall view.
  • Use SyntheticRequest events to keep track of trending and alerting patterns.

Set up your custom timers

Create your timing resources using addResource() or getResource(). You start these timers by using startTimer(). Likewise, you stop these timers by using stopTimer().

To create a timing resource:

const testTimer = $har.addResource("Test Timer");
testTimer.startTimer();
await sleep(100);
testTimer.endTimer();

Alternatively, create a timer using getResource():

$har.getResource("Test Timer").startTimer();
await sleep(100);
$har.getResource("Test Timer").endTimer();

Retrieve specific timing details

Depending on your specific scripting needs, you can pull more granular timing details into the UI through a variety of attributes. These include:

  • blocked
  • dns
  • connect
  • ssl
  • send
  • wait
  • receive

For example, to add timers to a simple DNS monitor:

const { Resolver } = require("dns").promises;
const myResolver = new Resolver();
myResolver.setServers(["1.1.1.1"]);
const dnsResource = $har.addResource("DNS Lookup");
dnsResource.startTimer();
dnsResource.dns().startTimer();
let addresses = await myResolver.resolve4("newrelic.com");
dnsResource.dns().endTimer();
dnsResource.endTimer();
console.log(addresses);
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.