監視 Azure Key Vault

當您有依賴 Azure 資源的重要應用程式和商務程序時,您會想要監視這些資源的可用性、效能和操作。 針對 Azure Key Vault,請務必在開始調整時就監視您的服務,因為傳送到您金鑰保存庫的要求數目將會增加。 這可能會增加要求的延遲,而且在極端情況下,會導致您的要求受到節流處理,進而影響服務效能。

本文會說明如何監視 Key Vault 產生的資料。 Key Vault 會使用 Azure 監視器。 Azure 監視器為所有使用到 Azure 監視器的 Azure 服務提供通用功能,若您對這些功能不甚熟悉,請參閱使用 Azure 監視器監視 Azure 資源

Azure 入口網站中的 [監視] 概觀頁面

每個金鑰保存庫在 Azure 入口網站中的 [概觀] 頁面會在 [監視] 索引標籤上包含下列計量:

  • 總要求數
  • 平均延遲
  • 成功率

您可以選取 [其他計量] (或 [監視] 底下左側提要欄位中的 [計量] 索引標籤) 以便也檢視以下計量:

  • 整體服務 API 延遲
  • 整體保存庫可用性
  • 整體保存庫飽和度
  • 服務 API 點擊次數總計
  • 服務 API 結果總計

Key Vault 深入解析

在 Azure 入口網站中,某些 Azure 服務具有專屬的預建監視儀表板,可做為您監控服務的起點。 這類特殊儀表板稱為「深入解析」。

Key Vault 深入解析可針對您的 Key Vault 要求、效能、失敗和延遲提供統合檢視,讓您能夠全面監視金鑰保存庫。 如需完整的詳細資料,請參閱使用 Key Vault 深入解析來監視金鑰保存庫服務

監視資料

Key Vault 會收集與其他 Azure 資源相同類型的監視資料,如監視 Azure 資源中的資料中所述。

如需 Key Vault 建立的計量和記錄計量的詳細資訊,請參閱監視 Key Vault 資料參考

收集和路由傳送

系統會自動收集和儲存平台計量和活動記錄,但是可以使用診斷設定將資料路由傳送至其他位置。

在您建立診斷設定並將其路由傳送至一個或多個位置之前,系統不會收集和儲存資源記錄。

如需使用 Azure 入口網站、Azure CLI 或 PowerShell 建立診斷設定的詳細程序,請參閱建立診斷設定以在 Azure 中收集平台記錄和計量。 在建立診斷設定時,您可以指定要收集的記錄類別。 Key Vault 的類別會列在 Key Vault 監視資料參考中。

若要為金鑰保存庫建立診斷設定,請參閱啟用 Key Vault 記錄。 下列各節將討論您可以收集的計量和記錄。

分析計量

可開啟 [Azure 監視器] 功能表的 [計量],使用計量瀏覽器以其他 Azure 服務提供的計量來分析 Key Vault 的計量。 如需使用此工具的詳細資料,請參閱使用 Azure 監視器計量總管分析計量

如需針對 Key Vault 所收集的平台計量清單,請參閱監視 Key Vault 資料參考計量

分析記錄

Azure 監視器記錄中的資料會儲存在資料表中,其中每個資料表都有一組專屬的唯一屬性。

Azure 監視器中的所有資源記錄都有相同的欄位,後面接著服務特定的欄位。 一般結構描述如 Azure 監視器資源記錄結構描述中所述

活動記錄是 Azure 中的一種平台記錄,可提供訂用帳戶層級事件的深入解析。 您可以獨立檢視活動記錄,或將記錄路由至 Azure 監視器記錄,以便使用 Log Analytics 處理更為複雜的查詢作業。

如需針對 Key Vault 所收集的資源記錄類型清單,請參閱監視 Key Vault 資料參考

如需 Azure 監視器記錄所使用且可由 Log Analytics 查詢的資料表清單,請參閱監視 Key Vault 資料參考

範例 Kusto 查詢

重要

當您從 [Key Vault] 功能表中選取 [記錄] 時,Log Analytics 會隨即開啟,並將查詢範圍設定為目前的金鑰保存庫。 這表示記錄查詢只會包含來自該資源的資料。 如果您想要執行包含其他金鑰保存庫資料或其他 Azure 服務資料的查詢,請從 [Azure 監視器] 功能表中選取 [記錄]。 如需詳細資訊,請參閱 Azure 監視器 Log Analytics 中的記錄查詢範圍和時間範圍

