1. Registry
  2. Packages
  3. Datadog Provider
  4. API Docs
  5. DerivedMetric
Viewing docs for Datadog v5.20.0
published on Wednesday, Nov 11, 2026 by Pulumi
datadog logo
Viewing docs for Datadog v5.20.0
published on Wednesday, Nov 11, 2026 by Pulumi

    Provides a Datadog derived metric resource computed from a formula and metric queries. Managing derived metrics requires the Manage Tags for Metrics permission.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as datadog from "@pulumi/datadog";
    
    // Create a derived metric that combines two metric queries
    const cpuTotal = new datadog.DerivedMetric("cpu_total", {
        name: "custom.cpu.total",
        definition: {
            formula: "a + b",
            queries: [
                {
                    name: "a",
                    dataSource: "metrics",
                    query: "avg:system.cpu.user{*}",
                },
                {
                    name: "b",
                    dataSource: "metrics",
                    query: "avg:system.cpu.system{*}",
                },
            ],
        },
    });
    
    import pulumi
    import pulumi_datadog as datadog
    
    # Create a derived metric that combines two metric queries
    cpu_total = datadog.DerivedMetric("cpu_total",
        name="custom.cpu.total",
        definition={
            "formula": "a + b",
            "queries": [
                {
                    "name": "a",
                    "data_source": "metrics",
                    "query": "avg:system.cpu.user{*}",
                },
                {
                    "name": "b",
                    "data_source": "metrics",
                    "query": "avg:system.cpu.system{*}",
                },
            ],
        })
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-datadog/sdk/v5/go/datadog"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		// Create a derived metric that combines two metric queries
    		_, err := datadog.NewDerivedMetric(ctx, "cpu_total", &datadog.DerivedMetricArgs{
    			Name: pulumi.String("custom.cpu.total"),
    			Definition: &datadog.DerivedMetricDefinitionArgs{
    				Formula: pulumi.String("a + b"),
    				Queries: datadog.DerivedMetricDefinitionQueryArray{
    					&datadog.DerivedMetricDefinitionQueryArgs{
    						Name:       pulumi.String("a"),
    						DataSource: pulumi.String("metrics"),
    						Query:      pulumi.String("avg:system.cpu.user{*}"),
    					},
    					&datadog.DerivedMetricDefinitionQueryArgs{
    						Name:       pulumi.String("b"),
    						DataSource: pulumi.String("metrics"),
    						Query:      pulumi.String("avg:system.cpu.system{*}"),
    					},
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Datadog = Pulumi.Datadog;
    
    return await Deployment.RunAsync(() => 
    {
        // Create a derived metric that combines two metric queries
        var cpuTotal = new Datadog.DerivedMetric("cpu_total", new()
        {
            Name = "custom.cpu.total",
            Definition = new Datadog.Inputs.DerivedMetricDefinitionArgs
            {
                Formula = "a + b",
                Queries = new[]
                {
                    new Datadog.Inputs.DerivedMetricDefinitionQueryArgs
                    {
                        Name = "a",
                        DataSource = "metrics",
                        Query = "avg:system.cpu.user{*}",
                    },
                    new Datadog.Inputs.DerivedMetricDefinitionQueryArgs
                    {
                        Name = "b",
                        DataSource = "metrics",
                        Query = "avg:system.cpu.system{*}",
                    },
                },
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.datadog.DerivedMetric;
    import com.pulumi.datadog.DerivedMetricArgs;
    import com.pulumi.datadog.inputs.DerivedMetricDefinitionArgs;
    import com.pulumi.datadog.inputs.DerivedMetricDefinitionQueryArgs;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            // Create a derived metric that combines two metric queries
            var cpuTotal = new DerivedMetric("cpuTotal", DerivedMetricArgs.builder()
                .name("custom.cpu.total")
                .definition(DerivedMetricDefinitionArgs.builder()
                    .formula("a + b")
                    .queries(                
                        DerivedMetricDefinitionQueryArgs.builder()
                            .name("a")
                            .dataSource("metrics")
                            .query("avg:system.cpu.user{*}")
                            .build(),
                        DerivedMetricDefinitionQueryArgs.builder()
                            .name("b")
                            .dataSource("metrics")
                            .query("avg:system.cpu.system{*}")
                            .build())
                    .build())
                .build());
    
        }
    }
    
    resources:
      # Create a derived metric that combines two metric queries
      cpuTotal:
        type: datadog:DerivedMetric
        name: cpu_total
        properties:
          name: custom.cpu.total
          definition:
            formula: a + b
            queries:
              - name: a
                dataSource: metrics
                query: avg:system.cpu.user{*}
              - name: b
                dataSource: metrics
                query: avg:system.cpu.system{*}
    
    terraform {
      required_providers {
        datadog = {
          source = "pulumi/datadog"
        }
      }
    }
    
    # Create a derived metric that combines two metric queries
    resource "datadog_derived_metric" "cpu_total" {
      lifecycle {
        create_before_destroy = true
      }
      name = "custom.cpu.total"
      definition = {
        formula = "a + b"
        queries = [{
          name        = "a"
          data_source = "metrics"
          query       = "avg:system.cpu.user{*}"
          }, {
          name        = "b"
          data_source = "metrics"
          query       = "avg:system.cpu.system{*}"
        }]
      }
    }
    

    Create DerivedMetric Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new DerivedMetric(name: string, args: DerivedMetricArgs, opts?: CustomResourceOptions);
    @overload
    def DerivedMetric(resource_name: str,
                      args: DerivedMetricArgs,
                      opts: Optional[ResourceOptions] = None)
    
    @overload
    def DerivedMetric(resource_name: str,
                      opts: Optional[ResourceOptions] = None,
                      definition: Optional[DerivedMetricDefinitionArgs] = None,
                      name: Optional[str] = None)
    func NewDerivedMetric(ctx *Context, name string, args DerivedMetricArgs, opts ...ResourceOption) (*DerivedMetric, error)
    public DerivedMetric(string name, DerivedMetricArgs args, CustomResourceOptions? opts = null)
    public DerivedMetric(String name, DerivedMetricArgs args)
    public DerivedMetric(String name, DerivedMetricArgs args, CustomResourceOptions options)
    
    type: datadog:DerivedMetric
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    resource "datadog_derived_metric" "name" {
        # resource properties
    }

    Parameters

    name string
    The unique name of the resource.
    args DerivedMetricArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args DerivedMetricArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args DerivedMetricArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args DerivedMetricArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args DerivedMetricArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var derivedMetricResource = new Datadog.DerivedMetric("derivedMetricResource", new()
    {
        Definition = new Datadog.Inputs.DerivedMetricDefinitionArgs
        {
            Formula = "string",
            Queries = new[]
            {
                new Datadog.Inputs.DerivedMetricDefinitionQueryArgs
                {
                    DataSource = "string",
                    Name = "string",
                    Query = "string",
                },
            },
        },
        Name = "string",
    });
    
    example, err := datadog.NewDerivedMetric(ctx, "derivedMetricResource", &datadog.DerivedMetricArgs{
    	Definition: &datadog.DerivedMetricDefinitionArgs{
    		Formula: pulumi.String("string"),
    		Queries: datadog.DerivedMetricDefinitionQueryArray{
    			&datadog.DerivedMetricDefinitionQueryArgs{
    				DataSource: pulumi.String("string"),
    				Name:       pulumi.String("string"),
    				Query:      pulumi.String("string"),
    			},
    		},
    	},
    	Name: pulumi.String("string"),
    })
    
    resource "datadog_derived_metric" "derivedMetricResource" {
      lifecycle {
        create_before_destroy = true
      }
      definition = {
        formula = "string"
        queries = [{
          data_source = "string"
          name        = "string"
          query       = "string"
        }]
      }
      name = "string"
    }
    
    var derivedMetricResource = new DerivedMetric("derivedMetricResource", DerivedMetricArgs.builder()
        .definition(DerivedMetricDefinitionArgs.builder()
            .formula("string")
            .queries(DerivedMetricDefinitionQueryArgs.builder()
                .dataSource("string")
                .name("string")
                .query("string")
                .build())
            .build())
        .name("string")
        .build());
    
    derived_metric_resource = datadog.DerivedMetric("derivedMetricResource",
        definition={
            "formula": "string",
            "queries": [{
                "data_source": "string",
                "name": "string",
                "query": "string",
            }],
        },
        name="string")
    
    const derivedMetricResource = new datadog.DerivedMetric("derivedMetricResource", {
        definition: {
            formula: "string",
            queries: [{
                dataSource: "string",
                name: "string",
                query: "string",
            }],
        },
        name: "string",
    });
    
    type: datadog:DerivedMetric
    properties:
        definition:
            formula: string
            queries:
                - dataSource: string
                  name: string
                  query: string
        name: string
    

    DerivedMetric Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The DerivedMetric resource accepts the following input properties:

    Definition DerivedMetricDefinition
    The definition of a derived metric as a formula over one or more queries.
    Name string
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    Definition DerivedMetricDefinitionArgs
    The definition of a derived metric as a formula over one or more queries.
    Name string
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition object
    The definition of a derived metric as a formula over one or more queries.
    name string
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition DerivedMetricDefinition
    The definition of a derived metric as a formula over one or more queries.
    name String
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition DerivedMetricDefinition
    The definition of a derived metric as a formula over one or more queries.
    name string
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition DerivedMetricDefinitionArgs
    The definition of a derived metric as a formula over one or more queries.
    name str
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition Property Map
    The definition of a derived metric as a formula over one or more queries.
    name String
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the DerivedMetric resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing DerivedMetric Resource

    Get an existing DerivedMetric resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: DerivedMetricState, opts?: CustomResourceOptions): DerivedMetric
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            definition: Optional[DerivedMetricDefinitionArgs] = None,
            name: Optional[str] = None) -> DerivedMetric
    func GetDerivedMetric(ctx *Context, name string, id IDInput, state *DerivedMetricState, opts ...ResourceOption) (*DerivedMetric, error)
    public static DerivedMetric Get(string name, Input<string> id, DerivedMetricState? state, CustomResourceOptions? opts = null)
    public static DerivedMetric get(String name, Output<String> id, DerivedMetricState state, CustomResourceOptions options)
    resources:  _:    type: datadog:DerivedMetric    get:      id: ${id}
    import {
      to = datadog_derived_metric.example
      id = "${id}"
    }
    
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Definition DerivedMetricDefinition
    The definition of a derived metric as a formula over one or more queries.
    Name string
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    Definition DerivedMetricDefinitionArgs
    The definition of a derived metric as a formula over one or more queries.
    Name string
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition object
    The definition of a derived metric as a formula over one or more queries.
    name string
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition DerivedMetricDefinition
    The definition of a derived metric as a formula over one or more queries.
    name String
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition DerivedMetricDefinition
    The definition of a derived metric as a formula over one or more queries.
    name string
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition DerivedMetricDefinitionArgs
    The definition of a derived metric as a formula over one or more queries.
    name str
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.
    definition Property Map
    The definition of a derived metric as a formula over one or more queries.
    name String
    Caller-assigned name sent as the create ID. After import, the first apply adopts the configured name through an update using the canonical API ID, without replacing the resource. Once the name is stored in state, changing it replaces the resource. String length must be at least 1.

    Supporting Types

    DerivedMetricDefinition, DerivedMetricDefinitionArgs

    Formula string
    The formula that combines the queries into the value of the derived metric.
    Queries List<DerivedMetricDefinitionQuery>
    The list of queries referenced by the formula.
    Formula string
    The formula that combines the queries into the value of the derived metric.
    Queries []DerivedMetricDefinitionQuery
    The list of queries referenced by the formula.
    formula string
    The formula that combines the queries into the value of the derived metric.
    queries list(object)
    The list of queries referenced by the formula.
    formula String
    The formula that combines the queries into the value of the derived metric.
    queries List<DerivedMetricDefinitionQuery>
    The list of queries referenced by the formula.
    formula string
    The formula that combines the queries into the value of the derived metric.
    queries DerivedMetricDefinitionQuery[]
    The list of queries referenced by the formula.
    formula str
    The formula that combines the queries into the value of the derived metric.
    queries Sequence[DerivedMetricDefinitionQuery]
    The list of queries referenced by the formula.
    formula String
    The formula that combines the queries into the value of the derived metric.
    queries List<Property Map>
    The list of queries referenced by the formula.

    DerivedMetricDefinitionQuery, DerivedMetricDefinitionQueryArgs

    DataSource string
    The data source that the query is run against.
    Name string
    The name used to reference this query from the formula.
    Query string
    The query string executed against the data source.
    DataSource string
    The data source that the query is run against.
    Name string
    The name used to reference this query from the formula.
    Query string
    The query string executed against the data source.
    data_source string
    The data source that the query is run against.
    name string
    The name used to reference this query from the formula.
    query string
    The query string executed against the data source.
    dataSource String
    The data source that the query is run against.
    name String
    The name used to reference this query from the formula.
    query String
    The query string executed against the data source.
    dataSource string
    The data source that the query is run against.
    name string
    The name used to reference this query from the formula.
    query string
    The query string executed against the data source.
    data_source str
    The data source that the query is run against.
    name str
    The name used to reference this query from the formula.
    query str
    The query string executed against the data source.
    dataSource String
    The data source that the query is run against.
    name String
    The name used to reference this query from the formula.
    query String
    The query string executed against the data source.

    Import

    The pulumi import command can be used, for example:

    Derived metrics can be imported using their name, e.g.

    $ pulumi import datadog:index/derivedMetric:DerivedMetric cpu_total "custom.cpu.total"
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    Datadog pulumi/pulumi-datadog
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the datadog Terraform Provider.
    datadog logo
    Viewing docs for Datadog v5.20.0
    published on Wednesday, Nov 11, 2026 by Pulumi

      Try Pulumi Cloud free.
      Your team will thank you.

      Start free trial