Skip to content

Instantly share code, notes, and snippets.

@jmarbach
Created February 9, 2023 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmarbach/0b1aeba0e02793d3f8e7ea42f1ee279c to your computer and use it in GitHub Desktop.
Save jmarbach/0b1aeba0e02793d3f8e7ea42f1ee279c to your computer and use it in GitHub Desktop.
Sending Graphite metrics to Grafana Cloud with Node.js
import fetch from 'node-fetch';
const USER_ID = '123456';
const API_KEY = 'your-api-key-123-!!!';
const body = [
{
"name": "test.metric",
"interval": 10,
"value": 12.345,
"tags": ["foo=bar", "source=grafana_cloud_docs"],
"time": 1534685580
},
{
"name": "test.metric",
"interval": 10,
"value": 12.345,
"tags": ["foo=baz", "source=grafana_cloud_docs"],
"time": 1534685590
}
]
// Endpoint is on the same page as the userid / API Key
const response = await fetch('https://[...].grafana.net/graphite/metrics', {
method: 'post',
body: JSON.stringify(body),
headers: {
'Authorization': `Bearer ${USER_ID}:${API_KEY}`,
'Content-Type': 'application/json',
},
});
const data = await response.json()
console.log(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment