How to push Graphite metrics to Grafana Cloud with curl?

407 Views Asked by At

I'm trying to get a very simple example of pushing Graphite metrics to Grafana Cloud using their HTTP API to work.

This example comes straight from the Graphite HTTP API documentation:

user_id=<USER_ID>
api_key=<API_KEY>
url=https://<SERVER_INSTANCE>.grafana.net/graphite/metrics

timestamp_now_rounded=$(($(date +%s) / 10 * 10))
timestamp_prev_rounded=$((timestamp_now_rounded - 10))

curl -X POST -H "Authorization: Bearer $user_id:$api_key" -H "Content-Type: application/json" "$url" -d '[{
    "name": "test.metric.tagged",
    "interval": 10,
    "value": 2,
    "tags": ["foo=bar", "baz=quux"],
    "time": '$timestamp_now_rounded'
}]'

When I run this script I get:

{"status":"error","error":"authentication error: invalid authentication credentials"}

I am not sure which credentials to use. I have already tried creating a service account and a cloud access policy with write permissions, and none of the credentials seem to work.

1

There are 1 best solutions below

0
Raine Revere On

To use the Graphite HTTP API, you need to:

  1. find the metrics url and user id
  2. add a cloud access policy with a token that has write access to metrics

User ID

  1. Log into grafana.com and click on the details of the hosted Graphite instance. Graphite Details
  2. Copy the URL and User. User will be a 7-digit number. This is the user id to use for your metrics query. Do not click "Generate now" here; that will create a read-only token. Grafana Data Source settings
  3. Scroll down to the attention box under Sending data with Carbon-Relay-NG, and click "Generate now". This is your API key. It actually creates a new token in your cloud access policy. You can add/edit/delete access policy keys by clicking Access Policy under the Security section in the left sidebar. Generate write token

With this user id and api key, you can make curl requests to your Grafana Cloud instance. You can then visualize the metrics by creating a dashboard connected to the grafanacloud-<ORG_NAME>-graphite data source.


References: