Skip to content

Commit 855ec2c

Browse files
authored
Merge pull request #106070 from johnkemnetz/patch-2
fix the powershell sample
2 parents bf7fa92 + e9d243f commit 855ec2c

File tree

1 file changed

+19
-70
lines changed

1 file changed

+19
-70
lines changed

articles/virtual-machines/extensions/diagnostics-linux.md

Lines changed: 19 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -89,80 +89,29 @@ The URL for the sample configuration, and its contents, are subject to change. D
8989
#### PowerShell sample
9090

9191
```Powershell
92-
// Set your Azure VM diagnostics variables correctly below - don't forget to replace the VMResourceID
92+
$storageAccountName = "johnkemtest"
93+
$storageAccountResourceGroup = "generalTest"
94+
$vmName = "johnkemlinuxtest"
95+
$VMresourceGroup = "generalTest"
9396
94-
$SASKey = '<SASKeyForDiagStorageAccount>'
97+
# Get the VM object
98+
$vm = Get-AzVM -Name $vmName -ResourceGroupName $VMresourceGroup
9599
96-
$ladCfg = "{
97-
'diagnosticMonitorConfiguration': {
98-
'performanceCounters': {
99-
'sinks': 'WADMetricEventHub,WADMetricJsonBlob',
100-
'performanceCounterConfiguration': [
101-
{
102-
'unit': 'Percent',
103-
'type': 'builtin',
104-
'counter': 'PercentProcessorTime',
105-
'counterSpecifier': '/builtin/Processor/PercentProcessorTime',
106-
'annotation': [
107-
{
108-
'locale': 'en-us',
109-
'displayName': 'Aggregate CPU %utilization'
110-
}
111-
],
112-
'condition': 'IsAggregate=TRUE',
113-
'class': 'Processor'
114-
},
115-
{
116-
'unit': 'Bytes',
117-
'type': 'builtin',
118-
'counter': 'UsedSpace',
119-
'counterSpecifier': '/builtin/FileSystem/UsedSpace',
120-
'annotation': [
121-
{
122-
'locale': 'en-us',
123-
'displayName': 'Used disk space on /'
124-
}
125-
],
126-
'condition': 'Name='/'',
127-
'class': 'Filesystem'
128-
}
129-
]
130-
},
131-
'metrics': {
132-
'metricAggregation': [
133-
{
134-
'scheduledTransferPeriod': 'PT1H'
135-
},
136-
{
137-
'scheduledTransferPeriod': 'PT1M'
138-
}
139-
],
140-
'resourceId': '<VMResourceID>'
141-
},
142-
'eventVolume': 'Large',
143-
'syslogEvents': {
144-
'sinks': 'SyslogJsonBlob,LoggingEventHub',
145-
'syslogEventConfiguration': {
146-
'LOG_USER': 'LOG_INFO'
147-
}
148-
}
149-
}
150-
}"
151-
$ladCfg = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($ladCfg))
152-
$perfCfg = "[
153-
{
154-
'query': 'SELECT PercentProcessorTime, PercentIdleTime FROM SCX_ProcessorStatisticalInformation WHERE Name='_TOTAL'',
155-
'table': 'LinuxCpu',
156-
'frequency': 60,
157-
'sinks': 'LinuxCpuJsonBlob'
158-
}
159-
]"
100+
# Get the public settings template from GitHub and update the templated values for storage account and resource ID
101+
$publicSettings = (Invoke-WebRequest -Uri https://raw.githubusercontent.com/Azure/azure-linux-extensions/master/Diagnostic/tests/lad_2_3_compatible_portal_pub_settings.json).Content
102+
$publicSettings = $publicSettings.Replace('__DIAGNOSTIC_STORAGE_ACCOUNT__', $storageAccountName)
103+
$publicSettings = $publicSettings.Replace('__VM_RESOURCE_ID__', $vm.Id)
104+
105+
# If you have your own customized public settings, you can inline those rather than using the template above: $publicSettings = '{"ladCfg": { ... },}'
160106
161-
// Get the VM Resource
162-
Get-AzureRmVM -ResourceGroupName <RGName> -VMName <VMName>
107+
# Generate a SAS token for the agent to use to authenticate with the storage account
108+
$sasToken = New-AzStorageAccountSASToken -Service Blob,Table -ResourceType Service,Container,Object -Permission "racwdlup" -Context (Get-AzStorageAccount -ResourceGroupName $storageAccountResourceGroup -AccountName $storageAccountName).Context
109+
110+
# Build the protected settings (storage account SAS token)
111+
$protectedSettings="{'storageAccountName': '$storageAccountName', 'storageAccountSasToken': '$sasToken'}"
163112
164-
// Finally tell Azure to install and enable the extension
165-
Set-AzureRmVMExtension -ExtensionType LinuxDiagnostic -Publisher Microsoft.Azure.Diagnostics -ResourceGroupName <RGName> -VMName <VMName> -Location <Location> -Name LinuxDiagnostic -Settings @{'StorageAccount'='<DiagStorageAccount>'; 'sampleRateInSeconds' = '15' ; 'ladCfg'=$ladCfg; 'perfCfg' = $perfCfg} -ProtectedSettings @{'storageAccountName' = '<DiagStorageAccount>'; 'storageAccountSasToken' = $SASKey } -TypeHandlerVersion 3.0
113+
# Finally install the extension with the settings built above
114+
Set-AzVMExtension -ResourceGroupName $VMresourceGroup -VMName $vmName -Location $vm.Location -ExtensionType LinuxDiagnostic -Publisher Microsoft.Azure.Diagnostics -Name LinuxDiagnostic -SettingString $publicSettings -ProtectedSettingString $protectedSettings -TypeHandlerVersion 3.0
166115
```
167116

168117
### Updating the extension settings

0 commit comments

Comments
 (0)