grafana-oss
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGrafana OSS
Grafana OSS
Dashboard Provisioning
仪表板配置管理
yaml
undefinedyaml
undefinedprovisioning/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
undefinedapiVersion: 1
providers:
- name: default folder: MyFolder type: file disableDeletion: false updateIntervalSeconds: 30 options: path: /var/lib/grafana/dashboards foldersFromFilesStructure: true
undefinedData Source Provisioning
数据源配置管理
yaml
undefinedyaml
undefinedprovisioning/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
undefinedapiVersion: 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
undefinedPanel Types
面板类型
| Panel | Use Case |
|---|---|
| Time series | Line/bar charts over time (default for metrics) |
| Stat | Single value with color thresholds |
| Gauge | Radial gauge for current value |
| Bar gauge | Horizontal bars for comparisons |
| Table | Tabular data, sortable columns |
| Logs | Log stream viewer (Loki) |
| Traces | Trace visualization (Tempo) |
| Heatmap | Distribution over time |
| Histogram | Value distribution |
| Pie chart | Part-to-whole ratios |
| Geomap | Geographic data |
| Canvas | Custom SVG-based layouts |
| Node graph | Service/topology graphs |
| Flame graph | CPU/memory profiling |
| Text | Markdown/HTML content |
| Alert list | Show firing alerts |
| 面板类型 | 使用场景 |
|---|---|
| Time series | 随时间变化的折线/柱状图(指标默认类型) |
| Stat | 带颜色阈值的单值展示 |
| Gauge | 显示当前值的径向仪表盘 |
| Bar gauge | 用于对比的水平条形图 |
| Table | 可排序的表格数据 |
| Logs | 日志流查看器(Loki) |
| Traces | 链路追踪可视化(Tempo) |
| Heatmap | 随时间变化的分布热力图 |
| Histogram | 值分布直方图 |
| Pie chart | 占比关系饼图 |
| Geomap | 地理数据展示 |
| Canvas | 基于SVG的自定义布局 |
| Node graph | 服务/拓扑关系图 |
| Flame graph | CPU/内存分析火焰图 |
| Text | Markdown/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.comini
[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.comServer 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 = publicDashboardsini
[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 = publicDashboardsRBAC
RBAC权限管理
Built-in Roles
内置角色
| Role | Permissions |
|---|---|
| Viewer | Read dashboards, alerts |
| Editor | Create/edit dashboards, alerts |
| Admin | Manage data sources, users, plugins |
| GrafanaAdmin | Server-wide admin (superuser) |
| 角色 | 权限 |
|---|---|
| Viewer | 查看仪表板、告警 |
| Editor | 创建/编辑仪表板、告警 |
| Admin | 管理数据源、用户、插件 |
| GrafanaAdmin | 服务器级超级管理员 |
Service Account Provisioning
服务账号配置管理
yaml
undefinedyaml
undefinedprovisioning/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
undefinedapiVersion: 1
serviceAccounts:
- name: ci-reader
orgId: 1
role: Viewer
tokens:
- name: ci-token expires: 2025-01-01T00:00:00Z
undefinedCustom RBAC Roles (Enterprise / Cloud)
自定义RBAC角色(企业版/云版)
yaml
undefinedyaml
undefinedprovisioning/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:*
undefinedapiVersion: 1
roles:
- name: DashboardEditor
description: Can create and edit dashboards
permissions:
- action: dashboards:create
- action: dashboards:write scope: dashboards:*
- action: folders:read scope: folders:*
undefinedDashboard 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
undefinedbash
undefinedCreate 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" }'
-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" }'
undefinedcurl -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" }'
-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" }'
undefinedPlugin Provisioning
插件配置管理
yaml
undefinedyaml
undefinedprovisioning/plugins/plugins.yaml
provisioning/plugins/plugins.yaml
apiVersion: 1
apps:
- type: grafana-pyroscope-app disabled: false jsonData: backendUrl: http://pyroscope:4040
undefinedapiVersion: 1
apps:
- type: grafana-pyroscope-app disabled: false jsonData: backendUrl: http://pyroscope:4040
undefinedKey API Endpoints
核心API端点
bash
undefinedbash
undefinedSearch 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
undefinedPOST /api/serviceaccounts/{id}/tokens
undefined