2017-05-09 2 views
0

Ich möchte Azure Cloud-Diagnosedaten (insbesondere Dienstleistungsindikatoren) in eine lokale Protokolldatei auf einer Rechnerinstanz schreiben, anstatt sie auf einem Azure-Speicherkonto zu speichern. Wie würde ich das erreichen?Schreiben von Azure Cloud Service-Leistungsindikatoren in eine lokale Datei

Verwandte: Entsprechend dieser: Initialize or Change Azure Diagnostics Configuration "Diagnosedaten werden gesammelt und auf der Rolleninstanz gespeichert" standardmäßig. Wo werden diese Daten gespeichert? Ist dies die lokale Protokolldatei, die ich suche?

+0

Können Sie den Grund angeben, warum Sie diese Daten in einer lokalen Datei speichern möchten? –

Antwort

1

Ich versuche, lokale Datei zu bekommen, auch wenn ich versuche, Powershell-Befehl zu verwenden, aber ich kann auch die Leistungsindikatoren-Datei nicht finden.

Basis auf meiner Erfahrung ist es eine gute Praxis, die Aufzeichnung im Speicher zu speichern. Dann könnten wir das SDK verwenden, um Datensätze von mehreren Instanzen einfach abzufragen.

Wenn wir nur den Datensatz in die lokale Datei abrufen möchten. Wir könnten das Azure-Speicher-SDK verwenden, um den Datensatz von der WADPerformanceCountersTable abzurufen und die Datensätze als Umgehung in der lokalen Datei zu speichern.

Wenn C# -Code für Sie möglich ist, versuchen Sie bitte, den folgenden Code zu verwenden, der das Snippet von document ist.

/ Get the connection string. When using Microsoft Azure Cloud Services, it is recommended 
// you store your connection string using the Microsoft Azure service configuration 
// system (*.csdef and *.cscfg files). You can you use the CloudConfigurationManager type 
// to retrieve your storage connection string. If you're not using Cloud Services, 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. 

string connectionString = Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("StorageConnectionString"); 
//string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString; 

// Get a reference to the storage account using the connection string. You can also use the development 
// storage account (Storage Emulator) for local debugging. 
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); 
//CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; 

// Create the table client. 
CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); 

// Create the CloudTable object that represents the "WADPerformanceCountersTable" table. 
CloudTable table = tableClient.GetTableReference("WADPerformanceCountersTable"); 

// Create the table query, filter on a specific CounterName, DeploymentId and RoleInstance. 
TableQuery<PerformanceCountersEntity> query = new TableQuery<PerformanceCountersEntity>() 
    .Where(
    TableQuery.CombineFilters(
     TableQuery.GenerateFilterCondition("CounterName", QueryComparisons.Equal, @"\Processor(_Total)\% Processor Time"), 
     TableOperators.And, 
     TableQuery.CombineFilters(
     TableQuery.GenerateFilterCondition("DeploymentId", QueryComparisons.Equal, "ec26b7a1720447e1bcdeefc41c4892a3"), 
     TableOperators.And, 
     TableQuery.GenerateFilterCondition("RoleInstance", QueryComparisons.Equal, "WebRole1_IN_0") 
    ) 
) 
); 

// Execute the table query. 
IEnumerable<PerformanceCountersEntity> result = table.ExecuteQuery(query); 

// Process the query results and build a CSV file. 
StringBuilder sb = new StringBuilder("TimeStamp,EventTickCount,DeploymentId,Role,RoleInstance,CounterName,CounterValue\n"); 

foreach (PerformanceCountersEntity entity in result) 
{ 
    sb.Append(entity.Timestamp + "," + entity.EventTickCount + "," + entity.DeploymentId + "," 
    + entity.Role + "," + entity.RoleInstance + "," + entity.CounterName + "," + entity.CounterValue+"\n"); 
} 

StreamWriter sw = File.CreateText(@"C:\temp\PerfCounters.csv"); 
sw.Write(sb.ToString()); 
sw.Close(); 

Weitere Informationen darüber, wie Azure-Speichertabelle bedienen Sie sich bitte an die Get started with Azure Table storage beziehen.

+0

+1, das ist hilfreich, falls ich diesen Weg gehen muss. Zu Ihrer Information: Ich suche nach Möglichkeiten, die Leistungsindikatoren zu ermitteln, ohne sie an ein Azure-Speicherkonto zu senden, da ich sie gerne in einem System außerhalb der Azure-Umgebung speichern möchte. – BobbyA

Verwandte Themen