Skip to content

Commit 4255e5e

Browse files
authored
Merge pull request #235965 from seesharprun/cosmos-monitor-resource-logs-arm-template
Cosmos DB | Add ARM template to monitor resource logs article
2 parents 54ac875 + 0323c90 commit 4255e5e

File tree

1 file changed

+221
-10
lines changed

1 file changed

+221
-10
lines changed

articles/cosmos-db/monitor-resource-logs.md

Lines changed: 221 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
2-
title: Monitor Azure Cosmos DB data by using Azure Diagnostic settings
2+
title: Monitor data by using Azure Diagnostic settings
3+
titleSuffix: Azure Cosmos DB
34
description: Learn how to use Azure diagnostic settings to monitor the performance and availability of data stored in Azure Cosmos DB
45
author: seesharprun
56
ms.author: sidandrews
67
ms.reviewer: esarroyo
78
ms.service: cosmos-db
89
ms.topic: how-to
9-
ms.date: 04/23/2023
10+
ms.date: 04/26/2023
1011
ms.custom: ignite-2022
1112
---
1213

@@ -26,8 +27,17 @@ Platform metrics and the Activity logs are collected automatically, whereas you
2627
> [!NOTE]
2728
> We recommend creating the diagnostic setting in resource-specific mode (for all APIs except API for Table) [following our instructions for creating diagnostics setting via REST API](monitor-resource-logs.md). This option provides additional cost-optimizations with an improved view for handling data.
2829
30+
## Prerequisites
31+
32+
- An existing Azure Cosmos DB account.
33+
- If you have an Azure subscription, [create a new account](nosql/how-to-create-account.md?tabs=azure-portal).
34+
- If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
35+
- Alternatively, you can [try Azure Cosmos DB free](try-free.md) before you commit.
36+
2937
## Create diagnostic settings
3038

39+
Here, we walk through the process of creating diagnostic settings for your account.
40+
3141
### [Azure portal](#tab/azure-portal)
3242

