Exportar (0) Imprimir
Expandir Tudo

Breaking Changes in Windows Azure Diagnostics (SDK 2.0)

Atualizado: dezembro de 2013

The Windows Azure Diagnostics library (Microsoft.WindowsAzure.Diagnostics.dll) in Windows Azure SDK for .NET version 2.0 includes breaking changes from version 1.8 of the library. The Windows Azure Diagnostics client library has been updated so that it no longer has a dependency on the Storage Client Library version 1.7 and may require changes in your code. This change makes it easier for your application to use newer versions of the Storage Client Library. This topic provides information about what changed between versions 1.8 and 2.0 and tips to help you migrate existing applications to the version 2.0 release.

Changes from version 1.8

Dependencies on the Storage Client Library have been removed from the Microsoft.WindowsAzure.Diagnostics and Microsoft.WindowsAzure.Diagnostics.Management APIs. Several methods accepted a CloudStorageAccount object as an input parameter in order to specify the Windows Azure Storage account associated with your application (the storage account where your applications diagnostics configuration is stored). Those methods have been replaced with new methods that now accept a connection string instead of a CloudStorageAccount object in order to specify the storage account.

The following table shows the mapping between the deprecated and new methods in the Microsoft.WindowsAzure.Diagnostics.Management namespace:

 

Version 1.8 (deprecated) Version 2.0 (new)

CloudAccountDiagnosticMonitorExtensions.CreateDeploymentDiagnosticManager(this CloudStorageAccount storageAccount,string deploymentId)

CreateDeploymentDiagnosticManager

CloudAccountDiagnosticMonitorExtensions.CreateRoleInstanceDiagnosticManager(this CloudStorageAccount storageAccount, string deploymentId, string roleName, string roleInstanceId)

CreateRoleInstanceDiagnosticManager

OnDemandTransferInfo.FromQueueMessage(CloudQueueMessage queueMessage)

FromQueueMessage

DeploymentDiagnosticManager.DeploymentDiagnosticManager(CloudStorageAccount storageAccount, string deploymentId)

DeploymentDiagnosticManager

RoleInstanceDiagnosticManager(CloudStorageAccount storageAccount, string deploymentId, string roleName, string roleInstanceId)

RoleInstanceDiagnosticManager

The following table shows the mapping between the deprecated and new methods in the Microsoft.WindowsAzure.Diagnostics namespace:

Microsoft.WindowsAzure.Diagnostics

Version 1.8 (deprecated) Version 2.0 (new)

DiagnosticMonitor.Start(CloudStorageAccount storageAccount, DiagnosticMonitorConfiguration initialConfiguration)

StartWithConnectionString

DiagnosticMonitor.UpdateStorageAccount(CloudStorageAccount storageAccount)

UpdateStorageAccount

Code migration example

The following example remotely changes the diagnostics configuration of all the instances in a specific role using a DeploymentDiagnosticManager object. Two performance counters are enabled for collection and the configuration changes saved. This example uses version 1.8 of the Microsoft.WindowsAzure.Diagnostics.dll assembly and the DeploymentDiagnosticManager constructor accepts a CloudStorageAccount object as an input parameter. The CloudStorageAccount object is used to specify the storage account where your application’s diagnostics configuration is stored.

// Get the connection string. It's recommended that you store the connection string in 
// your web.config or app.config file. Use the ConfigurationManager type to retrieve your 
// storage connection string.  You can find the account name and key in the Windows Azure 
// Management Portal (http://manage.windowsazure.com).
//string connectionString = "DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<AccountKey>";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;

// The deployment ID and role name for your application can be obtained from the Windows 
// Azure Management Portal (http://manage.windowsazure.com). See your application dashboard 
// under Cloud Services.
string deploymentID = "2f10410d4a194b0fa8863365674828ba";
string roleName = "WebRole1";

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

// Get the DeploymentDiagnosticManager object for your deployment.
DeploymentDiagnosticManager diagManager = new DeploymentDiagnosticManager(storageAccount, deploymentID);

// Get the RoleInstanceDiagnosticManager object for each instance of your role.
IEnumerable<RoleInstanceDiagnosticManager> instanceManagers = diagManager.GetRoleInstanceDiagnosticManagersForRole(roleName);

// Add a performance counter for processor time.
PerformanceCounterConfiguration pccCPU = new PerformanceCounterConfiguration();
pccCPU.CounterSpecifier = @"\Processor(_Total)\% Processor Time";
pccCPU.SampleRate = perfSampleRate;

// Add a performance counter for available memory.
PerformanceCounterConfiguration pccMemory = new PerformanceCounterConfiguration();
pccMemory.CounterSpecifier = @"\Memory\Available Mbytes";
pccMemory.SampleRate = perfSampleRate;

// Iterate through the role instances and update the configuration.
foreach (var roleInstance in instanceManagers)
{
   DiagnosticMonitorConfiguration currentConfiguration = roleInstance.GetCurrentConfiguration();

   currentConfiguration.PerformanceCounters.DataSources.Add(pccCPU);
   currentConfiguration.PerformanceCounters.DataSources.Add(pccMemory);

   //Update the configuration
   roleInstance.SetCurrentConfiguration(currentConfiguration);
}

The following shows the previous example, re-written to use version 2.0 of the Microsoft.WindowsAzure.Diagnostics.dll assembly. The DeploymentDiagnosticManager constructor now accepts a connection string to the storage account instead of a CloudStorageAccount object.

// Get the connection string. It's recommended that you store the connection string in 
// your web.config or app.config file. Use the ConfigurationManager type to retrieve your 
// storage connection string.  You can find the account name and key in the Windows Azure 
// Management Portal (http://manage.windowsazure.com).
//string connectionString = "DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<AccountKey>";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;

// The deployment ID and role name for your application can be obtained from the Windows 
// Azure Management Portal (http://manage.windowsazure.com).  See your application dashboard 
// under Cloud Services.
string deploymentID = "e2ab8b6667644666ba627bdf6f5e4daa";
string roleName = "WebRole1";

// Get the DeploymentDiagnosticManager object for your deployment.
DeploymentDiagnosticManager diagManager = new DeploymentDiagnosticManager(connectionString, deploymentID);

// Get the RoleInstanceDiagnosticManager object for each instance of your role.
IEnumerable<RoleInstanceDiagnosticManager> instanceManagers = diagManager.GetRoleInstanceDiagnosticManagersForRole(roleName);

// Use 45 seconds for the performance counter sample rate.
TimeSpan perfSampleRate = TimeSpan.FromSeconds(45.0);

// Add a performance counter for processor time.
PerformanceCounterConfiguration pccCPU = new PerformanceCounterConfiguration();
pccCPU.CounterSpecifier = @"\Processor(_Total)\% Processor Time";
pccCPU.SampleRate = perfSampleRate;

// Add a performance counter for available memory.
PerformanceCounterConfiguration pccMemory = new PerformanceCounterConfiguration();
pccMemory.CounterSpecifier = @"\Memory\Available Mbytes";
pccMemory.SampleRate = perfSampleRate;

// Iterate through the role instances and update the configuration.
foreach (RoleInstanceDiagnosticManager roleInstance in instanceManagers)
{
   DiagnosticMonitorConfiguration currentConfiguration = roleInstance.GetCurrentConfiguration();

   currentConfiguration.PerformanceCounters.DataSources.Add(pccCPU);
   currentConfiguration.PerformanceCounters.DataSources.Add(pccMemory);

   roleInstance.SetCurrentConfiguration(currentConfiguration);
}

Mostrar:
© 2014 Microsoft