Azure Monitor の Log Analytics ワークスペースへの Azure サービスのログとメトリックの収集Collect Azure service logs and metrics into Log Analytics workspace in Azure Monitor

Azure サービスのログとメトリックを収集する方法は 4 種類あります。There are four different ways of collecting logs and metrics for Azure services:

  1. Azure 診断から Azure Monitor の Log Analytics ワークスペースに直接 (次の表では "診断")Azure diagnostics direct to Log Analytics workspace in Azure Monitor (Diagnostics in the following table)
  2. Azure 診断から Azure storage 経由で Azure Monitor の Log Analytics ワークスペースに (次の表では "ストレージ")Azure diagnostics to Azure storage to Log Analytics workspace in Azure Monitor (Storage in the following table)
  3. Azure サービスのコネクタ (次の表の "コネクタ")Connectors for Azure services (Connectors in the following table)
  4. スクリプトでデータを収集して Azure Monitor の Log Analytics ワークスペースに投稿 (次の表の空白セルと、表に記載されていないサービス用)Scripts to collect and then post data into Log Analytics workspace in Azure Monitor (blanks in the following table and for services that are not listed)
ServiceService リソースの種類Resource Type ログLogs メトリックMetrics 解決策Solution
アプリケーション ゲートウェイApplication gateways Microsoft.Network/applicationGatewaysMicrosoft.Network/applicationGateways 診断Diagnostics 診断Diagnostics Azure Application Gateway 分析Azure Application Gateway Analytics
Application InsightsApplication insights コネクタConnector コネクタConnector Application Insights コネクタ (プレビュー)Application Insights Connector (Preview)
Automation アカウントAutomation accounts Microsoft.Automation/AutomationAccountsMicrosoft.Automation/AutomationAccounts 診断Diagnostics 詳細情報More information
Batch アカウントBatch accounts Microsoft.Batch/batchAccountsMicrosoft.Batch/batchAccounts 診断Diagnostics 診断Diagnostics
従来のクラウド サービスClassic cloud services StorageStorage 詳細情報More information
Cognitive ServicesCognitive services Microsoft.CognitiveServices/accountsMicrosoft.CognitiveServices/accounts 診断Diagnostics
Data Lake AnalyticsData Lake analytics Microsoft.DataLakeAnalytics/accountsMicrosoft.DataLakeAnalytics/accounts 診断Diagnostics
Data Lake StoreData Lake store Microsoft.DataLakeStore/accountsMicrosoft.DataLakeStore/accounts 診断Diagnostics
Event Hub 名前空間Event Hub namespace Microsoft.EventHub/namespacesMicrosoft.EventHub/namespaces 診断Diagnostics 診断Diagnostics
IoT HubIoT Hubs Microsoft.Devices/IotHubsMicrosoft.Devices/IotHubs 診断Diagnostics
Key VaultKey Vault Microsoft.KeyVault/vaultsMicrosoft.KeyVault/vaults 診断Diagnostics KeyVault 分析KeyVault Analytics
ロード バランサーLoad Balancers Microsoft.Network/loadBalancersMicrosoft.Network/loadBalancers 診断Diagnostics
Logic AppsLogic Apps Microsoft.Logic/workflowsMicrosoft.Logic/workflows
Microsoft.Logic/integrationAccountsMicrosoft.Logic/integrationAccounts
診断Diagnostics 診断Diagnostics
ネットワーク セキュリティ グループNetwork Security Groups Microsoft.Network/networksecuritygroupsMicrosoft.Network/networksecuritygroups 診断Diagnostics Azure ネットワーク セキュリティ グループ分析Azure Network Security Group Analytics
Recovery コンテナーRecovery vaults Microsoft.RecoveryServices/vaultsMicrosoft.RecoveryServices/vaults Azure Recovery Services Analytics (プレビュー)Azure Recovery Services Analytics (Preview)
Search サービスSearch services Microsoft.Search/searchServicesMicrosoft.Search/searchServices 診断Diagnostics 診断Diagnostics
Service Bus 名前空間Service Bus namespace Microsoft.ServiceBus/namespacesMicrosoft.ServiceBus/namespaces 診断Diagnostics 診断Diagnostics Service Bus Analytics (プレビュー)Service Bus Analytics (Preview)
Service FabricService Fabric StorageStorage Service Fabric Analytics (プレビュー)Service Fabric Analytics (Preview)
SQL (v12)SQL (v12) Microsoft.Sql/servers/databasesMicrosoft.Sql/servers/databases
Microsoft.Sql/servers/elasticPoolsMicrosoft.Sql/servers/elasticPools
診断Diagnostics Azure SQL Analytics (プレビュー)Azure SQL Analytics (Preview)
StorageStorage スクリプトScript Azure Storage Analytics (プレビュー)Azure Storage Analytics (Preview)
Virtual MachinesVirtual Machines Microsoft.Compute/virtualMachinesMicrosoft.Compute/virtualMachines 内線番号Extension 拡張機能Extension
診断Diagnostics
仮想マシン スケール セットVirtual Machines scale sets Microsoft.Compute/virtualMachinesMicrosoft.Compute/virtualMachines
Microsoft.Compute/virtualMachineScaleSets/virtualMachinesMicrosoft.Compute/virtualMachineScaleSets/virtualMachines
診断Diagnostics
Web サーバー ファームWeb Server farms Microsoft.Web/serverfarmsMicrosoft.Web/serverfarms 診断Diagnostics
Web サイトWeb Sites Microsoft.Web/sitesMicrosoft.Web/sites
Microsoft.Web/sites/slotsMicrosoft.Web/sites/slots
診断Diagnostics Azure Web Apps Analytics (プレビュー)Azure Web Apps Analytics (Preview)

