testing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Grafana Cloud Testing

Grafana Cloud 测试

Synthetic Monitoring

合成监控

Monitor uptime and performance from 20+ global locations without deploying your own agents.
无需部署自有代理,从20+全球位置监控正常运行时间和性能。

Check Types

检查类型

CheckUse Case
HTTPWebsite and API availability, response validation
DNSDNS resolution time and record validation
TCPPort/service connectivity
PingICMP availability
TracerouteNetwork path diagnostics
MultihttpMulti-step HTTP flows
Scripted (k6 browser)Full browser-based user flow testing
检查类型适用场景
HTTP网站和API可用性、响应验证
DNSDNS解析时间和记录验证
TCP端口/服务连通性
PingICMP可用性
Traceroute网络路径诊断
Multihttp多步骤HTTP流程
Scripted (k6 browser)基于完整浏览器的用户流测试

HTTP Check Configuration (API)

HTTP检查配置(API)

bash
curl -X POST https://synthetic-monitoring-api.grafana.net/sm/checks \
  -H "Authorization: Bearer <sm-access-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "job": "website",
    "target": "https://example.com",
    "frequency": 60000,
    "timeout": 15000,
    "enabled": true,
    "probes": [1, 5, 10],
    "settings": {
      "http": {
        "method": "GET",
        "ipVersion": "V4",
        "noFollowRedirects": false,
        "tlsConfig": {},
        "validStatusCodes": [200, 201],
        "validHTTPVersions": ["HTTP/1.1", "HTTP/2.0"],
        "failIfBodyMatchesRegexp": ["error", "exception"],
        "failIfBodyNotMatchesRegexp": ["OK"],
        "headers": [{"name": "User-Agent", "value": "Grafana-Synthetic-Monitoring"}]
      }
    }
  }'
bash
curl -X POST https://synthetic-monitoring-api.grafana.net/sm/checks \
  -H "Authorization: Bearer <sm-access-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "job": "website",
    "target": "https://example.com",
    "frequency": 60000,
    "timeout": 15000,
    "enabled": true,
    "probes": [1, 5, 10],
    "settings": {
      "http": {
        "method": "GET",
        "ipVersion": "V4",
        "noFollowRedirects": false,
        "tlsConfig": {},
        "validStatusCodes": [200, 201],
        "validHTTPVersions": ["HTTP/1.1", "HTTP/2.0"],
        "failIfBodyMatchesRegexp": ["error", "exception"],
        "failIfBodyNotMatchesRegexp": ["OK"],
        "headers": [{"name": "User-Agent", "value": "Grafana-Synthetic-Monitoring"}]
      }
    }
  }'

Synthetic Monitoring Metrics

合成监控指标

promql
undefined
promql
undefined

Probe success rate

Probe success rate

sum(rate(probe_success[5m])) by (job, instance, probe)
sum(rate(probe_success[5m])) by (job, instance, probe)

HTTP response time p95

HTTP response time p95

histogram_quantile(0.95, sum(rate(probe_duration_seconds_bucket[5m])) by (le, job))
histogram_quantile(0.95, sum(rate(probe_duration_seconds_bucket[5m])) by (le, job))

DNS lookup time

DNS lookup time

avg(probe_dns_lookup_time_seconds) by (job, instance)
avg(probe_dns_lookup_time_seconds) by (job, instance)

TLS expiry days remaining

TLS expiry days remaining

(probe_ssl_earliest_cert_expiry - time()) / 86400
undefined
(probe_ssl_earliest_cert_expiry - time()) / 86400
undefined

Alert on Synthetic Monitoring

合成监控告警配置

yaml
groups:
  - name: synthetic-monitoring
    rules:
      - alert: SyntheticCheckFailing
        expr: avg_over_time(probe_success[5m]) < 0.9
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "{{ $labels.job }} failing from {{ $labels.probe }}"

      - alert: TLSCertExpiringSoon
        expr: (probe_ssl_earliest_cert_expiry - time()) / 86400 < 14
        labels:
          severity: warning
        annotations:
          summary: "TLS cert for {{ $labels.instance }} expires in {{ $value }} days"
yaml
groups:
  - name: synthetic-monitoring
    rules:
      - alert: SyntheticCheckFailing
        expr: avg_over_time(probe_success[5m]) < 0.9
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "{{ $labels.job }} failing from {{ $labels.probe }}"

      - alert: TLSCertExpiringSoon
        expr: (probe_ssl_earliest_cert_expiry - time()) / 86400 < 14
        labels:
          severity: warning
        annotations:
          summary: "TLS cert for {{ $labels.instance }} expires in {{ $value }} days"

k6 Cloud (Grafana Cloud k6)

k6 Cloud(Grafana Cloud k6)

Run distributed load tests from multiple AWS regions without managing infrastructure.
无需管理基础设施,从多个AWS区域运行分布式负载测试。

k6 Script for Cloud

适用于云环境的k6脚本

javascript
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  cloud: {
    projectID: 3456789,
    name: 'API Load Test - Release v2.0',
    distribution: {
      loadZone1: { loadZone: 'amazon:us:ashburn', percent: 50 },
      loadZone2: { loadZone: 'amazon:eu:dublin', percent: 30 },
      loadZone3: { loadZone: 'amazon:ap:tokyo', percent: 20 },
    },
  },
  scenarios: {
    load: {
      executor: 'ramping-vus',
      startVUs: 0,
      stages: [
        { duration: '2m', target: 100 },
        { duration: '10m', target: 100 },
        { duration: '2m', target: 0 },
      ],
    },
  },
  thresholds: {
    http_req_duration: ['p(95)<500'],
    http_req_failed: ['rate<0.01'],
  },
};

export default function () {
  const res = http.get('https://api.example.com/users');
  check(res, {
    'status 200': (r) => r.status === 200,
    'fast': (r) => r.timings.duration < 500,
  });
  sleep(1);
}
bash
undefined
javascript
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  cloud: {
    projectID: 3456789,
    name: 'API Load Test - Release v2.0',
    distribution: {
      loadZone1: { loadZone: 'amazon:us:ashburn', percent: 50 },
      loadZone2: { loadZone: 'amazon:eu:dublin', percent: 30 },
      loadZone3: { loadZone: 'amazon:ap:tokyo', percent: 20 },
    },
  },
  scenarios: {
    load: {
      executor: 'ramping-vus',
      startVUs: 0,
      stages: [
        { duration: '2m', target: 100 },
        { duration: '10m', target: 100 },
        { duration: '2m', target: 0 },
      ],
    },
  },
  thresholds: {
    http_req_duration: ['p(95)<500'],
    http_req_failed: ['rate<0.01'],
  },
};

export default function () {
  const res = http.get('https://api.example.com/users');
  check(res, {
    'status 200': (r) => r.status === 200,
    'fast': (r) => r.timings.duration < 500,
  });
  sleep(1);
}
bash
undefined

Authenticate

Authenticate

k6 cloud login --token <your-grafana-cloud-token>
k6 cloud login --token <your-grafana-cloud-token>

Run in cloud

Run in cloud

k6 cloud script.js
k6 cloud script.js

Run locally but stream to cloud

Run locally but stream to cloud

k6 run --out cloud script.js
undefined
k6 run --out cloud script.js
undefined

k6 Cloud Test Runs API

k6 Cloud测试运行API

bash
undefined
bash
undefined

List test runs

List test runs

curl https://api.k6.io/v3/projects/{projectId}/test-runs
-H "Authorization: Token <token>"
curl https://api.k6.io/v3/projects/{projectId}/test-runs
-H "Authorization: Token <token>"

Get test run results

Get test run results

curl https://api.k6.io/v3/runs/{runId}
-H "Authorization: Token <token>"
curl https://api.k6.io/v3/runs/{runId}
-H "Authorization: Token <token>"

Stop a running test

Stop a running test

curl -X POST https://api.k6.io/v3/runs/{runId}/stop
-H "Authorization: Token <token>"
undefined
curl -X POST https://api.k6.io/v3/runs/{runId}/stop
-H "Authorization: Token <token>"
undefined

CI/CD Integration

CI/CD集成

yaml
undefined
yaml
undefined

GitHub Actions

GitHub Actions

  • name: Run k6 Load Test uses: grafana/k6-action@v0.3.1 with: filename: tests/load.js cloud: true token: ${{ secrets.K6_CLOUD_TOKEN }} flags: --out cloud
undefined
  • name: Run k6 Load Test uses: grafana/k6-action@v0.3.1 with: filename: tests/load.js cloud: true token: ${{ secrets.K6_CLOUD_TOKEN }} flags: --out cloud
undefined

Frontend Observability (Faro / RUM)

前端可观测性(Faro / RUM)

javascript
// Initialize Faro in your web app
import { initializeFaro, getWebInstrumentations } from '@grafana/faro-web-sdk';
import { TracingInstrumentation } from '@grafana/faro-web-tracing';

const faro = initializeFaro({
  url: 'https://faro-collector-prod-xx.grafana.net/collect',
  apiKey: 'your-faro-api-key',
  app: {
    name: 'my-frontend',
    version: '1.0.0',
    environment: 'production',
  },
  instrumentations: [
    ...getWebInstrumentations({
      captureConsole: true,
      captureConsoleDisabledLevels: [],
    }),
    new TracingInstrumentation(),
  ],
});

// Custom events
faro.api.pushEvent('checkout_completed', { cart_value: '99.99' });

// Custom measurements
faro.api.pushMeasurement({ type: 'api_latency', values: { ms: 234 } });

// Error capturing
faro.api.pushError(new Error('Payment failed'));
bash
undefined
javascript
// Initialize Faro in your web app
import { initializeFaro, getWebInstrumentations } from '@grafana/faro-web-sdk';
import { TracingInstrumentation } from '@grafana/faro-web-tracing';

const faro = initializeFaro({
  url: 'https://faro-collector-prod-xx.grafana.net/collect',
  apiKey: 'your-faro-api-key',
  app: {
    name: 'my-frontend',
    version: '1.0.0',
    environment: 'production',
  },
  instrumentations: [
    ...getWebInstrumentations({
      captureConsole: true,
      captureConsoleDisabledLevels: [],
    }),
    new TracingInstrumentation(),
  ],
});

// Custom events
faro.api.pushEvent('checkout_completed', { cart_value: '99.99' });

// Custom measurements
faro.api.pushMeasurement({ type: 'api_latency', values: { ms: 234 } });

// Error capturing
faro.api.pushError(new Error('Payment failed'));
bash
undefined

Install

Install

npm install @grafana/faro-web-sdk @grafana/faro-web-tracing
undefined
npm install @grafana/faro-web-sdk @grafana/faro-web-tracing
undefined