No custom metrics when posting by HTTP

Viewed 590

There seems to be very limited documentation on this. I'm looking to post a custom metric (actually from an IoT microcontroller) via HTTP.

According to this page the appropriate endpoint is POST https://api.datadoghq.com/api/v1/series?api_key=xyz, although this does seem more geared to posting a bulk set of time series data and not for individual measurements. Anyway, I've posted to it in various ways (including the EXAMPLE JSON given on that page) and receiving back HTTP 202s, which leads me to believe the data is sinking in somewhere.

However, nothing appears in the Metrics Explorer section on my account.

Can anyone provide some direction?

2 Answers

At the time of writing, the docs are wrong.

The currently provided example for cURL is:



## Dynamic Points
# Post time-series data that can be graphed on Datadog’s dashboards.
# Template variables
export NOW="$(date +%s)"
# Curl command
curl -X POST "https://api.datadoghq.com/api/v1/series" \
-H "Content-Type: text/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-d @- << EOF
{
  "series": [
    {
      "metric": "system.load.1",
      "points": [
        [
          "${NOW}",
          "1234.5"
        ]
      ]
    }
  ]
}
EOF

The API returns a 202 OK, but no custom metric is created.

The points key needs to be an array of tuple(number, number), and in the example is a tuple(string, string).

Changing it to:

      "points": [
        [
          ${NOW},
          1234.5
        ]

Resolved the issue for me.

I've contacted their support about the docs being incorrect, and the fact the API endpoint should return 400 for the invalid example payload.

With the information provided, I don't see where the issue can come from. Could you share the full code used for the submission (without the API key).

If another example could help, here is what I use in Python:

import json
import requests
import time

def submit_timeseries_point(config, metricname, hostname, value, tags, type = "gauge"):
  timestamp = time.time()
  payload = { "series": [{
      "metric": metricname,
      "points": [[timestamp, value]],
      "type": type,
      "host": hostname,
      "tags": tags
  }]}
  headers = {'content-type': 'application/json'}
  url = '{}api/v1/series?api_key={}'.format(config["api_host"], config["api_key"])
  r = requests.post(url, data=json.dumps(payload), headers=headers)
  jsonResponse = r.json()

Then I usually check if the metric appears in the metric summary page.

Related