send-data
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSending Data to Grafana Cloud
向Grafana Cloud发送数据
Quick Start: Find Your Credentials
快速开始:查找凭证
In Grafana Cloud portal → My Account → Stack → Details:
| Signal | Credential Fields |
|---|---|
| Metrics | Prometheus remote write URL, username, password/API key |
| Logs | Loki URL, username, password/API key |
| Traces | Tempo OTLP endpoint, username, password/API key |
| Profiles | Pyroscope URL, username, password/API key |
在Grafana Cloud门户中 → 我的账户 → Stack → 详情:
| 信号类型 | 凭证字段 |
|---|---|
| 指标 | Prometheus remote write URL, username, password/API key |
| 日志 | Loki URL, username, password/API key |
| 追踪数据 | Tempo OTLP endpoint, username, password/API key |
| 性能剖析数据 | Pyroscope URL, username, password/API key |
Alloy (Recommended — All Signals)
Alloy(推荐方案——支持所有信号类型)
alloy
// METRICS
prometheus.scrape "app" {
targets = [{"__address__" = "localhost:8080"}]
forward_to = [prometheus.remote_write.cloud.receiver]
}
prometheus.remote_write "cloud" {
endpoint {
url = "https://prometheus-prod-xx.grafana.net/api/prom/push"
basic_auth {
username = sys.env("PROM_USER")
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
}
}
// LOGS
loki.source.file "app" {
targets = [{__path__ = "/var/log/app/*.log", job = "app"}]
forward_to = [loki.write.cloud.receiver]
}
loki.write "cloud" {
endpoint {
url = "https://logs-prod-xx.grafana.net/loki/api/v1/push"
basic_auth {
username = sys.env("LOKI_USER")
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
}
}
// TRACES (OTLP receive → forward)
otelcol.receiver.otlp "default" {
grpc { endpoint = "0.0.0.0:4317" }
http { endpoint = "0.0.0.0:4318" }
output {
traces = [otelcol.exporter.otlp.cloud.input]
}
}
otelcol.exporter.otlp "cloud" {
client {
endpoint = "tempo-prod-xx.grafana.net:443"
auth = otelcol.auth.basic.cloud.handler
}
}
otelcol.auth.basic "cloud" {
username = sys.env("TEMPO_USER")
password = sys.env("GRAFANA_CLOUD_API_KEY")
}alloy
// METRICS
prometheus.scrape "app" {
targets = [{"__address__" = "localhost:8080"}]
forward_to = [prometheus.remote_write.cloud.receiver]
}
prometheus.remote_write "cloud" {
endpoint {
url = "https://prometheus-prod-xx.grafana.net/api/prom/push"
basic_auth {
username = sys.env("PROM_USER")
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
}
}
// LOGS
loki.source.file "app" {
targets = [{__path__ = "/var/log/app/*.log", job = "app"}]
forward_to = [loki.write.cloud.receiver]
}
loki.write "cloud" {
endpoint {
url = "https://logs-prod-xx.grafana.net/loki/api/v1/push"
basic_auth {
username = sys.env("LOKI_USER")
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
}
}
// TRACES (OTLP receive → forward)
otelcol.receiver.otlp "default" {
grpc { endpoint = "0.0.0.0:4317" }
http { endpoint = "0.0.0.0:4318" }
output {
traces = [otelcol.exporter.otlp.cloud.input]
}
}
otelcol.exporter.otlp "cloud" {
client {
endpoint = "tempo-prod-xx.grafana.net:443"
auth = otelcol.auth.basic.cloud.handler
}
}
otelcol.auth.basic "cloud" {
username = sys.env("TEMPO_USER")
password = sys.env("GRAFANA_CLOUD_API_KEY")
}Direct Prometheus Remote Write
直接使用Prometheus远程写入
yaml
undefinedyaml
undefinedprometheus.yml
prometheus.yml
remote_write:
- url: https://prometheus-prod-xx.grafana.net/api/prom/push
basic_auth:
username: "123456"
password: "your-api-key"
write_relabel_configs:
- source_labels: [name] regex: "go_.*" action: drop # optional: drop high-cardinality metrics
undefinedremote_write:
- url: https://prometheus-prod-xx.grafana.net/api/prom/push
basic_auth:
username: "123456"
password: "your-api-key"
write_relabel_configs:
- source_labels: [name] regex: "go_.*" action: drop # optional: drop high-cardinality metrics
undefinedDirect Loki Push (curl)
直接使用Loki推送(curl)
bash
curl -X POST https://logs-prod-xx.grafana.net/loki/api/v1/push \
-H "Content-Type: application/json" \
-u "123456:your-api-key" \
-d '{
"streams": [{
"stream": { "app": "myapp", "env": "prod" },
"values": [
["1706745600000000000", "application started"]
]
}]
}'bash
curl -X POST https://logs-prod-xx.grafana.net/loki/api/v1/push \
-H "Content-Type: application/json" \
-u "123456:your-api-key" \
-d '{
"streams": [{
"stream": { "app": "myapp", "env": "prod" },
"values": [
["1706745600000000000", "application started"]
]
}]
}'OpenTelemetry SDK → Grafana Cloud
OpenTelemetry SDK 接入Grafana Cloud
bash
undefinedbash
undefinedEnvironment variables for OTLP export
Environment variables for OTLP export
export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-xx.grafana.net/otlp"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic $(echo -n '123456:your-api-key' | base64)"
export OTEL_SERVICE_NAME="my-service"
Python example:
```python
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
provider = TracerProvider()
exporter = OTLPSpanExporter() # reads OTEL_EXPORTER_OTLP_* env vars
provider.add_span_processor(BatchSpanProcessor(exporter))
trace.set_tracer_provider(provider)export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-xx.grafana.net/otlp"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic $(echo -n '123456:your-api-key' | base64)"
export OTEL_SERVICE_NAME="my-service"
Python示例:
```python
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
provider = TracerProvider()
exporter = OTLPSpanExporter() # reads OTEL_EXPORTER_OTLP_* env vars
provider.add_span_processor(BatchSpanProcessor(exporter))
trace.set_tracer_provider(provider)Cloud Integrations
云集成
Pre-built integrations for common infrastructure (install from Grafana Cloud UI or API):
bash
undefined针对常见基础设施的预构建集成(可从Grafana Cloud UI或API安装):
bash
undefinedList available integrations
List available integrations
curl https://integrations-api-prod.grafana.net/api/v1/integrations
-H "Authorization: Bearer <api-key>"
-H "Authorization: Bearer <api-key>"
curl https://integrations-api-prod.grafana.net/api/v1/integrations
-H "Authorization: Bearer <api-key>"
-H "Authorization: Bearer <api-key>"
Install AWS CloudWatch integration
Install AWS CloudWatch integration
curl -X POST https://integrations-api-prod.grafana.net/api/v1/integrations/cloudwatch
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"name": "aws-prod", "config": {...}}'
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"name": "aws-prod", "config": {...}}'
Popular integrations: AWS CloudWatch, Azure Monitor, GCP, Kubernetes, Docker, MySQL, PostgreSQL, Redis, Nginx, Apache, JVM, Node.js, Python, .NET.curl -X POST https://integrations-api-prod.grafana.net/api/v1/integrations/cloudwatch
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"name": "aws-prod", "config": {...}}'
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"name": "aws-prod", "config": {...}}'
热门集成:AWS CloudWatch、Azure Monitor、GCP、Kubernetes、Docker、MySQL、PostgreSQL、Redis、Nginx、Apache、JVM、Node.js、Python、.NET。Kubernetes Agent Operator
Kubernetes代理操作器
yaml
undefinedyaml
undefinedvalues.yaml for grafana/k8s-monitoring Helm chart
values.yaml for grafana/k8s-monitoring Helm chart
cluster:
name: production
externalServices:
prometheus:
host: https://prometheus-prod-xx.grafana.net
basicAuth:
username: "123456"
password:
secretName: grafana-cloud-secret
secretKey: api-key
loki:
host: https://logs-prod-xx.grafana.net
basicAuth:
username: "234567"
password:
secretName: grafana-cloud-secret
secretKey: api-key
metrics:
enabled: true
podMonitors:
enabled: true
serviceMonitors:
enabled: true
logs:
pod_logs:
enabled: true
traces:
enabled: true
```bash
helm install k8s-monitoring grafana/k8s-monitoring \
-n monitoring --create-namespace \
-f values.yamlcluster:
name: production
externalServices:
prometheus:
host: https://prometheus-prod-xx.grafana.net
basicAuth:
username: "123456"
password:
secretName: grafana-cloud-secret
secretKey: api-key
loki:
host: https://logs-prod-xx.grafana.net
basicAuth:
username: "234567"
password:
secretName: grafana-cloud-secret
secretKey: api-key
metrics:
enabled: true
podMonitors:
enabled: true
serviceMonitors:
enabled: true
logs:
pod_logs:
enabled: true
traces:
enabled: true
```bash
helm install k8s-monitoring grafana/k8s-monitoring \
-n monitoring --create-namespace \
-f values.yamlAPI Key Management
API密钥管理
bash
undefinedbash
undefinedCreate API key via Grafana API
Create API key via Grafana API
curl -X POST https://yourstack.grafana.net/api/auth/keys
-H "Content-Type: application/json"
-u "admin:adminpassword"
-d '{"name": "alloy-writer", "role": "MetricsPublisher", "secondsToLive": 0}'
-H "Content-Type: application/json"
-u "admin:adminpassword"
-d '{"name": "alloy-writer", "role": "MetricsPublisher", "secondsToLive": 0}'
Roles for data ingestion: `MetricsPublisher`, `LogsPublisher`, `TracesPublisher`, `ProfilesPublisher`curl -X POST https://yourstack.grafana.net/api/auth/keys
-H "Content-Type: application/json"
-u "admin:adminpassword"
-d '{"name": "alloy-writer", "role": "MetricsPublisher", "secondsToLive": 0}'
-H "Content-Type: application/json"
-u "admin:adminpassword"
-d '{"name": "alloy-writer", "role": "MetricsPublisher", "secondsToLive": 0}'
数据摄取相关角色:`MetricsPublisher`、`LogsPublisher`、`TracesPublisher`、`ProfilesPublisher`