注意

Azure 仮想マシン (Linux と Windows の両方) を監視する場合は、Log Analytics VM 拡張機能のインストールをお勧めします。For monitoring Azure virtual machines (both Linux and Windows), we recommend installing the Log Analytics VM extension. 仮想マシン内から収集された洞察は、エージェントによって提供されます。The agent provides you with insights collected from within your virtual machines. 仮想マシン スケール セットの拡張機能を使用することもできます。You can also use the extension for Virtual machine scale sets.

Azure Diagnostics から Log Analytics に直接Azure diagnostics direct to Log Analytics

多くの Azure リソースで診断ログとメトリックを Azure Monitor の Log Analytics ワークスペースに直接書き込むことができます。分析用のデータを収集するにはこの方法がお勧めです。Many Azure resources are able to write diagnostic logs and metrics directly to a Log Analytics workspace in Azure Monitor, and this is the preferred way of collecting the data for analysis. Azure 診断を使用すると、データがワークスペースに即座に書き込まれるため、データを最初にストレージに出力する必要はありません。When using Azure diagnostics, data is written immediately to the workspace, and there is no need to first write the data to storage.

Azure Monitor をサポートする Azure リソースのログとメトリックは、Log Analytics ワークスペースに直接送信できます。Azure resources that support Azure monitor can send their logs and metrics directly to a Log Analytics workspace.

注意

診断設定を使用した Log Analytics ワークスペースへの多ディメンション メトリックの送信は現在サポートされていません。Sending multi-dimensional metrics to a Log Analytics workpace via diagnostic settings is not currently supported. ディメンションを含むメトリックは、ディメンション値間で集計され、フラット化された単一ディメンションのメトリックとしてエクスポートされます。Metrics with dimensions are exported as flattened single dimensional metrics, aggregated across dimension values.

: イベント ハブの "受信メッセージ" メトリックは、キュー単位のレベルで調査およびグラフ化できます。For example: The 'Incoming Messages' metric on an Event Hub can be explored and charted on a per queue level. ただし、診断設定を使用してエクスポートすると、メトリックは、イベント ハブ内のすべてのキューのすべての受信メッセージとして表されます。However, when exported via diagnostic settings the metric is represented as all incoming messages across all queues in the Event Hub.

PowerShell を使用して診断を有効にするEnable diagnostics with PowerShell

注意

この記事は、新しい Azure PowerShell Az モジュールを使用するために更新されました。This article has been updated to use the new Azure PowerShell Az module. AzureRM モジュールはまだ使用でき、少なくとも 2020 年 12 月までは引き続きバグ修正が行われます。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. Az モジュールと AzureRM の互換性の詳細については、「Introducing the new Azure PowerShell Az module (新しい Azure PowerShell Az モジュールの概要)」を参照してください。To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. Az モジュールのインストール手順については、Azure PowerShell のインストールを参照してください。For Az module installation instructions, see Install Azure PowerShell.

次の PowerShell の例は、Set-AzDiagnosticSetting を使用してネットワーク セキュリティ グループで診断を有効にする方法を示しています。The following PowerShell example shows how to use Set-AzDiagnosticSetting to enable diagnostics on a network security group. 同じ方法をサポート対象のすべてのリソースで利用できます。診断を有効にするリソースのリソース ID に $resourceId を設定します。The same approach works for all supported resources - set $resourceId to the resource id of the resource you want to enable diagnostics for.

PowerShell
$workspaceId = "/subscriptions/d2e37fee-1234-40b2-5678-0b2199de3b50/resourcegroups/oi-default-east-us/providers/microsoft.operationalinsights/workspaces/rollingbaskets"

$resourceId = "/SUBSCRIPTIONS/ec11ca60-1234-491e-5678-0ea07feae25c/RESOURCEGROUPS/DEMO/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/DEMO"

Set-AzDiagnosticSetting -ResourceId $ResourceId  -WorkspaceId $workspaceId -Enabled $true

Resource Manager テンプレートを使用して診断を有効にするEnable diagnostics with Resource Manager templates

リソースを作成するときにリソースで診断を有効にして診断を Log Analytics ワークスペースに送信するには、次のようなテンプレートを使用できます。To enable diagnostics on a resource when it is created, and have the diagnostics sent to your Log Analytics workspace you can use a template similar to the one below. この例は Automation アカウント向けですが、サポートされているすべてのリソース タイプで動作します。This example is for an Automation account but works for all supported resource types.

JSON
        {
            "type": "Microsoft.Automation/automationAccounts/providers/diagnosticSettings",
            "name": "[concat(parameters('omsAutomationAccountName'), '/', 'Microsoft.Insights/service')]",
            "apiVersion": "2015-07-01",
            "dependsOn": [
                "[concat('Microsoft.Automation/automationAccounts/', parameters('omsAutomationAccountName'))]",
                "[concat('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspaceName'))]"
            ],
            "properties": {
                "workspaceId": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('omsWorkspaceName'))]",
                "logs": [
                    {
                        "category": "JobLogs",
                        "enabled": true
                    },
                    {
                        "category": "JobStreams",
                        "enabled": true
                    }
                ]
            }
        }

Azure Diagnostics のトラブルシューティングTroubleshoot Azure Diagnostics

次のエラー メッセージが表示される場合は、Microsoft.insights リソース プロバイダーが登録されていません。If you receive the following error message, the Microsoft.insights resource provider is not registered:

Failed to update diagnostics for 'resource'. {"code":"Forbidden","message":"Please register the subscription 'subscription id' with Microsoft.Insights."}

リソース プロバイダーを登録するには、Azure Portal で次の手順を実行します。To register the resource provider, perform the following steps in the Azure portal:

  1. 左側のナビゲーション ウィンドウで、 [サブスクリプション] をクリックします。In the navigation pane on the left, click Subscriptions
  2. エラー メッセージで示されたサブスクリプションを選択します。Select the subscription identified in the error message
  3. [リソース プロバイダー] をクリックします。Click Resource Providers
  4. Microsoft.insights プロバイダーを探します。Find the Microsoft.insights provider
  5. [登録] リンクをクリックします。Click the Register link

