監視公用 IP 位址

當您有依賴 Azure 資源的重要應用程式和商務程序時,您會想要監視這些資源的可用性、效能和操作。

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

公用 IP 位址深入解析

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

公用 IP 位址深入解析提供:

  • 流量資料

  • DDoS 資訊

監視資料

公用 IP 位址會收集與其他 Azure 資源相同類型的監視資料,如監視 Azure 資源中的資料中所述。

如需公用 IP 位址所建立之計量和記錄計量的詳細資訊,請參閱監視公用 IP 位址資料參考

收集和路由傳送

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

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

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

建立診斷設定

您可以使用 Azure 入口網站、PowerShell 或 Azure CLI 來建立診斷設定。

入口網站

  1. 登入 Azure 入口網站

  2. 在入口網站頂端的搜尋方塊中,輸入公用 IP 位址。 在搜尋結果中,選取 [公用 IP 位址]

  3. 選取您要為其啟用設定的公用 IP 位址。 在此範例中,會使用 myPublicIP

  4. 在公用 IP 位址的 [監視] 區段中,選取 [診斷設定]

  5. 選取 [新增診斷設定]

  6. [診斷設定] 中輸入或選取下列資訊。

    設定
    診斷設定名稱 輸入診斷設定的名稱。
    記錄
    類別 選取 [DDoSProtectionNotifications][DDoSMitigationFlowLogs][DDoSMitigationReports]
    計量
    選取 [AllMetrics]
  7. 選取 [目的地詳細資料]。 部分目的地選項如下:

    • 傳送至 Log Analytics 工作區

      • 選取 [訂用帳戶] 和 [Log Analytics 工作區]
    • 封存至儲存體帳戶

      • 選取 [訂用帳戶][儲存體帳戶]
    • 串流至事件中樞

      • 選取 [訂用帳戶]、[事件中樞命名空間]、\[事件中樞名稱 \(選擇性\)\] 及 [事件中樞原則名稱]
    • 傳送至合作夥伴解決方案

      • 選取 [訂用帳戶][目的地]
  8. 選取 [儲存]。

PowerShell

登入 Azure PowerShell:

Connect-AzAccount 

記錄分析工作區

若要將資源記錄傳送至 Log Analytics 工作區,請輸入這些命令。 在此範例中,myResourceGroupmyLogAnalyticsWorkspacemyPublicIP 會用於資源值。 將這些值取代為您的。

## Place the public IP in a variable. ##
$ippara = @{
    ResourceGroupName = 'myResourceGroup'
    Name = 'myPublicIP'
}
$ip = Get-AzPublicIPAddress @ippara
    
## Place the workspace in a variable. ##
$wspara = @{
    ResourceGroupName = 'myResourceGroup'
    Name = 'myLogAnalyticsWorkspace'
}
$ws = Get-AzOperationalInsightsWorkspace @wspara
    
## Enable the diagnostic setting. ##
$diag = @{
	ResourceId = $ip.id
	Name = 'myDiagnosticSetting'
	Enabled = $true
	WorkspaceId = $ws.ResourceId
}
Set-AzDiagnosticSetting @diag

儲存體帳戶

若要將資源記錄傳送至儲存體帳戶,請輸入這些命令。 在此範例中,myResourceGroupmystorageaccount8675myPublicIP 會用於資源值。 將這些值取代為您的。

## Place the public IP in a variable. ##
$ippara = @{
    ResourceGroupName = 'myResourceGroup'
    Name = 'myPublicIP'
}
$lb = Get-AzPublicIPAddress @ippara
    
## Place the storage account in a variable. ##
$storpara = @{
    ResourceGroupName = 'myResourceGroup'
    Name = 'mystorageaccount8675'
}
$storage = Get-AzStorageAccount @storpara
    
## Enable the diagnostic setting. ##
$diag = @{
	ResourceId = $ip.id
	Name = 'myDiagnosticSetting'
	StorageAccountId = $storage.id
  Enabled = $true
}
Set-AzDiagnosticSetting @diag

事件中樞

若要將資源記錄傳送至事件中樞命名空間,請輸入這些命令。 在此範例中,myResourceGroupmyeventhub8675myPublicIP 會用於資源值。 將這些值取代為您的。

## Place the public IP in a variable. ##
$ippara = @{
    ResourceGroupName = 'myResourceGroup'
    Name = 'myPublicIP'
}
$lb = Get-AzPublicIPAddress @ippara
    
## Place the event hub in a variable. ##
$hubpara = @{
    ResourceGroupName = 'myResourceGroup'
    Name = 'myeventhub8675'
}
$eventhub = Get-AzEventHubNamespace @hubpara

