Skip to content

Instantly share code, notes, and snippets.

@jmarbach
Created September 1, 2022 16:52
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/5e8b2b85718b05633524c59c0f44b049 to your computer and use it in GitHub Desktop.
Save jmarbach/5e8b2b85718b05633524c59c0f44b049 to your computer and use it in GitHub Desktop.
Sending InfluxDB Metrics to Grafana Cloud with Ruby
require 'net/http'
require 'uri'
require 'base64'
# 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-!!!'
BASE64_ENCODED_AUTH = Base64.strict_encode64(USER_ID + ':' + API_KEY)
uri = "https://influx[...].grafana.net/api/v1/push/influx/write"
uri = URI.parse(uri)
body = 'test,bar_label=abc,source=grafana_cloud_docs metric=35.2'
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |client|
request = Net::HTTP::Post.new(uri.path)
request.body = body
request["Authorization"] = "Basic #{BASE64_ENCODED_AUTH}"
request["Content-Type"] = "text/plain"
client.request(request)
end
data = response.code
puts data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment