/grafana-by-example-remote-write

Examples of remote writing telemetry data to Grafana Metics, Logs and Traces

Primary LanguagePythonGNU Affero General Public License v3.0AGPL-3.0

grafana-by-example-remote-write

Examples of remote writing telemetry data to Grafana Metics, Logs and Traces

Remote write to Grafana Cloud Metrics endpoint

Example Python script to demonstrate remote write to a Grafana Cloud Metrics endpoint

Uses protocol buffer messages defined from Prometheus prompb and gogoprotobuf

Required environment variables

Configure these from the Grafana Cloud account:

File: envvars-grafana-cloud.sh

export GRAFANA_METRICS_URL="https://prometheus-prod-10-prod-us-central-0.grafana.net/api/prom/push"
export GRAFANA_METRICS_USERNAME="[REQUIRED]"
export GRAFANA_METRICS_API_KEY="[REQUIRED]"

Required environment

  • Python3
  • Google Protocol Buffer compiler
  • pip3 install python-snappy
  • pip3 install requests

Example usage

Install the Protocol Buffer compiler, protoc using:

# On macOS:
brew install protobuf
pip3 install --upgrade protobuf
pip3 install python-snappy requests
# Download the gogo.proto, remote.proto and types.proto
./ctl.sh configure

# Build the Python protobuf libraries
./ctl.sh build-pb

# Source the environment variables for the Grafana Cloud Prometheus endpoint
source envvars-grafana-cloud.sh

# Run the example
python3 metrics-generator.py single 5 100

Validate the metrics have be received at the Grafana Cloud Prometheus instance under the labels:

job="test1"
test1_http_errors_total{}
test1_http_requests_total{}

Reference Documents