// Submit metrics returns "Payload accepted" 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/datadogV2"
)
func main() {
body := datadogV2.MetricPayload{
Series: []datadogV2.MetricSeries{
{
Metric: "system.load.1",
Type: datadogV2.METRICINTAKETYPE_UNSPECIFIED.Ptr(),
Points: []datadogV2.MetricPoint{
{
Timestamp: datadog.PtrInt64(time.Now().Unix()),
Value: datadog.PtrFloat64(0.7),
},
},
Resources: []datadogV2.MetricResource{
{
Name: datadog.PtrString("dummyhost"),
Type: datadog.PtrString("host"),
},
},
},
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewMetricsApi(apiClient)
resp, r, err := api.SubmitMetrics(ctx, body, *datadogV2.NewSubmitMetricsOptionalParameters())
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `MetricsApi.SubmitMetrics`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `MetricsApi.SubmitMetrics`:\n%s\n", responseContent)
}