銷售: 1-800-867-1380

Azure 診斷 (SDK 2.0) 中的重大變更

更新日期: 2014年12月

Windows Azure SDK for .NET 2.0 版中的 Windows Azure 診斷程式庫 (Microsoft.WindowsAzure.Diagnostics.dll) 包含從程式庫 1.8 版所做的最新變更。Windows Azure 診斷用戶端程式庫已更新,而不再依存於儲存體用戶端程式庫 1.7 版,但您可能必須在程式碼中進行變更。此變更讓您的應用程式更容易使用較新版的儲存體用戶端程式庫。本主題提供有關 1.8 版與 2.0 版之間所做變更的資訊,和有助於您將現有的應用程式移轉至 2.0 發行版的提示。

已從 Microsoft.WindowsAzure.DiagnosticsMicrosoft.WindowsAzure.Diagnostics.Management API 中移除對儲存體用戶端程式庫的相依性。有數種方法可接受將 CloudStorageAccount 物件作為輸入參數,以指定與您的應用程式相關聯的 Windows Azure 儲存體帳戶 (您的應用程式診斷組態儲存所在的儲存體帳戶)。這些方法已由新的方法所取代,而新方法可接受以連線字串來指定儲存體帳戶,而不使用 CloudStorageAccount 物件。

下表列出 Microsoft.WindowsAzure.Diagnostics.Management 命名空間中已過時的方法與新方法之間的對應:

 

1.8 版 (過時) 2.0 版 (新)

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

下表列出 Microsoft.WindowsAzure.Diagnostics 命名空間中已過時的方法與新方法之間的對應:

Microsoft.WindowsAzure.Diagnostics

1.8 版 (過時) 2.0 版 (新)

DiagnosticMonitor.Start(CloudStorageAccount storageAccount, DiagnosticMonitorConfiguration initialConfiguration)

StartWithConnectionString

DiagnosticMonitor.UpdateStorageAccount(CloudStorageAccount storageAccount)

UpdateStorageAccount

下列範例會使用 DeploymentDiagnosticManager 物件,從遠端變更特定角色中所有執行個體的診斷組態。對於已儲存的集合和組態變更,會啟用兩個效能計數器。此範例使用 1.8 版的 Microsoft.WindowsAzure.Diagnostics.dll 組件,且 DeploymentDiagnosticManager 建構函式可接式以 CloudStorageAccount 作為輸入參數。CloudStorageAccount 物件會用來指定應用程式的診斷組態儲存所在的儲存體帳戶。

// 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);
}

以下是以前述範例重寫而使用 2.0 版 Microsoft.WindowsAzure.Diagnostics.dll 組件的範例。DeploymentDiagnosticManager 建構函式現在可接受以連線字串來指定儲存體帳戶,而不使用 CloudStorageAccount 物件。

// 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);
}

本文對您有任何幫助嗎?
(剩餘 1500 個字元)
感謝您提供意見
顯示:
© 2015 Microsoft