Diagnostische gegevens inSchakelen in Azure Cloud Services (klassiek) met behulp van PowerShell

Belangrijk

Cloud Services (klassiek) is nu afgeschaft voor nieuwe klanten en wordt op 31 augustus 2024 voor alle klanten buiten gebruik gesteld. Nieuwe implementaties moeten gebruikmaken van het nieuwe op Azure Resource Manager gebaseerde implementatiemodel Azure Cloud Services (uitgebreide ondersteuning).

U kunt diagnostische gegevens verzamelen, zoals toepassingslogboeken, prestatiemeteritems, enzovoort. van een cloudservice met behulp van de extensie Azure Diagnostics. In dit artikel wordt beschreven hoe u de Azure Diagnostics-extensie inschakelt voor een cloudservice met behulp van PowerShell. Zie Azure PowerShell installeren en configureren voor de vereisten die nodig zijn voor dit artikel.

De extensie voor diagnostische gegevens inschakelen als onderdeel van het implementeren van een cloudservice

Deze benadering is van toepassing op scenario's van het type continue integratie, waarbij de extensie voor diagnostische gegevens kan worden ingeschakeld als onderdeel van de implementatie van de cloudservice. Wanneer u een nieuwe cloudservice-implementatie maakt, kunt u de diagnostische extensie inschakelen door de parameter ExtensionConfiguration door te geven aan de cmdlet New-AzureDeployment . De parameter ExtensionConfiguration gebruikt een matrix met diagnostische configuraties die kunnen worden gemaakt met behulp van de cmdlet New-AzureServiceDiagnosticsExtensionConfig .

In het volgende voorbeeld ziet u hoe u diagnostische gegevens kunt inschakelen voor een cloudservice met een WebRole en WorkerRole, elk met een andere diagnostische configuratie.

$service_name = "MyService"
$service_package = "CloudService.cspkg"
$service_config = "ServiceConfiguration.Cloud.cscfg"
$webrole_diagconfigpath = "MyService.WebRole.PubConfig.xml"
$workerrole_diagconfigpath = "MyService.WorkerRole.PubConfig.xml"

$webrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WebRole" -DiagnosticsConfigurationPath $webrole_diagconfigpath
$workerrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole" -DiagnosticsConfigurationPath $workerrole_diagconfigpath

New-AzureDeployment -ServiceName $service_name -Slot Production -Package $service_package -Configuration $service_config -ExtensionConfiguration @($webrole_diagconfig,$workerrole_diagconfig)

Als in het configuratiebestand voor diagnostische gegevens een StorageAccount element met een opslagaccountnaam wordt opgegeven, wordt dat opslagaccount automatisch door de New-AzureServiceDiagnosticsExtensionConfig cmdlet gebruikt. Dit werkt alleen als het opslagaccount zich in hetzelfde abonnement bevindt als de cloudservice die wordt geïmplementeerd.

Vanaf Azure SDK 2.6 bevatten de extensieconfiguratiebestanden die worden gegenereerd door de msBuild-publicatiedoeluitvoer de naam van het opslagaccount op basis van de diagnostische configuratiereeks die is opgegeven in het serviceconfiguratiebestand (.cscfg). In het onderstaande script ziet u hoe u de extensieconfiguratiebestanden van de uitvoer van het publicatiedoel parseert en diagnostische extensie configureert voor elke rol bij het implementeren van de cloudservice.

$service_name = "MyService"
$service_package = "C:\build\output\CloudService.cspkg"
$service_config = "C:\build\output\ServiceConfiguration.Cloud.cscfg"

#Find the Extensions path based on service configuration file
$extensionsSearchPath = Join-Path -Path (Split-Path -Parent $service_config) -ChildPath "Extensions"

$diagnosticsExtensions = Get-ChildItem -Path $extensionsSearchPath -Filter "PaaSDiagnostics.*.PubConfig.xml"
$diagnosticsConfigurations = @()
foreach ($extPath in $diagnosticsExtensions)
{
    #Find the RoleName based on file naming convention PaaSDiagnostics.<RoleName>.PubConfig.xml
    $roleName = ""
    $roles = $extPath -split ".",0,"simplematch"
    if ($roles -is [system.array] -and $roles.Length -gt 1)
    {
        $roleName = $roles[1]
        $x = 2
        while ($x -le $roles.Length)
            {
               if ($roles[$x] -ne "PubConfig")
                {
                    $roleName = $roleName + "." + $roles[$x]
                }
                else
                {
                    break
                }
                $x++
            }
        $fullExtPath = Join-Path -path $extensionsSearchPath -ChildPath $extPath
        $diagnosticsconfig = New-AzureServiceDiagnosticsExtensionConfig -Role $roleName -DiagnosticsConfigurationPath $fullExtPath
        $diagnosticsConfigurations += $diagnosticsconfig
    }
}
New-AzureDeployment -ServiceName $service_name -Slot Production -Package $service_package -Configuration $service_config -ExtensionConfiguration $diagnosticsConfigurations

