Prenez des snapshots de graphiques à l’aide de l’API.
GET https://api.datadoghq.eu/api/v1/graph/snapshothttps://api.datadoghq.com/api/v1/graph/snapshot
Prenez des snapshots de graphiques. Remarque : lorsqu’un snapshot est créé, vous devez attendre un certain temps avant de pouvoir y accéder.
Nom
Type
Description
metric_query [required]
string
The metric query.
start [required]
integer
The POSIX timestamp of the start of the query.
end [required]
integer
The POSIX timestamp of the end of the query.
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.
OK
Object representing a graph snapshot.
{
"graph_def": "string",
"metric_query": "string",
"snapshot_url": "https://app.datadoghq.com/s/f12345678/aaa-bbb-ccc"
}
Bad Request
Error response object.
{
"errors": [
"Bad Request"
]
}
Forbidden
Error response object.
{
"errors": [
"Bad Request"
]
}
# Required query arguments
export start="CHANGE_ME"
export end="CHANGE_ME"
# Curl command
curl -X GET "https://api.datadoghq.eu"https://api.datadoghq.com/api/v1/graph/snapshot&start=${start}&end=${end}" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_CLIENT_APP_KEY}"
package main
import (
"context"
"encoding/json"
"fmt"
"os"
datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)
func main() {
ctx := context.WithValue(
context.Background(),
datadog.ContextAPIKeys,
map[string]datadog.APIKey{
"apiKeyAuth": {
Key: os.Getenv("DD_CLIENT_API_KEY"),
},
"appKeyAuth": {
Key: os.Getenv("DD_CLIENT_APP_KEY"),
},
},
)
start := int64(789) // int64 | The POSIX timestamp of the start of the query.
end := int64(789) // int64 | The POSIX timestamp of the end of the query.
metricQuery := "metricQuery_example" // string | The metric query. (optional)
eventQuery := "eventQuery_example" // string | A query that adds event bands to the graph. (optional)
graphDef := "graphDef_example" // string | A JSON document defining the graph. `graph_def` can be used instead of `metric_query`. The JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar) and should be formatted to a single line then URL encoded. (optional)
title := "title_example" // string | A title for the graph. If no title is specified, the graph does not have a title. (optional)
configuration := datadog.NewConfiguration()
api_client := datadog.NewAPIClient(configuration)
resp, r, err := api_client.SnapshotsApi.GetGraphSnapshot(ctx).Start(start).End(end).MetricQuery(metricQuery).EventQuery(eventQuery).GraphDef(graphDef).Title(title).Execute()
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)
}
// response from `GetGraphSnapshot`: GraphSnapshot
response_content, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from SnapshotsApi.GetGraphSnapshot:\n%s\n", response_content)
}
// Import classes:
import java.util.*;
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.auth.*;
import com.datadog.api.v1.client.model.*;
import com.datadog.api.v1.client.api.SnapshotsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure the Datadog site to send API calls to
HashMap<String, String> serverVariables = new HashMap<String, String>();
String site = System.getenv("DD_SITE");
if (site != null) {
serverVariables.put("site", site);
defaultClient.setServerVariables(serverVariables);
}
// Configure API key authorization:
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
defaultClient.configureApiKeys(secrets);
SnapshotsApi apiInstance = new SnapshotsApi(defaultClient);
Long start = 56L; // Long | The POSIX timestamp of the start of the query.
Long end = 56L; // Long | The POSIX timestamp of the end of the query.
String metricQuery = "metricQuery_example"; // String | The metric query.
String eventQuery = "eventQuery_example"; // String | A query that adds event bands to the graph.
String graphDef = "graphDef_example"; // String | A JSON document defining the graph. `graph_def` can be used instead of `metric_query`. The JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar) and should be formatted to a single line then URL encoded.
String title = "title_example"; // String | A title for the graph. If no title is specified, the graph does not have a title.
try {
GraphSnapshot result = apiInstance.getGraphSnapshot()
.start(start)
.end(end)
.metricQuery(metricQuery)
.eventQuery(eventQuery)
.graphDef(graphDef)
.title(title)
.execute();
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();
}
}
}
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
)
import os
from dateutil.parser import parse as dateutil_parser
import datadog_api_client.v1
from datadog_api_client.v1.api import snapshots_api
from datadog_api_client.v1.models import *
from pprint import pprint
# Defining the host is optional and defaults to https://api.datadoghq.com
# See configuration.py for a list of all supported configuration parameters.
configuration = datadog_api_client.v1.Configuration(
host = "https://api.datadoghq.com"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure API key authorization: apiKeyAuth
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['apiKeyAuth'] = 'Bearer'
# Configure API key authorization: appKeyAuth
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['appKeyAuth'] = 'Bearer'
# Enter a context with an instance of the API client
with datadog_api_client.v1.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = snapshots_api.SnapshotsApi(api_client)
start = 1 # int | The POSIX timestamp of the start of the query.
end = 1 # int | The POSIX timestamp of the end of the query.
metric_query = "metric_query_example" # str | The metric query. (optional)
event_query = "event_query_example" # str | A query that adds event bands to the graph. (optional)
graph_def = "graph_def_example" # str | A JSON document defining the graph. `graph_def` can be used instead of `metric_query`. The JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar) and should be formatted to a single line then URL encoded. (optional)
title = "title_example" # str | A title for the graph. If no title is specified, the graph does not have a title. (optional)
# example passing only required values which don't have defaults set
try:
# Take graph snapshots
api_response = api_instance.get_graph_snapshot(start, end)
pprint(api_response)
except datadog_api_client.v1.ApiException as e:
print("Exception when calling SnapshotsApi->get_graph_snapshot: %s\n" % e)
# example passing only required values which don't have defaults set
# and optional values
try:
# Take graph snapshots
api_response = api_instance.get_graph_snapshot(start, end, metric_query=metric_query, event_query=event_query, graph_def=graph_def, title=title)
pprint(api_response)
except datadog_api_client.v1.ApiException as e:
print("Exception when calling SnapshotsApi->get_graph_snapshot: %s\n" % e)
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)
require 'time'
require 'datadog_api_client/v1'
# setup authorization
DatadogAPIClient::V1.configure do |config|
# Configure API key authorization: apiKeyAuth
config.api_key['apiKeyAuth'] = ENV["DD_CLIENT_API_KEY"]
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
# config.api_key_prefix['apiKeyAuth'] = 'Bearer'
# Configure API key authorization: appKeyAuth
config.api_key['appKeyAuth'] = ENV["DD_CLIENT_APP_KEY"]
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
# config.api_key_prefix['appKeyAuth'] = 'Bearer'
end
api_instance = DatadogAPIClient::V1::SnapshotsApi.new
start = 789 # Integer | The POSIX timestamp of the start of the query.
_end = 789 # Integer | The POSIX timestamp of the end of the query.
opts = {
metric_query: 'metric_query_example', # String | The metric query.
event_query: 'event_query_example', # String | A query that adds event bands to the graph.
graph_def: 'graph_def_example', # String | A JSON document defining the graph. `graph_def` can be used instead of `metric_query`. The JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar) and should be formatted to a single line then URL encoded.
title: 'title_example' # String | A title for the graph. If no title is specified, the graph does not have a title.
}
begin
# Take graph snapshots
result = api_instance.get_graph_snapshot(start, _end, opts)
p result
rescue DatadogAPIClient::V1::ApiError => e
puts "Error when calling SnapshotsApi->get_graph_snapshot: #{e}"
end