全部產品
Search
文件中心

Simple Log Service:SPL指令

更新時間:Apr 29, 2025

本文主要介紹時序SPL指令的詳細資料。

SPL指令列表

指令名稱

說明

make-series

將Table資料構建成Series資料。

render

將SPL查詢結果渲染為圖表以實現可視化。

make-series

將table構建為series結構。

文法

| make-series  <output> = <field-col> [default = <default-value>]
             [, ...]
             on <time-col>
             [from <time-begin> to <time-end>
              step <step-value>]
             [by <tag-col>,...]

指令塊

指令塊

必填

說明

<output> = <field-col> , ...

被轉換為series的欄位列,可以選擇多列。

on <time-col>

時間含義的欄位列。

[default = <default-value>]

&

[from <time-begin> to <time-end>

step <step-value>]

根據time列進行缺失值填充。包含截取的time範圍、填充步長和填充策略。

[by <tag-col>,...]

按指定的tag列作彙總。

參數說明

參數

類型

說明

output

Field

輸出彙總後的欄位。

field-col

Field

輸入的欄位列。

default-value

String

缺失值填充方式。

可選值:

  • null: 以null填補缺失的資料點。

  • nan:以nan填補缺失的浮點數。

  • 0:以0填補缺失的資料點。

  • last:使用最後觀察到的值來填補缺失的資料點,也稱為前向填充。前向填充適用於當您預期缺失的資料在新的觀察出現之前邏輯上保持最後已知狀態的情況下。它通常用於值被認為在更新之前保持不變的情境。

  • next:使用下一個觀察到的值來填補缺失的資料點,也稱為後向填充。適用於當資料可能被認為在某個未來狀態下存在,然後才被明確觀察到的情況。當歷史值被認為與下一個觀察值相同時,可以使用後向填充。

  • avg:使用前一個時間點和後一個時間點的平均值來填補缺失的資料點。

time-col

Field

輸入的時間列。

time-begin

String or Field

期望得到的時間列範圍,起始點。

選擇性參數為:

  • 具體欄位名。類型為 bigint 的欄位,其中的值為起始點,單位為納秒。

  • min:使用每行時間序列的最小值作為起始點。

  • sls_begin_time:使用查詢的起始時間作為每行時間序列的起始點。

time-end

String or Field

期望得到的時間列範圍,結束點。選擇性參數為:

  • 具體欄位名。類型為 bigint 的欄位,其中的值為結束點,單位為納秒。

  • 'min':使用每行時間序列的最大值作為結束點。

  • 'sls_begin_time':使用查詢的結束時間作為每行時間序列的結束點。

step-value

String

缺失值填充步長。

可選單位: s(秒)、m(分鐘)、h(小時)、d(天)、w(周)。

tag-col

Field

按該欄位值進行彙總。

樣本

將未經處理資料中的時間點構造為時間軸,並填充缺失點。

  • 未經處理資料

    對不同的 Method,將時間戳記按60s對齊,並計算出60s時間視窗內的彙總指標,得到時間點。

    • SPL語句

      * | extend ts = second_to_nano(__time__ - __time__ % 60)
        | stats latency_avg = avg(cast(latency as double)), inflow_avg = avg(cast (inflow as double)) by ts, Method
    • 輸出結果

      image.png

  • SPL語句

    * | extend ts = second_to_nano(__time__ - __time__ % 60)
      | stats latency_avg = max(cast(latency as double)), inflow_avg = min(cast (inflow as double)) by ts, Method
      | make-series   latency_avg default = 'last',
                    inflow_avg default = 'last'
                    on ts
                    from 'min' to 'max'
                    step '1m'
                    by Method
  • 輸出結果

    image

render

將SPL查詢結果渲染為圖表進行可視化。

  • render指令必須位於SPL查詢的最後一個運算子。

  • render指令不修改資料,只將可視化參數添加到查詢結果的拓展屬性中。

文法

render visualization [with ( propertyName = propertyValue [, ...])]

指令塊

指令塊

必填

說明

visualization

指示要使用的可視化圖表類型。支援的類型請參見Visualization

propertyName = propertyValue

索引值屬性對的分隔列表。支援類型請參見Properties

參數說明

Visualization

Visualization

Description

linechart

線圖

Properties

PropertyName/PropertyValue 索引值對指示渲染圖表時要使用的額外資訊。所有屬性都是可選的。支援的屬性:

渲染時序預測圖的參數配置

PropertyName

PropertyValue

xcolumn

查詢結果中作為x軸的列名。

ycolumns

查詢結果中作為y軸的列名列表,以逗號分隔。

例如:

... ...
| render linechart with (xcolumn=time_series,
                         ycolumns=metric_series, forecast_metric_series)
渲染異常檢測圖的參數配置

PropertyName

PropertyValue

xcolumn

查詢結果中作為 x 軸的列名。

ycolumns

查詢結果中作為 y 軸的列名列表,以逗號分隔。

anomalyscore

在圖表上顯示異常點的異常分數,僅作用於linechart。

anomalytype

在圖表上顯示異常點的異常類型,僅作用於linechart。

例如:

... ...
| render linechart with (xcolumn=ts,
                         ycolumns=mem_arr, cpu_arr,
                         anomalyscore = anomalies_score_series,
                         anomalytype = anomalies_type_series)

樣本

對所有時間軸異常檢測之後,保留最近 5 min 異常分數值,渲染異常檢測圖。

  • SPL語句

    * 
    | extend ts= (__time__- __time__%60)*1000000000
    | where Method='PostLogStoreLogs'
    | stats latency_avg=avg(cast( Latency as bigint)) by ts, Method
    | make-series   latency_avg = latency_avg default = 'null'
                    on ts
                    from 'min' to 'max'
                    step '1m'
                    by Method
    | extend ret = series_decompose_anomalies(latency_avg)
    | extend anomalies_score_series = ret.anomalies_score_series, anomalies_type_series = ret.anomalies_type_series, error_msg = ret.error_msg
    | render linechart with (xcolumn=__ts__,
                             ycolumns=latency_avg,
                             anomalyscore = anomalies_score_series,
                             anomalytype = anomalies_type_series)
  • 輸出結果

    image