-
-
Save jmarbach/0b1aeba0e02793d3f8e7ea42f1ee279c to your computer and use it in GitHub Desktop.
Sending Graphite metrics to Grafana Cloud with Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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