Skip to content

Commit 5776109

Browse files
committed
DCR samples
1 parent a7df4b8 commit 5776109

File tree

2 files changed

+191
-9
lines changed

2 files changed

+191
-9
lines changed

articles/azure-monitor/essentials/data-collection-rule-create-edit.md

Lines changed: 188 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,29 @@ The following table lists methods to create data collection scenarios using the
3232
| | [Enable VM insights overview](../vm/vminsights-enable-overview.md) | When you enable VM insights on a VM, the Azure Monitor agent is installed, and a DCR is created that collects a predefined set of performance counters. You shouldn't modify this DCR. |
3333
| Container insights | [Enable Container insights](../containers/kubernetes-monitoring-enable.md#enable-prometheus-and-grafana) | When you enable Container insights on a Kubernetes cluster, a containerized version of the Azure Monitor agent is installed, and a DCR is created that collects data according to the configuration you selected. You may need to modify this DCR to add a transformation. |
3434
| Text or JSON logs | [Collect logs from a text or JSON file with Azure Monitor Agent](../agents/data-collection-text-log.md?tabs=portal) | Use the Azure portal to create a DCR to collect entries from a text log on a machine with Azure Monitor Agent. |
35-
| Workspace transformation | [Add a transformation in a workspace data collection rule using the Azure portal](../logs/tutorial-workspace-transformations-portal.md) | Create a transformation for any supported table in a Log Analytics workspace. The transformation is defined in a DCR that's then associated with the workspace. It's applied to any data sent to that table from a legacy workload that doesn't use a DCR. |
3635

3736

3837
## Manually create a DCR
3938
To manually create a DCR, create a JSON file using the appropriate configuration for the data collection that you're configuring. Start with one of the [sample DCRs](./data-collection-rule-samples.md) and use information in [Structure of a data collection rule in Azure Monitor](./data-collection-rule-structure.md) to modify the JSON file for your particular environment and requirements.
4039

4140
Once you have the JSON file created, you can use any of the following methods to create the DCR:
4241

43-
## [CLI](#tab/CLI)
42+
### [CLI](#tab/CLI)
4443
Use the [az monitor data-collection rule create](/cli/azure/monitor/data-collection/rule) command to create a DCR from your JSON file using the Azure CLI as shown in the following example.
4544

4645
```azurecli
4746
az monitor data-collection rule create --location 'eastus' --resource-group 'my-resource-group' --name 'myDCRName' --rule-file 'C:\MyNewDCR.json' --description 'This is my new DCR'
4847
```
4948

50-
## [PowerShell](#tab/powershell)
49+
### [PowerShell](#tab/powershell)
5150
Use the [New-AzDataCollectionRule](/powershell/module/az.monitor/new-azdatacollectionrule) cmdlet to create the DCR from your JSON file using PowerShell as shown in the following example.
5251

5352
```powershell
5453
New-AzDataCollectionRule -Location 'east-us' -ResourceGroupName 'my-resource-group' -RuleName 'myDCRName' -RuleFile 'C:\MyNewDCR.json' -Description 'This is my new DCR'
5554
```
5655

5756

58-
## [API](#tab/api)
57+
### [API](#tab/api)
5958
Use the [DCR create API](/rest/api/monitor/data-collection-rules/create) to create the DCR from your JSON file. You can use any method to call a REST API as shown in the following examples.
6059

6160

@@ -74,10 +73,15 @@ az rest --method put --url $ResourceId"?api-version=2022-06-01" --body @$FilePat
7473
```
7574

7675

77-
## [ARM](#tab/arm)
78-
Using an ARM template, you can define parameters so you can provide particular values at the time you install the DCR. This allows you to use a single template for multiple installations. Use the following template, copying in the JSON for your DCR and adding any other parameters you want to use.
76+
### [ARM](#tab/arm)
7977

80-
See [Deploy the sample templates](../resource-manager-samples.md#deploy-the-sample-templates) for different methods to deploy ARM templates.
78+
### DCR
79+
80+
See the follow references for defining DCRs and associations in a template.
81+
- [Data collection rules](/azure/templates/microsoft.insights/datacollectionrules)
82+
- [Data collection rule associations](/azure/templates/microsoft.insights/datacollectionruleassociations)
83+
84+
Use the following template to create a DCR using information from [Structure of a data collection rule in Azure Monitor](./data-collection-rule-structure.md) and [Sample data collection rules (DCRs) in Azure Monitor](./data-collection-rule-samples.md) to define the `dcr-properties`.
8185

8286
```json
8387
{
@@ -110,6 +114,183 @@ See [Deploy the sample templates](../resource-manager-samples.md#deploy-the-samp
110114
]
111115
}
112116

117+
```
118+
119+
### DCR Association -Azure VM
120+
121+
#### Bicep
122+
123+
```bicep
124+
@description('The name of the virtual machine.')
125+
param vmName string
126+
127+
@description('The name of the association.')
128+
param associationName string
129+
130+
@description('The resource ID of the data collection rule.')
131+
param dataCollectionRuleId string
132+
133+
resource vm 'Microsoft.Compute/virtualMachines@2021-11-01' existing = {
134+
name: vmName
135+
}
136+
137+
resource association 'Microsoft.Insights/dataCollectionRuleAssociations@2021-09-01-preview' = {
138+
name: associationName
139+
scope: vm
140+
properties: {
141+
description: 'Association of data collection rule. Deleting this association will break the data collection for this virtual machine.'
142+
dataCollectionRuleId: dataCollectionRuleId
143+
}
144+
}
145+
```
146+
147+
#### ARM
148+
149+
```json
150+
{
151+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
152+
"contentVersion": "1.0.0.0",
153+
"parameters": {
154+
"vmName": {
155+
"type": "string",
156+
"metadata": {
157+
"description": "The name of the virtual machine."
158+
}
159+
},
160+
"associationName": {
161+
"type": "string",
162+
"metadata": {
163+
"description": "The name of the association."
164+
}
165+
},
166+
"dataCollectionRuleId": {
167+
"type": "string",
168+
"metadata": {
169+
"description": "The resource ID of the data collection rule."
170+
}
171+
}
172+
},
173+
"resources": [
174+
{
175+
"type": "Microsoft.Insights/dataCollectionRuleAssociations",
176+
"apiVersion": "2021-09-01-preview",
177+
"scope": "[format('Microsoft.Compute/virtualMachines/{0}', parameters('vmName'))]",
178+
"name": "[parameters('associationName')]",
179+
"properties": {
180+
"description": "Association of data collection rule. Deleting this association will break the data collection for this virtual machine.",
181+
"dataCollectionRuleId": "[parameters('dataCollectionRuleId')]"
182+
}
183+
}
184+
]
185+
}
186+
```
187+
188+
#### Parameter file
189+
190+
```json
191+
{
192+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
193+
"contentVersion": "1.0.0.0",
194+
"parameters": {
195+
"vmName": {
196+
"value": "my-azure-vm"
197+
},
198+
"associationName": {
199+
"value": "my-windows-vm-my-dcr"
200+
},
201+
"dataCollectionRuleId": {
202+
"value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/microsoft.insights/datacollectionrules/my-dcr"
203+
}
204+
}
205+
}
206+
```
207+
### DCR Association -Arc-enabled server
208+
209+
#### Bicep
210+
211+
```bicep
212+
@description('The name of the virtual machine.')
213+
param vmName string
214+
215+
@description('The name of the association.')
216+
param associationName string
217+
218+
@description('The resource ID of the data collection rule.')
219+
param dataCollectionRuleId string
220+
221+
resource vm 'Microsoft.HybridCompute/machines@2021-11-01' existing = {
222+
name: vmName
223+
}
224+
225+
resource association 'Microsoft.Insights/dataCollectionRuleAssociations@2021-09-01-preview' = {
226+
name: associationName
227+
scope: vm
228+
properties: {
229+
description: 'Association of data collection rule. Deleting this association will break the data collection for this Arc server.'
230+
dataCollectionRuleId: dataCollectionRuleId
231+
}
232+
}
233+
```
234+
235+
#### ARM
236+
237+
```json
238+
{
239+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
240+
"contentVersion": "1.0.0.0",
241+
"parameters": {
242+
"vmName": {
243+
"type": "string",
244+
"metadata": {
245+
"description": "The name of the virtual machine."
246+
}
247+
},
248+
"associationName": {
249+
"type": "string",
250+
"metadata": {
251+
"description": "The name of the association."
252+
}
253+
},
254+
"dataCollectionRuleId": {
255+
"type": "string",
256+
"metadata": {
257+
"description": "The resource ID of the data collection rule."
258+
}
259+
}
260+
},
261+
"resources": [
262+
{
263+
"type": "Microsoft.Insights/dataCollectionRuleAssociations",
264+
"apiVersion": "2021-09-01-preview",
265+
"scope": "[format('Microsoft.HybridCompute/machines/{0}', parameters('vmName'))]",
266+
"name": "[parameters('associationName')]",
267+
"properties": {
268+
"description": "Association of data collection rule. Deleting this association will break the data collection for this Arc server.",
269+
"dataCollectionRuleId": "[parameters('dataCollectionRuleId')]"
270+
}
271+
}
272+
]
273+
}
274+
```
275+
276+
#### Parameter file
277+
278+
```json
279+
{
280+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
281+
"contentVersion": "1.0.0.0",
282+
"parameters": {
283+
"vmName": {
284+
"value": "my-hybrid-vm"
285+
},
286+
"associationName": {
287+
"value": "my-windows-vm-my-dcr"
288+
},
289+
"dataCollectionRuleId": {
290+
"value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/microsoft.insights/datacollectionrules/my-dcr"
291+
}
292+
}
293+
}
113294
```
114295
---
115296

articles/azure-monitor/essentials/data-collection-transformations-workspace.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ See [Tables that support transformations in Azure Monitor Logs](../logs/tables-f
2626
See the following tutorials for creating a workspace transformation DCR:
2727

2828
- [Add workspace transformation to Azure Monitor Logs by using the Azure portal](../logs/tutorial-workspace-transformations-portal.md)
29-
- [Add workspace transformation to Azure Monitor Logs by using Resource Manager templates](../logs/tutorial-workspace-transformations-api.md) |
29+
- [Add workspace transformation to Azure Monitor Logs by using Resource Manager templates](../logs/tutorial-workspace-transformations-api.md)
3030

3131

3232
## Next steps
3333

34-
[Create a data collection rule](../agents/data-collection-rule-azure-monitor-agent.md) and an association to it from a virtual machine by using Azure Monitor Agent.
34+
- [Use the Azure portal to create a workspace transformation DCR.](../logs/tutorial-workspace-transformations-api.md)
35+
- [Use ARM templates to create a workspace transformation DCR.](../logs/tutorial-workspace-transformations-portal.md)
3536

0 commit comments

Comments
 (0)