Examples of remote writing telemetry data to Grafana Metics, Logs and Traces
Example Python script to demonstrate remote write to a Grafana Cloud Metrics endpoint
Uses protocol buffer messages defined from Prometheus prompb and gogoprotobuf
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]"
- Python3
- Google Protocol Buffer compiler
- pip3 install python-snappy
- pip3 install requests
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{}
- Google Protocol Buffer Guide
- Protocol Buffer Basics: Python Guide
- Protobuf definitions for the OpenTelemetry protocol (OTLP) metrics.proto
- OpenTelemetry Prometheus Remote Write Exporter Python Package
- Prometheus Potocol Buffer prompb
- Promethues Metrics Grafana Cloud