building-dashboards 是做什麼的?
透過 API 設計與建構 Axiom 儀表板。涵蓋圖表類型、APL 和指標/MPL 查詢模式、智慧篩選器、版面配置及設定選項。適合用於建立儀表板、從 Splunk 遷移或設定圖表選項。
概述
此技能提供建立、取得、更新與刪除 Axiom 儀表板的指南。儀表板是一種資料視覺化工具,可將查詢結果以圖表、表格或數值形式呈現。每個儀表板由多個面板組成,每個面板包含一個或多個圖表。此處涵蓋的儀表板定義格式與 Axiom API 完全相容。
支援的平台
- Axiom(主要)
- 任何可透過 HTTP 呼叫 Axiom API 的環境
使用方法
- 準備一個包含儀表板定義的 JSON 檔案。
- 使用
POST /v1/dashboardsAPI 端點來建立儀表板。 - 使用
PUT /v1/dashboards/{id}來更新現有儀表板。 - 使用
DELETE /v1/dashboards/{id}來刪除儀表板。
儀表板結構
儀表板定義包含以下主要部分:
- id:唯一的儀表板識別碼(UUID)。
- name:儀表板名稱。
- description:選擇性的說明文字。
- timeRange:預設的時間範圍。
- charts:圖表定義的陣列。
- variables:全域變數(選擇性)。
- smartFilters:智慧篩選器(選擇性)。
- layout:頁面與面板的版面配置。
圖表類型
支援以下圖表類型:
| 類型 | 說明 |
|---|---|
timeseries | 時間序列圖(折線圖或區域圖) |
numeric | 單一數值 |
list | 列出資料點 |
table | 表格檢視 |
bar | 長條圖 |
count | 計數圖 |
查詢模式
APL 查詢
APL(Axiom 處理語言)用於查詢事件日誌資料。範例:
'my-dataset'
| where ['status'] == "error"
| summarize count() by ['service']
指標/MPL 查詢
MPL(指標查詢語言)用於查詢指標資料。範例:
rate(container_cpu_usage_seconds_total[5m])
智慧篩選器
智慧篩選器可讓使用者動態篩選儀表板資料。它們在 smartFilters 區塊中定義:
{
"smartFilters": [
{
"field": "service",
"title": "服務",
"values": []
}
]
}
版面配置
版面配置以巢狀格式定義頁面與面板。頁面包含面板,每個面板可包含一個或多個圖表。
{
"layout": [
{
"title": "概覽頁面",
"panels": [
{
"title": "錯誤率",
"chartIds": ["chart-1", "chart-2"]
}
]
}
]
}
組態選項
每個圖表類型都有特定的組態選項:
- timeseries:
showLegend、stackMode、nullValueTreatment - bar:
orientation、showValues - table:
columnSettings、showRowNumbers - numeric:
prefix、suffix、decimalPlaces - list:
maxItems、sortBy - count:
groupBy
從 Splunk 遷移
從 Splunk 遷移時,請依照以下步驟操作:
- 將 Splunk 查詢轉換為 APL。
- 將 Splunk 儀表板 XML 轉換為 Axiom JSON 格式。
- 透過 API 建立新的儀表板。
- 驗證資料是否正確呈現。
範例
建立一個簡單儀表板
{
"name": "服務監控",
"description": "監控服務健康狀態",
"timeRange": {
"type": "relative",
"value": 3600000
},
"charts": [
{
"id": "chart-1",
"type": "timeseries",
"query": {
"apl": "'my-dataset' | summarize count() by ['status']"
},
"options": {
"showLegend": true,
"stackMode": "none"
}
}
],
"layout": [
{
"panels": [
{
"chartIds": ["chart-1"]
}
]
}
]
}
使用變數
{
"variables": [
{
"name": "service",
"type": "query",
"query": {
"apl": "'my-dataset' | distinct ['service']"
}
}
]
}