• /
  • Log in
  • Free account
Docs

RecordMetric (.NET agent API)

Syntax

NewRelic.Api.Agent.NewRelic.RecordMetric(string $metric_name, single $metric_value)

Records a custom metric with the given name.

Requirements

Compatible with all agent versions.

Compatible with all app types.

Description

Records a custom metric with the given name. To view these custom metrics, use the query builder to search metrics and create customizable charts. See also IncrementCounter() and RecordResponseTimeMetric().

Important

When creating a custom metric, start the name with Custom/ (for example, Custom/MyMetric).

Parameters

Parameter

Description

$metric_name

string

Required. The name of the metric to record. Only the first 255 characters are retained.

$metric_value

single

Required. The quantity to record for the metric.

Examples

Record response time of a sleeping process

Stopwatch stopWatch = Stopwatch.StartNew();
System.Threading.Thread.Sleep(5000);
stopWatch.Stop();
NewRelic.Api.Agent.NewRelic.RecordMetric("Custom/DEMO_Record_Metric", stopWatch.ElapsedMilliseconds);

For more help

If you need more help, check out these support and learning resources:

Docs
Create issueEdit page
Copyright © 2021 New Relic Inc.