Snapshots

Take graph snapshots using the API.

GET https://api.ap1.datadoghq.com/api/v1/graph/snapshothttps://api.datadoghq.eu/api/v1/graph/snapshothttps://api.ddog-gov.com/api/v1/graph/snapshothttps://api.datadoghq.com/api/v1/graph/snapshothttps://api.us3.datadoghq.com/api/v1/graph/snapshothttps://api.us5.datadoghq.com/api/v1/graph/snapshot

Overview

Take graph snapshots. Note: When a snapshot is created, there is some delay before it is available.

Arguments

Query Strings

Name

Type

Description

metric_query

string

The metric query.

start [required]

integer

The POSIX timestamp of the start of the query in seconds.

end [required]

integer

The POSIX timestamp of the end of the query in seconds.

event_query

string

A query that adds event bands to the graph.

graph_def

string

A JSON document defining the graph. graph_def can be used instead of metric_query. The JSON document uses the grammar defined here and should be formatted to a single line then URL encoded.

title

string

A title for the graph. If no title is specified, the graph does not have a title.

height

integer

The height of the graph. If no height is specified, the graph’s original height is used.

width

integer

The width of the graph. If no width is specified, the graph’s original width is used.

Response

OK

Object representing a graph snapshot.

Expand All

Field

Type

Description

graph_def

string

A JSON document defining the graph. graph_def can be used instead of metric_query. The JSON document uses the grammar defined here and should be formatted to a single line then URL encoded.

metric_query

string

The metric query. One of metric_query or graph_def is required.

snapshot_url

string

URL of your graph snapshot.

{
  "graph_def": "string",
  "metric_query": "string",
  "snapshot_url": "https://app.datadoghq.com/s/f12345678/aaa-bbb-ccc"
}

Bad Request

Error response object.

Expand All

Field

Type

Description

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Forbidden

Error response object.

Expand All

Field

Type

Description

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

Error response object.

Expand All

Field

Type

Description

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Code Example

// Take graph snapshots returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	"time"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)

func main() {
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV1.NewSnapshotsApi(apiClient)
	resp, r, err := api.GetGraphSnapshot(ctx, time.Now().AddDate(0, 0, -1).Unix(), time.Now().Unix(), *datadogV1.NewGetGraphSnapshotOptionalParameters().WithMetricQuery("avg:system.load.1{*}").WithTitle("System load").WithHeight(400).WithWidth(600))

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `SnapshotsApi.GetGraphSnapshot`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `SnapshotsApi.GetGraphSnapshot`:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"

PREVIEWING: deforest/fix-security-rule-link