Splunk 對 Kusto 的功能提要

此文章將協助熟悉 Splunk 的使用者,瞭解 Kusto 查詢語言,以使用 Kusto 來撰寫記錄查詢。 我們會直接比較這兩者的各項內容,以醒目提示主要差異及相似之處,以便您組建現有的知識。

結構和概念

下表比較 Splunk 與 Kusto 記錄之間的概念和資料結構:

概念 Splunk Kusto 註解
部署單位 叢集 叢集 Kusto 允許任意的跨叢集查詢。 Splunk 不會。
資料快取 貯體 快取與保留原則 控制資料的期間和快取層級。 此設定會直接影響查詢效能和部署成本。
資料的邏輯分割 索引 [資料庫] 可允許資料的邏輯分隔。 兩種實作皆允許分割區的集合聯集和聯結。
結構化的事件中繼資料 N/A 資料表 Splunk 不會將事件中繼資料的概念公開給搜尋語言。 Kusto 記錄有資料表的概念,且資料表具有資料行。 每個事件執行個體會對應至一個資料列。
記錄 (record) event 僅限詞彙變更。
記錄屬性 field 在 Kusto 中,這項設定已預先定義為資料表結構的一部分。 在 Splunk 中,每個事件都有自己的欄位集。
types datatype datatype 由於 Kusto 資料類型是在資料行上進行設定,因此會更明確。 兩者都能夠以動態方式使用資料類型,且擁有大致相當的資料類型集,包括 JSON 支援。
查詢和搜尋 搜尋 查詢 Kusto 和 Splunk 之間的概念基本相同。
事件擷取時間 系統時間 ingestion_time() 在 Splunk 中,每個事件都會取得事件編製索引時間的系統時間戳記。 在 Kusto 中,您可以定義稱為 ingestion_time 的原則,其會公開可透過 ingestion_time() 函式來參考的系統資料行。

函式

下表指定 Kusto 中與 Splunk 函式相等的函式。

Splunk Kusto 註解
strcat strcat() (1)
split split() (1)
if iff() (1)
tonumber todouble()
tolong()
toint()
(1)
upper
lower
toupper()
tolower()
(1)
replace replace_string()replace_strings()replace_regex() (1)
雖然 replace 函式在這兩個產品中都採用三個參數,但參數不同。
substr substring() (1)
也請注意,Splunk 使用以一為基底的索引。 Kusto 是以零為基底的索引。
tolower tolower() (1)
toupper toupper() (1)
match matches regex (2)
regex matches regex 在 Splunk 中,regex 是運算子。 在 Kusto 中,這是關係運算子。
searchmatch == 在 Splunk 中,searchmatch 可允許搜尋完全相符的字串。
random rand()
rand(n)
Splunk 的函式會傳回介於 0 到 231-1 的數字。 Kusto 的函式會傳回介於 0.0 和 1.0 之間的數字,或者,如果提供參數,傳回的數字則介於 0 到 n-1 之間。
now now() (1)
relative_time totimespan() (1)
在 Kusto 中,Splunk relative_time(datetimeVal, offsetVal) 的對等函式為 datetimeVal + totimespan(offsetVal)
例如 search | eval n=relative_time(now(), "-1d@d") 會成為 ... | extend myTime = now() - totimespan("1d")

(1) 在 Splunk 中,會使用 eval 運算子叫用函式。 在 Kusto 中,其會用作 extendproject 的一部分。
(2) 在 Splunk 中,會使用 eval 運算子叫用函式。 在 Kusto 中,其可以與 where 運算子搭配使用。

運算子

下列各節提供如何在 Splunk 和 Kusto 中,使用不同運算子的範例。

注意

在下列範例中,Splunk 欄位 rule 會對應 Kusto 中的資料表,而 Splunk 的預設時間戳記會對應記錄分析 ingestion_time() 資料行。

在 Splunk 中,您可以省略 search 關鍵字,並指定不具引號的字串。 在 Kusto 中,您必須使用 find 啟動每個查詢,不具引號的字串是資料行名稱,且查閱值必須是加上引號的字串。

產品 運算子 範例
Splunk search search Session.Id="c8894ffd-e684-43c9-9125-42adc25cd3fc" earliest=-24h
Kusto find find Session.Id=="c8894ffd-e684-43c9-9125-42adc25cd3fc" and ingestion_time()> ago(24h)

篩選

Kusto 記錄查詢會從套用 filter 的表格式結果集開始。 Splunk 的篩選則是在目前索引上的預設作業。 您也可以在 Splunk 中使用運算子,但不建議使用 where

產品 運算子 範例
Splunk search Event.Rule="330009.2" Session.Id="c8894ffd-e684-43c9-9125-42adc25cd3fc" _indextime>-24h
Kusto where Office_Hub_OHubBGTaskError
| where Session_Id == "c8894ffd-e684-43c9-9125-42adc25cd3fc" and ingestion_time() > ago(24h)

取得 n 個事件或資料列進行檢查

Kusto 記錄也支援以 take 作為 limit 的別名。 在 Splunk 中,如果結果已進行排序,則 head 會傳回前 n 個結果。 在 Kusto 中,limit 不會進行排序,但會傳回找到的前 n 個資料列。

產品 運算子 範例
Splunk head Event.Rule=330009.2
| head 100
Kusto limit Office_Hub_OHubBGTaskError
| limit 100

取得依欄位或資料行進行排序的前 n 個事件或資料列

針對底部結果,您可以在 Splunk 中使用 tail。 在 Kusto 中,您可以使用 asc 指定排序方向。

產品 運算子 範例
Splunk head Event.Rule="330009.2"
| sort Event.Sequence
| head 20
Kusto top Office_Hub_OHubBGTaskError
| top 20 by Event_Sequence

以新的欄位或資料行來擴充結果集

Splunk 具有 eval 函式,但無法與 Kusto 中的 eval 運算子比較。 Splunk 的 eval 運算子和 Kusto 的 extend 運算子皆只支援純量函式和算術運算子。

產品 運算子 範例
Splunk eval Event.Rule=330009.2
| eval state= if(Data.Exception = "0", "success", "error")
Kusto extend Office_Hub_OHubBGTaskError
| extend state = iff(Data_Exception == 0,"success" ,"error")

重新命名

Kusto 使用 project-rename 運算子來重新命名欄位。 在 project-rename 運算子中,查詢可利用針對欄位所預先建立的任何索引。 Splunk 具有執行相同操作的 rename 運算子。

產品 運算子 範例
Splunk rename Event.Rule=330009.2
| rename Date.Exception as execption
Kusto project-rename Office_Hub_OHubBGTaskError
| project-rename exception = Date_Exception

格式結果和投影

Splunk 會 table 使用 命令來選取要包含在結果中的數據行。 Kusto 有一個 project 運算符會執行相同 和更多動作。

產品 運算子 範例
Splunk table Event.Rule=330009.2
| table rule, state
Kusto project Office_Hub_OHubBGTaskError
| project exception, state

Splunk 會 field - 使用 命令來選取要從結果中排除的數據行。 Kusto 有一個 project-away 會執行相同動作的運算符。

產品 運算子 範例
Splunk fields - Event.Rule=330009.2
| fields - quota, hightest_seller
Kusto project-away Office_Hub_OHubBGTaskError
| project-away exception, state

彙總

查看可用的彙總函式摘要清單

Splunk 運算子 Splunk 範例 Kusto 運算子 Kusto 範例
stats search (Rule=120502.*)
| stats count by OSEnv, Audience
summarize Office_Hub_OHubBGTaskError
| summarize count() by App_Platform, Release_Audience
evenstats ...
| stats count_i by time, category
| eventstats sum(count_i) AS count_total by _time_
join T2
| join kind=inner (T1) on _time
| project _time, category, count_i, count_total

Join

join 在 Splunk 中具有大量限制。 子查詢的限制為 10,000 筆結果 (設定在部署組態檔中),且可用的聯結類別數目有限。

產品 運算子 範例
Splunk join Event.Rule=120103* | stats by Client.Id, Data.Alias
| join Client.Id max=0 [search earliest=-24h Event.Rule="150310.0" Data.Hresult=-2147221040]
Kusto join cluster("OAriaPPT").database("Office PowerPoint").Office_PowerPoint_PPT_Exceptions
| where Data_Hresult== -2147221040
| join kind = inner (Office_System_SystemHealthMetadata
| summarize by Client_Id, Data_Alias)on Client_Id

Sort

在 Splunk 中,若要以遞增順序排序,您必須使用 reverse 運算子。 Kusto 也支援定義 Null 的放置位置 (置於開頭或結尾)。

產品 運算子 範例
Splunk sort Event.Rule=120103
| sort Data.Hresult
| reverse
Kusto order by Office_Hub_OHubBGTaskError
| order by Data_Hresult, desc

展開多重值

Splunk 和 Kusto 的多值展開運算子相似。

產品 運算子 範例
Splunk mvexpand mvexpand solutions
Kusto mv-expand mv-expand solutions

結果 Facet、關鍵欄位

在 Azure 入口網站中的 Log Analytics,只會公開第一個資料行。 所有資料行可透過 API 提供。

產品 運算子 範例
Splunk fields Event.Rule=330009.2
| fields App.Version, App.Platform
Kusto facets Office_Excel_BI_PivotTableCreate
| facet by App_Branch, App_Version

刪除重複資料

在 Kusto 中,您可以使用 summarize arg_min() 來反轉所選記錄的順序。

產品 運算子 範例
Splunk dedup Event.Rule=330009.2
| dedup device_id sortby -batterylife
Kusto summarize arg_max() Office_Excel_BI_PivotTableCreate
| summarize arg_max(batterylife, *) by device_id