Visual Studio Online gebruikt een vergelijkbare benadering voor geautomatiseerde implementaties van Cloud Services met de diagnostische extensie. Zie Publish-AzureCloudDeployment.ps1 voor een volledig voorbeeld.

Als er geen StorageAccount is opgegeven in de diagnostische configuratie, moet u de parameter StorageAccountName doorgeven aan de cmdlet. Als de parameter StorageAccountName is opgegeven, gebruikt de cmdlet altijd het opslagaccount dat is opgegeven in de parameter en niet het account dat is opgegeven in het configuratiebestand voor diagnostische gegevens.

Als het opslagaccount voor diagnostische gegevens zich in een ander abonnement dan de cloudservice bevindt, moet u de parameters StorageAccountName en StorageAccountKey expliciet doorgeven aan de cmdlet. De parameter StorageAccountKey is niet nodig wanneer het opslagaccount voor diagnostische gegevens zich in hetzelfde abonnement bevindt, omdat de cmdlet automatisch een query kan uitvoeren en de sleutelwaarde kan instellen bij het inschakelen van de diagnostische extensie. Als het opslagaccount voor diagnostische gegevens zich echter in een ander abonnement bevindt, kan de cmdlet de sleutel mogelijk niet automatisch ophalen en moet u de sleutel expliciet opgeven via de parameter StorageAccountKey .

$webrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WebRole" -DiagnosticsConfigurationPath $webrole_diagconfigpath -StorageAccountName $diagnosticsstorage_name -StorageAccountKey $diagnosticsstorage_key
$workerrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole" -DiagnosticsConfigurationPath $workerrole_diagconfigpath -StorageAccountName $diagnosticsstorage_name -StorageAccountKey $diagnosticsstorage_key

De extensie voor diagnostische gegevens inschakelen voor een bestaande cloudservice

U kunt de cmdlet Set-AzureServiceDiagnosticsExtension gebruiken om de diagnostische configuratie in te schakelen of bij te werken voor een cloudservice die al wordt uitgevoerd.

Waarschuwing

Wanneer u diagnostische gegevens inschakelt voor een bestaande rol, worden alle extensies die u al hebt ingesteld, uitgeschakeld wanneer het pakket wordt geïmplementeerd. Deze omvatten:

  • Diagnostische gegevens van Microsoft Monitoring Agent
  • Microsoft Azure-beveiligingsbewaking
  • Microsoft Antimalware
  • Microsoft Monitoring Agent
  • Microsoft Service Profiler Agent
  • Windows Azure-domeinextensie
  • Windows Azure Diagnostics-extensie
  • Windows Azure Extern bureaublad-extensie
  • Windows Azure-logboekverzamelaar

U kunt uw extensies opnieuw instellen via de Azure Portal of PowerShell nadat u de bijgewerkte rol hebt geïmplementeerd.

$service_name = "MyService"
$webrole_diagconfigpath = "MyService.WebRole.PubConfig.xml"
$workerrole_diagconfigpath = "MyService.WorkerRole.PubConfig.xml"

$webrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WebRole" -DiagnosticsConfigurationPath $webrole_diagconfigpath
$workerrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole" -DiagnosticsConfigurationPath $workerrole_diagconfigpath

Set-AzureServiceDiagnosticsExtension -DiagnosticsConfiguration @($webrole_diagconfig,$workerrole_diagconfig) -ServiceName $service_name

De huidige configuratie van de extensie voor diagnostische gegevens ophalen

Gebruik de cmdlet Get-AzureServiceDiagnosticsExtension om de huidige diagnostische configuratie voor een cloudservice op te halen.

Get-AzureServiceDiagnosticsExtension -ServiceName "MyService"

De extensie voor diagnostische gegevens verwijderen

Als u diagnostische gegevens voor een cloudservice wilt uitschakelen, kunt u de cmdlet Remove-AzureServiceDiagnosticsExtension gebruiken.

Remove-AzureServiceDiagnosticsExtension -ServiceName "MyService"

Als u de diagnostische extensie hebt ingeschakeld met Set-AzureServiceDiagnosticsExtension of de New-AzureServiceDiagnosticsExtensionConfig zonder de parameter Role , kunt u de extensie verwijderen met Remove-AzureServiceDiagnosticsExtension zonder de parameter Role . Als de rolparameter is gebruikt bij het inschakelen van de extensie, moet deze ook worden gebruikt bij het verwijderen van de extensie.

De extensie voor diagnostische gegevens verwijderen voor elke afzonderlijke rol:

Remove-AzureServiceDiagnosticsExtension -ServiceName "MyService" -Role "WebRole"

Volgende stappen