3343
1. Sign into the [Azure portal](https://portal.azure.com).
@@ -114,7 +124,6 @@ Use the [Azure Monitor REST API](/rest/api/monitor/diagnosticsettings/createorup
114124
> [!NOTE]
115125
> The URI for the Microsoft Insights subresource is in this format: `subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP}/providers/Microsoft.DocumentDb/databaseAccounts/{ACCOUNT_NAME}/providers/microsoft.insights/diagnosticSettings/{DIAGNOSTIC_SETTING_NAME}`. For more information about Azure Cosmos DB resource URIs, see [resource URI syntax for Azure Cosmos DB REST API](/rest/api/cosmos-db/cosmosdb-resource-uri-syntax-for-rest).
116126
117-
118127
1. Set the body of the request to this JSON payload.
119128
120129
```json
@@ -184,6 +193,210 @@ Use the [Azure Monitor REST API](/rest/api/monitor/diagnosticsettings/createorup
184193
}
185194
```
186195
196+
### [ARM Template](#tab/azure-resource-manager-template)
197+
198+
Here, use an [Azure Resource Manager (ARM) template](../azure-resource-manager/templates/index.yml) to create a diagnostic setting.
199+
200+
> [!NOTE]
201+
> Set the **logAnalyticsDestinationType** property to **Dedicated** to enable resource-specific tables.
202+
203+
1. Create the following JSON template file to deploy diagnostic settings for your Azure Cosmos DB resource.
204+
205+
```json
206+
{
207+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
208+
"contentVersion": "1.0.0.0",
209+
"parameters": {
210+
"settingName": {
211+
"type": "string",
212+
"metadata": {
213+
"description": "The name of the diagnostic setting."
214+
}
215+
},
216+
"dbName": {
217+
"type": "string",
218+
"metadata": {
219+
"description": "The name of the database."
220+
}
221+
},
222+
"workspaceId": {
223+
"type": "string",
224+
"metadata": {
225+
"description": "The resource Id of the workspace."
226+
}
227+
},
228+
"storageAccountId": {
229+
"type": "string",
230+
"metadata": {
231+
"description": "The resource Id of the storage account."
232+
}
233+
},
234+
"eventHubAuthorizationRuleId": {
235+
"type": "string",
236+
"metadata": {
237+
"description": "The resource Id of the event hub authorization rule."
238+
}
239+
},
240+
"eventHubName": {
241+
"type": "string",
242+
"metadata": {
243+
"description": "The name of the event hub."
244+
}
245+
}
246+
},
247+
"resources": [
248+
{
249+
"type": "Microsoft.Insights/diagnosticSettings",
250+
"apiVersion": "2021-05-01-preview",
251+
"scope": "[format('Microsoft.DocumentDB/databaseAccounts/{0}', parameters('dbName'))]",
252+
"name": "[parameters('settingName')]",
253+
"properties": {
254+
"workspaceId": "[parameters('workspaceId')]",
255+
"storageAccountId": "[parameters('storageAccountId')]",
256+
"eventHubAuthorizationRuleId": "[parameters('eventHubAuthorizationRuleId')]",
257+
"eventHubName": "[parameters('eventHubName')]",
258+
"logAnalyticsDestinationType": "[parameters('logAnalyticsDestinationType')]",
259+
"logs": [
260+
{
261+
"category": "DataPlaneRequests",
262+
"categoryGroup": null,
263+
"enabled": true,
264+
"retentionPolicy": {
265+
"days": 0,
266+
"enabled": false
267+
}
268+
},
269+
{
270+
"category": "MongoRequests",
271+
"categoryGroup": null,
272+
"enabled": false,
273+
"retentionPolicy": {
274+
"days": 0,
275+
"enabled": false
276+
}
277+
},
278+
{
279+
"category": "QueryRuntimeStatistics",
280+
"categoryGroup": null,
281+
"enabled": true,
282+
"retentionPolicy": {
283+
"days": 0,
284+
"enabled": false
285+
}
286+
},
287+
{
288+
"category": "PartitionKeyStatistics",
289+
"categoryGroup": null,
290+
"enabled": true,
291+
"retentionPolicy": {
292+
"days": 0,
293+
"enabled": false
294+
}
295+
},
296+
{
297+
"category": "PartitionKeyRUConsumption",
298+
"categoryGroup": null,
299+
"enabled": true,
300+
"retentionPolicy": {
301+
"days": 0,
302+
"enabled": false
303+
}
304+
},
305+
{
306+
"category": "ControlPlaneRequests",
307+
"categoryGroup": null,
308+
"enabled": true,
309+
"retentionPolicy": {
310+
"days": 0,
311+
"enabled": false
312+
}
313+
},
314+
{
315+
"category": "CassandraRequests",
316+
"categoryGroup": null,
317+
"enabled": false,
318+
"retentionPolicy": {
319+
"days": 0,
320+
"enabled": false
321+
}
322+
},
323+
{
324+
"category": "GremlinRequests",
325+
"categoryGroup": null,
326+
"enabled": false,
327+
"retentionPolicy": {
328+
"days": 0,
329+
"enabled": false
330+
}
331+
},
332+
{
333+
"category": "TableApiRequests",
334+
"categoryGroup": null,
335+
"enabled": false,
336+
"retentionPolicy": {
337+
"days": 0,
338+
"enabled": false
339+
}
340+
}
341+
],
342+
"metrics": [
343+
{
344+
"timeGrain": null,
345+
"enabled": false,
346+
"retentionPolicy": {
347+
"days": 0,
348+
"enabled": false
349+
},
350+
"category": "Requests"
351+
}
352+
]
353+
}
354+
}
355+
]
356+
}
357+
```
358+
359+
1. Create the following JSON parameter file with settings appropriate for your Azure Cosmos DB resource.
360+
361+
```json
362+
{
363+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
364+
"contentVersion": "1.0.0.0",
365+
"parameters": {
366+
"settingName": {
367+
"value": "{DIAGNOSTIC_SETTING_NAME}"
368+
},
369+
"dbName": {
370+
"value": "{ACCOUNT_NAME}"
371+
},
372+
"workspaceId": {
373+
"value": "/subscriptions/{SUBSCRIPTION_ID}/resourcegroups/{RESOURCE_GROUP}/providers/microsoft.operationalinsights/workspaces/{WORKSPACE_NAME}"
374+
},
375+
"storageAccountId": {
376+
"value": "/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP}/providers/Microsoft.Storage/storageAccounts/{STORAGE_ACCOUNT_NAME}"
377+
},
378+
"eventHubAuthorizationRuleId": {
379+
"value": "/subscriptions/{SUBSCRIPTION_ID}/resourcegroups{RESOURCE_GROUP}/providers/Microsoft.EventHub/namespaces/{EVENTHUB_NAMESPACE}/authorizationrules/{EVENTHUB_POLICY_NAME}"
380+
},
381+
"eventHubName": {
382+
"value": "{EVENTHUB_NAME}"
383+
},
384+
"logAnalyticsDestinationType": {
385+
"value": "Dedicated"
386+
}
387+
}
388+
}
389+
```
390+
391+
1. Deploy the template using [`az deployment group create`](/cli/azure/deployment/group#az-deployment-group-create).
392+
393+
```azurecli
394+
az deployment group create \
395+
--resource-group <resource-group-name> \
396+
--template-file <path-to-template>.json \
397+
--parameters @<parameters-file-name>.json
398+
```
399+
187400
---
188401
189402
## Enable full-text query for logging query text
@@ -197,13 +410,13 @@ Azure Cosmos DB provides advanced logging for detailed troubleshooting. By enabl
197410
198411
1. To enable this feature, navigate to the `Features` page in your Azure Cosmos DB account.
199412
200-
:::image type="content" source="media/monitor/full-text-query-features.png" lightbox="media/monitor/full-text-query-features.png" alt-text="Screenshot of navigation to the Features page.":::
413+
:::image type="content" source="media/monitor/full-text-query-features.png" lightbox="media/monitor/full-text-query-features.png" alt-text="Screenshot of the navigation process to the Features page.":::
201414
202415
2. Select `Enable`. This setting is applied within a few minutes. All newly ingested logs have the full-text or PIICommand text for each request.
203416
204-
:::image type="content" source="media/monitor/select-enable-full-text.png" alt-text="Screenshot of full-text being enabled.":::
417+
:::image type="content" source="media/monitor/select-enable-full-text.png" alt-text="Screenshot of the full-text feature being enabled.":::
205418
206-
### [Azure CLI / REST API](#tab/azure-cli+rest-api)
419+
### [Azure CLI / REST API / ARM template](#tab/azure-cli+rest-api+azure-resource-manager-template)
207420
208421
1. Ensure you're logged in to the Azure CLI. For more information, see [sign in with Azure CLI](/cli/azure/authenticate-azure-cli). Optionally, ensure that you've configured the active subscription for your CLI. For more information, see [change the active Azure CLI subscription](/cli/azure/manage-azure-subscriptions-azure-cli#change-the-active-subscription).
209422
@@ -303,7 +516,5 @@ To learn how to query using these newly enabled features, see:
303516
304517
## Next steps
305518
306-
- For a reference of the log and metric data, see [monitoring Azure Cosmos DB data reference](monitor-reference.md#resource-logs).
307-
- For more information on how to query resource-specific tables, see [troubleshooting using resource-specific tables](monitor-logs-basic-queries.md#resource-specific-queries).
308-
- For more information on how to query AzureDiagnostics tables, see [troubleshooting using AzureDiagnostics tables](monitor-logs-basic-queries.md#azure-diagnostics-queries).
309-
- For detailed information about how to create a diagnostic setting by using the Azure portal, CLI, or PowerShell, see [create diagnostic setting to collect platform logs and metrics in Azure](../azure-monitor/essentials/diagnostic-settings.md) article.
519+
> [!div class="nextstepaction"]
520+
> [Monitoring Azure Cosmos DB data reference](monitor-reference.md#resource-logs)

0 commit comments

Comments
 (0)