## Place the event hub authorization rule in a variable. ##    
$hubrule = @{
    ResourceGroupName = 'myResourceGroup'
    Namespace = 'myeventhub8675'
}
$eventhubrule = Get-AzEventHubAuthorizationRule @hubrule

## Enable the diagnostic setting. ##
$diag = @{
	ResourceId = $ip.id
	Name = 'myDiagnosticSetting'
	EventHubName = $eventhub.Name
  EventHubAuthorizationRuleId = $eventhubrule.Id
  Enabled = $true
}
Set-AzDiagnosticSetting @diag

Azure CLI

登入 Azure CLI:

az login

記錄分析工作區

若要將資源記錄傳送至 Log Analytics 工作區,請輸入這些命令。 在此範例中,myResourceGroupmyLogAnalyticsWorkspacemyPublicIP 會用於資源值。 將這些值取代為您的。

ipid=$(az network public-ip show \
    --name myPublicIP \
    --resource-group myResourceGroup \
    --query id \
    --output tsv)

wsid=$(az monitor log-analytics workspace show \
    --resource-group myResourceGroup \
    --workspace-name myLogAnalyticsWorkspace \
    --query id \
    --output tsv)
    
az monitor diagnostic-settings create \
    --name myDiagnosticSetting \
    --resource $ipid \
    --logs '[{"category": "DDoSProtectionNotifications","enabled": true},{"category": "DDoSMitigationFlowLogs","enabled": true},{"category": "DDoSMitigationReports","enabled": true}]' \
    --metrics '[{"category": "AllMetrics","enabled": true}]' \
    --workspace $wsid

儲存體帳戶

若要將資源記錄傳送至儲存體帳戶,請輸入這些命令。 在此範例中,myResourceGroupmystorageaccount8675myPublicIP 會用於資源值。 將這些值取代為您的。

ipid=$(az network public-ip show \
    --name myPublicIP \
    --resource-group myResourceGroup \
    --query id \
    --output tsv)

storid=$(az storage account show \
        --name mystorageaccount8675 \
        --resource-group myResourceGroup \
        --query id \
        --output tsv)
    
az monitor diagnostic-settings create \
    --name myDiagnosticSetting \
    --resource $ipid \
    --logs '[{"category": "DDoSProtectionNotifications","enabled": true},{"category": "DDoSMitigationFlowLogs","enabled": true},{"category": "DDoSMitigationReports","enabled": true}]' \
    --metrics '[{"category": "AllMetrics","enabled": true}]' \
    --storage-account $storid

事件中樞

若要將資源記錄傳送至事件中樞命名空間,請輸入這些命令。 在此範例中,myResourceGroupmyeventhub8675myPublicIP 會用於資源值。 將這些值取代為您的。

ipid=$(az network public-ip show \
    --name myPublicIP \
    --resource-group myResourceGroup \
    --query id \
    --output tsv)

az monitor diagnostic-settings create \
    --name myDiagnosticSetting \
    --resource $ipid \
    --event-hub myeventhub8675 \
    --event-hub-rule RootManageSharedAccessKey \
    --logs '[{"category": "DDoSProtectionNotifications","enabled": true},{"category": "DDoSMitigationFlowLogs","enabled": true},{"category": "DDoSMitigationReports","enabled": true}]' \
    --metrics '[{"category": "AllMetrics","enabled": true}]'

下列各節將討論您可以收集的計量和記錄。

分析計量

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

如需針對公用 IP 位址平台計量的已收集清單,請參閱 監視公用 IP 位址資料參考

如需參考,您可以查看 Azure 監視器中支援的所有資源計量清單。

分析記錄

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

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

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

如需針對公用 IP 位址資源記錄類型的已收集清單,請參閱監視公用 IP 位址資料參考

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

範例 Kusto 查詢

重要

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

如需公用 IP 位址的常見查詢清單,請參閱 Log Analytics 查詢介面

以下是在 Azure 入口網站中 Long Analytics 查詢介面中找到之公用 IP 位址的內建查詢範例。

Screenshot of the built in queries for Public IP addresses.

警示

在監視資料中發現重大狀況時,Azure 監視器會主動通知您。 如此便能在您的客戶注意到之前,先在您的系統中識別問題並加以對應。 可在 [計量]、[記錄]、[活動記錄] 中設定警示。 不同類型的警示各有優缺點。

下表列出公用 IP 位址常見和建議的警示規則。

警示類型 Condition 描述
是否遭受 DDoS 攻擊 大於 0。
1 目前正在遭受攻擊。
0 表示正常活動
作為 Azure 邊緣保護的一部分,公用 IP 位址會受到 DDoS 攻擊的監視。 警示可讓您在公用 IP 位址受到影響時收到通知。

下一步