GET https://api.datadoghq.eu/api/v1/graph/snapshot https://api.ddog-gov.com/api/v1/graph/snapshot https://api.datadoghq.com/api/v1/graph/snapshot https://api.us3.datadoghq.com/api/v1/graph/snapshot https://api.us5.datadoghq.com/api/v1/graph/snapshot
Présentation Prenez des snapshots de graphiques.
Remarque : lorsqu’un snapshot est créé, vous devez attendre un certain temps avant de pouvoir y accéder.
Arguments Chaînes de requête The POSIX timestamp of the start of the query.
The POSIX timestamp of the end of the query.
A query that adds event bands to the graph.
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.
A title for the graph. If no title is specified, the graph does not have a title.
Réponse OK
Object representing a graph snapshot.
Expand All
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.
The metric query. One of metric_query
or graph_def
is required.
Copier
{
"graph_def" : "string" ,
"metric_query" : "string" ,
"snapshot_url" : "https://app.datadoghq.com/s/f12345678/aaa-bbb-ccc"
}
Bad Request
Error response object.
Expand All
Array of errors returned by the API.
Copier
{
"errors" : [
"Bad Request"
]
}
Forbidden
Error response object.
Expand All
Array of errors returned by the API.
Copier
{
"errors" : [
"Bad Request"
]
}
Too many requests
Error response object.
Expand All
Array of errors returned by the API.
Copier
{
"errors" : [
"Bad Request"
]
}
Exemple de code Copier
# Required query arguments export start = "CHANGE_ME" export end = "CHANGE_ME" # Curl command
curl -X GET "https://api.datadoghq.eu "https://api.ddog-gov.com "https://api.datadoghq.com "https://api.us3.datadoghq.com "https://api.us5.datadoghq.com /api/v1/graph/snapshot ? start = ${start} & end = ${end} " \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY} " \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY} "
Copier
"""
Take graph snapshots returns "OK" response
"""
from datetime import datetime
from dateutil.relativedelta import relativedelta
from datadog_api_client import ApiClient , Configuration
from datadog_api_client.v1.api.snapshots_api import SnapshotsApi
configuration = Configuration ()
with ApiClient ( configuration ) as api_client :
api_instance = SnapshotsApi ( api_client )
response = api_instance . get_graph_snapshot (
metric_query = "avg:system.load.1{*}" ,
start = int (( datetime . now () + relativedelta ( days =- 1 )) . timestamp ()),
end = int ( datetime . now () . timestamp ()),
title = "System load" ,
)
print ( response )
Instructions First install the library and its dependencies and then save the example to example.py
and run following commands:
DD_SITE = "datadoghq.com us3.datadoghq.com us5.datadoghq.com datadoghq.eu ddog-gov.com " DD_API_KEY = "<DD_API_KEY>" DD_APP_KEY = "<DD_APP_KEY>" python3 "example.py"
Copier
# Take graph snapshots returns "OK" response
require "datadog_api_client"
api_instance = DatadogAPIClient :: V1 :: SnapshotsAPI . new
opts = {
metric_query : "avg:system.load.1{*}" ,
title : "System load" ,
}
p api_instance . get_graph_snapshot (( Time . now + - 1 * 86400 ) . to_i , Time . now . to_i , opts )
Instructions First install the library and its dependencies and then save the example to example.rb
and run following commands:
DD_SITE = "datadoghq.com us3.datadoghq.com us5.datadoghq.com datadoghq.eu ddog-gov.com " DD_API_KEY = "<DD_API_KEY>" DD_APP_KEY = "<DD_APP_KEY>" rb "example.rb"
Copier
require 'rubygems'
require 'dogapi'
api_key = '<DATADOG_API_KEY>'
app_key = '<DATADOG_APPLICATION_KEY>'
dog = Dogapi :: Client . new ( api_key , app_key )
end_ts = Time . now () . to_i
start_ts = end_ts - ( 60 * 60 )
dog . graph_snapshot ( "system.load.1{*}" , start_ts , end_ts )
Instructions First install the library and its dependencies and then save the example to example.rb
and run following commands:
DD_SITE = "datadoghq.com us3.datadoghq.com us5.datadoghq.com datadoghq.eu ddog-gov.com " DD_API_KEY = "<DD_API_KEY>" DD_APP_KEY = "<DD_APP_KEY>" rb "example.rb"
Copier
/**
* Take graph snapshots returns "OK" response
*/
import { v1 } from "@datadog/datadog-api-client" ;
const configuration = v1 . createConfiguration ();
const apiInstance = new v1 . SnapshotsApi ( configuration );
const params : v1.SnapshotsApiGetGraphSnapshotRequest = {
metricQuery : "avg:system.load.1{*}" ,
start : new Date ( new Date (). getTime () / 1000 + - 1 * 86400 ). getTime () / 1000 ,
end : new Date (). getTime () / 1000 ,
title : "System load" ,
};
apiInstance
. getGraphSnapshot ( params )
. then (( data : v1.GraphSnapshot ) => {
console . log (
"API called successfully. Returned data: " + JSON . stringify ( data )
);
})
. catch (( error : any ) => console . error ( error ));
Instructions First install the library and its dependencies and then save the example to example.ts
and run following commands:
DD_SITE = "datadoghq.com us3.datadoghq.com us5.datadoghq.com datadoghq.eu ddog-gov.com " DD_API_KEY = "<DD_API_KEY>" DD_APP_KEY = "<DD_APP_KEY>" tsc "example.ts"
Copier
// Take graph snapshots returns "OK" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"time"
datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)
func main () {
ctx := datadog . NewDefaultContext ( context . Background ())
configuration := datadog . NewConfiguration ()
apiClient := datadog . NewAPIClient ( configuration )
resp , r , err := apiClient . SnapshotsApi . GetGraphSnapshot ( ctx , time . Now (). AddDate ( 0 , 0 , - 1 ). Unix (), time . Now (). Unix (), * datadog . NewGetGraphSnapshotOptionalParameters (). WithMetricQuery ( "avg:system.load.1{*}" ). WithTitle ( "System load" ))
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.com us3.datadoghq.com us5.datadoghq.com datadoghq.eu ddog-gov.com " DD_API_KEY = "<DD_API_KEY>" DD_APP_KEY = "<DD_APP_KEY>" go run "main.go"
Copier
// Take graph snapshots returns "OK" response
import com.datadog.api.v1.client.ApiClient ;
import com.datadog.api.v1.client.ApiException ;
import com.datadog.api.v1.client.Configuration ;
import com.datadog.api.v1.client.api.SnapshotsApi ;
import com.datadog.api.v1.client.api.SnapshotsApi.GetGraphSnapshotOptionalParameters ;
import com.datadog.api.v1.client.model.GraphSnapshot ;
import java.time.OffsetDateTime ;
public class Example {
public static void main ( String [] args ) {
ApiClient defaultClient = Configuration . getDefaultApiClient ();
SnapshotsApi apiInstance = new SnapshotsApi ( defaultClient );
try {
GraphSnapshot result =
apiInstance . getGraphSnapshot (
OffsetDateTime . now (). plusDays (- 1 ). toInstant (). getEpochSecond (),
OffsetDateTime . now (). toInstant (). getEpochSecond (),
new GetGraphSnapshotOptionalParameters ()
. metricQuery ( "avg:system.load.1{*}" )
. title ( "System load" ));
System . out . println ( result );
} catch ( ApiException e ) {
System . err . println ( "Exception when calling SnapshotsApi#getGraphSnapshot" );
System . err . println ( "Status code: " + e . getCode ());
System . err . println ( "Reason: " + e . getResponseBody ());
System . err . println ( "Response headers: " + e . getResponseHeaders ());
e . printStackTrace ();
}
}
}
Instructions First install the library and its dependencies and then save the example to Example.java
and run following commands:
DD_SITE = "datadoghq.com us3.datadoghq.com us5.datadoghq.com datadoghq.eu ddog-gov.com " DD_API_KEY = "<DD_API_KEY>" DD_APP_KEY = "<DD_APP_KEY>" java "Example.java"
Copier
from datadog import initialize , api
import time
options = {
'api_key' : '<DATADOG_API_KEY>' ,
'app_key' : '<DATADOG_APPLICATION_KEY>'
}
initialize ( ** options )
# Take a graph snapshot
end = int ( time . time ())
start = end - ( 60 * 60 )
api . Graph . create (
graph_def = '{ \
"viz": "timeseries", \
"requests": [ \
{"q": "avg:system.load.1{*}", "conditional_formats": [], "type": "line"}, \
{"q": "avg:system.load.5{*}", "type": "line"}, \
{"q": "avg:system.load.15{*}", "type": "line"} \
], \
"events": [ \
{"q": "hosts:* ", "tags_execution": "and"} \
]}' ,
start = start ,
end = end
)
Instructions First install the library and its dependencies and then save the example to example.py
and run following commands:
DD_SITE = "datadoghq.com us3.datadoghq.com us5.datadoghq.com datadoghq.eu ddog-gov.com " DD_API_KEY = "<DD_API_KEY>" DD_APP_KEY = "<DD_APP_KEY>" python "example.py"