microsoft.insights リソース プロバイダーの登録

Microsoft.insights リソース プロバイダーが登録されたら、診断の構成を再試行してください。Once the Microsoft.insights resource provider is registered, retry configuring diagnostics.

PowerShell で次のエラー メッセージが表示された場合は、PowerShell のバージョンを更新する必要があります。In PowerShell, if you receive the following error message, you need to update your version of PowerShell:

Set-AzDiagnosticSetting : A parameter cannot be found that matches parameter name 'WorkspaceId'.

お使いの Azure PowerShell バージョンを更新し、Azure PowerShell のインストールに関する記事で説明されている手順に従ってください。Update your version of Azure PowerShell, follow the instructions in the Install Azure PowerShell article.

Azure Diagnostics からストレージ経由で Log Analytics にAzure diagnostics to storage then to Log Analytics

一部のリソース内からログを収集するには、Azure Storage にログを送信して、そこからログを読み取るように Log Analytics ワークスペースを構成することができます。For collecting logs from within some resources, it is possible to send the logs to Azure storage and then configure the Log Analytics workspace to read the logs from storage.

Azure Monitor では、この方法を使用して、次のリソースとログについて Azure Storage から診断を収集できます。Azure Monitor can use this approach to collect diagnostics from Azure storage for the following resources and logs:

ResourceResource ログLogs
Service FabricService Fabric ETWEventETWEvent
操作イベントOperational Event
Reliable Actor イベントReliable Actor Event
Reliable Service イベントReliable Service Event
Virtual MachinesVirtual Machines Linux SyslogLinux Syslog
Windows イベントWindows Event
IIS ログIIS Log
Windows ETWEventWindows ETWEvent
Web ロールWeb Roles
worker ロールWorker Roles
Linux SyslogLinux Syslog
Windows イベントWindows Event
IIS ログIIS Log
Windows ETWEventWindows ETWEvent

注意

ストレージ アカウントに診断を送信する際、および Log Analytics ワークスペースがストレージ アカウントからデータを読み取る際のデータの格納と転送には、通常の Azure 料金が課金されます。You are charged normal Azure data rates for storage and transactions when you send diagnostics to a storage account and for when the Log Analytics workspace reads the data from your storage account.

Azure Monitor でこれらのログを収集する方法の詳細については、IIS の Blob Storage とイベントの Table Storage の使用に関するページをご覧ください。See Use blob storage for IIS and table storage for events to learn more about how Azure Monitor can collect these logs.

Azure サービスのコネクタConnectors for Azure services

Application Insights にはコネクタがあり、これを使用して、Application Insights で収集されたデータを Log Analytics ワークスペースに送信することができます。There is a connector for Application Insights, which allows data collected by Application Insights to be sent to a Log Analytics workspace.

Application Insights コネクタに関する詳細を確認してください。Learn more about the Application Insights connector.

スクリプトでデータを収集して Log Analytics ワークスペースに投稿Scripts to collect and post data to Log Analytics workspace

Log Analytics ワークスペースにログとメトリックを直接送信する手段が提供されていない Azure のサービスについては、Azure Automation スクリプトを使用してログとメトリックを収集することができます。For Azure services that do not provide a direct way to send logs and metrics to a Log Analytics workspace you can use an Azure Automation script to collect the log and metrics. 次に、このスクリプトでデータ コレクター API を使用してワークスペースにデータを送信できますThe script can then send the data to the workspace using the data collector API

Azure テンプレート ギャラリーには、サービスからデータを収集し、Azure Monitor に送信するために Azure Automation を使用する例が用意されています。The Azure template gallery has examples of using Azure Automation to collect data from services and send it to Azure Monitor.

次の手順Next steps