以下是一些您可以在 [記錄搜尋] 列中輸入以利監視 Key Vault 資源的查詢。 這些查詢使用新語言

  • 是否有任何用戶端使用舊版 TLS (<1.2)?

    AzureDiagnostics
    | where TimeGenerated > ago(90d) 
    | where ResourceProvider =="MICROSOFT.KEYVAULT" 
    | where isnotempty(tlsVersion_s) and strcmp(tlsVersion_s,"TLS1_2") <0
    | project TimeGenerated,Resource, OperationName, requestUri_s, CallerIPAddress, OperationVersion,clientInfo_s,tlsVersion_s,todouble(tlsVersion_s)
    | sort by TimeGenerated desc
    
  • 是否有任何緩慢的要求?

    // List of KeyVault requests that took longer than 1sec. 
    // To create an alert for this query, click '+ New alert rule'
    let threshold=1000; // let operator defines a constant that can be further used in the query
    
    AzureDiagnostics
    | where ResourceProvider =="MICROSOFT.KEYVAULT" 
    | where DurationMs > threshold
    | summarize count() by OperationName, _ResourceId
    
  • 是否有任何失敗?

    // Count of failed KeyVault requests by status code. 
    // To create an alert for this query, click '+ New alert rule'
    
    AzureDiagnostics
    | where ResourceProvider =="MICROSOFT.KEYVAULT" 
    | where httpStatusCode_d >= 300 and not(OperationName == "Authentication" and httpStatusCode_d == 401)
    | summarize count() by requestUri_s, ResultSignature, _ResourceId
    // ResultSignature contains HTTP status, e.g. "OK" or "Forbidden"
    // httpStatusCode_d contains HTTP status code returned
    
  • 輸入還原序列化錯誤

    // Shows errors caused due to malformed events that could not be deserialized by the job. 
    // To create an alert for this query, click '+ New alert rule'
    
    AzureDiagnostics
    | where ResourceProvider == "MICROSOFT.KEYVAULT" and parse_json(properties_s).DataErrorType in ("InputDeserializerError.InvalidData", "InputDeserializerError.TypeConversionError", "InputDeserializerError.MissingColumns", "InputDeserializerError.InvalidHeader", "InputDeserializerError.InvalidCompressionType")
    | project TimeGenerated, Resource, Region_s, OperationName, properties_s, Level, _ResourceId
    
  • 這個 KeyVault 有多活躍?

    // Line chart showing trend of KeyVault requests volume, per operation over time. 
    // KeyVault diagnostic currently stores logs in AzureDiagnostics table which stores logs for multiple services. 
    // Filter on ResourceProvider for logs specific to a service.
    
    AzureDiagnostics
    | where ResourceProvider =="MICROSOFT.KEYVAULT" 
    | summarize count() by bin(TimeGenerated, 1h), OperationName // Aggregate by hour
    | render timechart
    
    
  • 誰在呼叫此 KeyVault?

    // List of callers identified by their IP address with their request count.  
    // KeyVault diagnostic currently stores logs in AzureDiagnostics table which stores logs for multiple services. 
    // Filter on ResourceProvider for logs specific to a service.
    
    AzureDiagnostics
    | where ResourceProvider =="MICROSOFT.KEYVAULT"
    | summarize count() by CallerIPAddress
    
  • 這個 KeyVault 對要求提供服務的速度有多快?

    // Line chart showing trend of request duration over time using different aggregations. 
    
    AzureDiagnostics
    | where ResourceProvider =="MICROSOFT.KEYVAULT" 
    | summarize avg(DurationMs) by requestUri_s, bin(TimeGenerated, 1h) // requestUri_s contains the URI of the request
    | render timechart
    
  • 上個月發生了哪些變更?

    // Lists all update and patch requests from the last 30 days. 
    // KeyVault diagnostic currently stores logs in AzureDiagnostics table which stores logs for multiple services. 
    // Filter on ResourceProvider for logs specific to a service.
    
    AzureDiagnostics
    | where TimeGenerated > ago(30d) // Time range specified in the query. Overrides time picker in portal.
    | where ResourceProvider =="MICROSOFT.KEYVAULT" 
    | where OperationName == "VaultPut" or OperationName == "VaultPatch"
    | sort by TimeGenerated desc
    

警示

在監視資料中發現重大狀況時,Azure 監視器會主動通知您。 其可讓您事先識別並解決系統中的問題。 可在 [計量]、[記錄]、[活動記錄] 中設定警示。

若要建立或執行在 Azure Key Vault 上運作的應用程式,Azure 監視器 Application Insights 可提供更多類型的警示。

以下是 Azure Key Vault 的一些常見和建議的警示規則 -

  • Key Vault 可用性降到低於 100% (靜態閾值)
  • Key Vault 延遲大於 1000 毫秒 (靜態閾值)
  • 整體保存庫飽和度大於 75% (靜態閾值)
  • 整體保存庫飽和度超過平均值 (動態閾值)
  • 錯誤碼總數高於平均值 (動態閾值)

如需詳細資訊,請參閱 Azure Key Vault 的警示

下一步