Skip to content

Instantly share code, notes, and snippets.

@jmarbach
Created February 9, 2023 20:10
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/5f3e5ed1040cabfae2c497b124b02bcb to your computer and use it in GitHub Desktop.
Save jmarbach/5f3e5ed1040cabfae2c497b124b02bcb to your computer and use it in GitHub Desktop.
Sending Prometheus metrics to Grafana Cloud using the Influx Line Protocol and Node.js
import fetch from 'node-fetch';
const USER_ID = '123456';
const API_KEY = 'your-api-key-123-!!!';
const body = 'test,bar_label=abc,source=grafana_cloud_docs metric=35.2';
// Endpoint is on the same page as the userid / API Key
const response = await fetch('https://influx[...].grafana.net/api/v1/push/influx/write', {
method: 'post',
body,
headers: {
'Authorization': `Bearer ${USER_ID}:${API_KEY}`,
'Content-Type': 'text/plain',
},
});
const data = await response.status;
console.log(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment