-
-
Save jmarbach/5b0d27a94c16a9bbc9cb1462286fdcbe to your computer and use it in GitHub Desktop.
Sending Graphite Metrics to Grafana Cloud with Ruby
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
require 'faraday' | |
# Go to "My Account" (grafana.com/orgs/your-organization), | |
# then under your Grafana stack, click the "Details" button under Graphite. | |
# Under the section titled "Using Grafana with Grafana Cloud Graphite" you will see | |
# your username. You can also generate an API key here, or do so in the account | |
# overview side navigation. | |
USER_ID = '123456' | |
API_KEY = 'your-api-key-123-!!!' | |
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 | |
response = Faraday.post('https://[...].grafana.net/graphite/metrics', | |
body.to_json, | |
content_type: 'application/json', | |
authorization: "Bearer #{USER_ID}:#{API_KEY}" | |
) | |
data = JSON.parse(response.body) | |
puts data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment