grafana-oss

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Grafana OSS

Grafana OSS

Dashboard Provisioning

仪表板配置管理

yaml
undefined
yaml
undefined

provisioning/dashboards/default.yaml

provisioning/dashboards/default.yaml

apiVersion: 1 providers:
  • name: default folder: MyFolder type: file disableDeletion: false updateIntervalSeconds: 30 options: path: /var/lib/grafana/dashboards foldersFromFilesStructure: true
undefined
apiVersion: 1 providers:
  • name: default folder: MyFolder type: file disableDeletion: false updateIntervalSeconds: 30 options: path: /var/lib/grafana/dashboards foldersFromFilesStructure: true
undefined

Data Source Provisioning

数据源配置管理

yaml
undefined
yaml
undefined

provisioning/datasources/datasources.yaml

provisioning/datasources/datasources.yaml

apiVersion: 1 datasources:
  • name: Prometheus type: prometheus access: proxy url: http://prometheus:9090 isDefault: true jsonData: timeInterval: 15s httpMethod: POST
  • name: Loki type: loki access: proxy url: http://loki:3100
  • name: Tempo type: tempo access: proxy url: http://tempo:3200 jsonData: tracesToLogsV2: datasourceUid: loki_uid tags: [{ key: "service.name", value: "app" }] serviceMap: datasourceUid: prometheus_uid nodeGraph: enabled: true
  • name: Pyroscope type: grafana-pyroscope-datasource url: http://pyroscope:4040
undefined
apiVersion: 1 datasources:
  • name: Prometheus type: prometheus access: proxy url: http://prometheus:9090 isDefault: true jsonData: timeInterval: 15s httpMethod: POST
  • name: Loki type: loki access: proxy url: http://loki:3100
  • name: Tempo type: tempo access: proxy url: http://tempo:3200 jsonData: tracesToLogsV2: datasourceUid: loki_uid tags: [{ key: "service.name", value: "app" }] serviceMap: datasourceUid: prometheus_uid nodeGraph: enabled: true
  • name: Pyroscope type: grafana-pyroscope-datasource url: http://pyroscope:4040
undefined

Panel Types

面板类型

PanelUse Case
Time seriesLine/bar charts over time (default for metrics)
StatSingle value with color thresholds
GaugeRadial gauge for current value
Bar gaugeHorizontal bars for comparisons
TableTabular data, sortable columns
LogsLog stream viewer (Loki)
TracesTrace visualization (Tempo)
HeatmapDistribution over time
HistogramValue distribution
Pie chartPart-to-whole ratios
GeomapGeographic data
CanvasCustom SVG-based layouts
Node graphService/topology graphs
Flame graphCPU/memory profiling
TextMarkdown/HTML content
Alert listShow firing alerts
面板类型使用场景
Time series随时间变化的折线/柱状图(指标默认类型)
Stat带颜色阈值的单值展示
Gauge显示当前值的径向仪表盘
Bar gauge用于对比的水平条形图
Table可排序的表格数据
Logs日志流查看器(Loki)
Traces链路追踪可视化(Tempo)
Heatmap随时间变化的分布热力图
Histogram值分布直方图
Pie chart占比关系饼图
Geomap地理数据展示
Canvas基于SVG的自定义布局
Node graph服务/拓扑关系图
Flame graphCPU/内存分析火焰图
TextMarkdown/HTML内容展示
Alert list触发告警列表展示

Template Variables

模板变量

json
{
  "templating": {
    "list": [
      {
        "name": "namespace",
        "type": "query",
        "datasource": { "type": "prometheus", "uid": "prom" },
        "definition": "label_values(kube_pod_info, namespace)",
        "includeAll": true,
        "multi": true
      },
      {
        "name": "env",
        "type": "custom",
        "query": "production,staging,dev",
        "current": { "value": "production" }
      },
      {
        "name": "interval",
        "type": "interval",
        "query": "1m,5m,15m,1h",
        "auto": true
      }
    ]
  }
}
Use variables in queries:
rate(http_requests_total{namespace="$namespace"}[$interval])
json
{
  "templating": {
    "list": [
      {
        "name": "namespace",
        "type": "query",
        "datasource": { "type": "prometheus", "uid": "prom" },
        "definition": "label_values(kube_pod_info, namespace)",
        "includeAll": true,
        "multi": true
      },
      {
        "name": "env",
        "type": "custom",
        "query": "production,staging,dev",
        "current": { "value": "production" }
      },
      {
        "name": "interval",
        "type": "interval",
        "query": "1m,5m,15m,1h",
        "auto": true
      }
    ]
  }
}
在查询中使用变量:
rate(http_requests_total{namespace="$namespace"}[$interval])

Alerting Configuration (grafana.ini)

告警配置(grafana.ini)

ini
[alerting]
enabled = true

[unified_alerting]
enabled = true

[smtp]
enabled = true
host = smtp.gmail.com:587
user = alerts@example.com
password = yourpassword
from_address = alerts@example.com
ini
[alerting]
enabled = true

[unified_alerting]
enabled = true

[smtp]
enabled = true
host = smtp.gmail.com:587
user = alerts@example.com
password = yourpassword
from_address = alerts@example.com

Server Configuration (grafana.ini)

服务器配置(grafana.ini)

ini
[server]
http_port = 3000
domain = grafana.example.com
root_url = https://grafana.example.com/

[database]
type = postgres
host = postgres:5432
name = grafana
user = grafana
password = secret

[auth.generic_oauth]
enabled = true
name = Okta
client_id = your_client_id
client_secret = your_secret
auth_url = https://your-org.okta.com/oauth2/v1/authorize
token_url = https://your-org.okta.com/oauth2/v1/token
api_url = https://your-org.okta.com/oauth2/v1/userinfo
scopes = openid profile email groups

[security]
admin_user = admin
admin_password = secret
allow_embedding = true       # for embedding dashboards

[feature_toggles]
enable = publicDashboards
ini
[server]
http_port = 3000
domain = grafana.example.com
root_url = https://grafana.example.com/

[database]
type = postgres
host = postgres:5432
name = grafana
user = grafana
password = secret

[auth.generic_oauth]
enabled = true
name = Okta
client_id = your_client_id
client_secret = your_secret
auth_url = https://your-org.okta.com/oauth2/v1/authorize
token_url = https://your-org.okta.com/oauth2/v1/token
api_url = https://your-org.okta.com/oauth2/v1/userinfo
scopes = openid profile email groups

[security]
admin_user = admin
admin_password = secret
allow_embedding = true       # 用于嵌入仪表板

[feature_toggles]
enable = publicDashboards

RBAC

RBAC权限管理

Built-in Roles

内置角色

RolePermissions
ViewerRead dashboards, alerts
EditorCreate/edit dashboards, alerts
AdminManage data sources, users, plugins
GrafanaAdminServer-wide admin (superuser)
角色权限
Viewer查看仪表板、告警
Editor创建/编辑仪表板、告警
Admin管理数据源、用户、插件
GrafanaAdmin服务器级超级管理员

Service Account Provisioning

服务账号配置管理

yaml
undefined
yaml
undefined

provisioning/access-control/service_accounts.yaml

provisioning/access-control/service_accounts.yaml

apiVersion: 1 serviceAccounts:
  • name: ci-reader orgId: 1 role: Viewer tokens:
    • name: ci-token expires: 2025-01-01T00:00:00Z
undefined
apiVersion: 1 serviceAccounts:
  • name: ci-reader orgId: 1 role: Viewer tokens:
    • name: ci-token expires: 2025-01-01T00:00:00Z
undefined

Custom RBAC Roles (Enterprise / Cloud)

自定义RBAC角色(企业版/云版)

yaml
undefined
yaml
undefined

provisioning/access-control/roles.yaml

provisioning/access-control/roles.yaml

apiVersion: 1 roles:
  • name: DashboardEditor description: Can create and edit dashboards permissions:
    • action: dashboards:create
    • action: dashboards:write scope: dashboards:*
    • action: folders:read scope: folders:*
undefined
apiVersion: 1 roles:
  • name: DashboardEditor description: Can create and edit dashboards permissions:
    • action: dashboards:create
    • action: dashboards:write scope: dashboards:*
    • action: folders:read scope: folders:*
undefined

Dashboard JSON Model

仪表板JSON模型

json
{
  "title": "Service Overview",
  "uid": "service-overview",
  "time": { "from": "now-1h", "to": "now" },
  "refresh": "30s",
  "panels": [
    {
      "type": "timeseries",
      "title": "Request Rate",
      "gridPos": { "x": 0, "y": 0, "w": 12, "h": 8 },
      "targets": [
        {
          "datasource": { "type": "prometheus" },
          "expr": "rate(http_requests_total{job=\"$job\"}[5m])",
          "legendFormat": "{{method}} {{status}}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "red", "value": 1000 }
            ]
          }
        }
      }
    }
  ]
}
json
{
  "title": "Service Overview",
  "uid": "service-overview",
  "time": { "from": "now-1h", "to": "now" },
  "refresh": "30s",
  "panels": [
    {
      "type": "timeseries",
      "title": "Request Rate",
      "gridPos": { "x": 0, "y": 0, "w": 12, "h": 8 },
      "targets": [
        {
          "datasource": { "type": "prometheus" },
          "expr": "rate(http_requests_total{job=\"$job\"}[5m])",
          "legendFormat": "{{method}} {{status}}"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "red", "value": 1000 }
            ]
          }
        }
      }
    }
  ]
}

Annotations

注释

bash
undefined
bash
undefined

Create annotation via API

通过API创建注释

curl -X POST https://grafana.example.com/api/annotations
-H 'Authorization: Bearer <token>'
-H 'Content-Type: application/json'
-d '{ "dashboardUID": "service-overview", "panelId": 1, "time": 1706745600000, "timeEnd": 1706749200000, "tags": ["deploy", "v2.0"], "text": "Deployed v2.0" }'
undefined
curl -X POST https://grafana.example.com/api/annotations
-H 'Authorization: Bearer <token>'
-H 'Content-Type: application/json'
-d '{ "dashboardUID": "service-overview", "panelId": 1, "time": 1706745600000, "timeEnd": 1706749200000, "tags": ["deploy", "v2.0"], "text": "Deployed v2.0" }'
undefined

Plugin Provisioning

插件配置管理

yaml
undefined
yaml
undefined

provisioning/plugins/plugins.yaml

provisioning/plugins/plugins.yaml

apiVersion: 1 apps:
undefined
apiVersion: 1 apps:
undefined

Key API Endpoints

核心API端点

bash
undefined
bash
undefined

Search dashboards

搜索仪表板

GET /api/search?query=service&type=dash-db&folderIds=1
GET /api/search?query=service&type=dash-db&folderIds=1

Get dashboard

获取仪表板

GET /api/dashboards/uid/{uid}
GET /api/dashboards/uid/{uid}

Create/update dashboard

创建/更新仪表板

POST /api/dashboards/db { "dashboard": {...}, "folderUID": "...", "overwrite": true }
POST /api/dashboards/db { "dashboard": {...}, "folderUID": "...", "overwrite": true }

List data sources

列出数据源

GET /api/datasources
GET /api/datasources

Create data source

创建数据源

POST /api/datasources
POST /api/datasources

List users

列出用户

GET /api/org/users
GET /api/org/users

Create service account token

创建服务账号令牌

POST /api/serviceaccounts/{id}/tokens
undefined
POST /api/serviceaccounts/{id}/tokens
undefined