How to get Cloud Service (Hosted Service) diagnostic data using Java or Rest API?
We can get DiagnosticsConnectionString from Azure Portal for Roles and using which we can query to WADPerformanceCounter Table (Storage API).
Getting following exception while executing:
query:java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details. at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:113) at TestStorage.main(TestStorage.java:225) Caused by: com.microsoft.azure.storage.table.TableServiceException: Bad Request
@Prit, There is not any code in your question so that I couldn't figure out the issue which was caused by what.
So I post my steps and code here as reference for helping.
Copy the DIAGNOSTICS CONNECTION STRINGS
of one role of the Cloud Service at the tab CONFIGURE
of Cloud Service on Azure Management portal, the format of conection string is like DefaultEndpointsProtocol=https;AccountName=<storage-account-name>;AccountKey=<storage-key>
.
Use the GUI tool Micorsoft Azure Storage Explorer
to find & view the table WADPerformanceCounter
.
Code in Java to retrieve all diagnostic data as below.
import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.table.CloudTable;
import com.microsoft.azure.storage.table.CloudTableClient;
import com.microsoft.azure.storage.table.TableQuery;
import com.microsoft.azure.storage.table.TableServiceEntity;
public class WADPerformanceCounterReader {
public static final String storageConnectionString =
"DefaultEndpointsProtocol=https;"+
"AccountName=<storage-account-name>;"+
"AccountKey=<storage-key>";
public static void main(String[] args) {
try {
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the table client.
CloudTableClient tableClient = storageAccount.createCloudTableClient();
CloudTable cloudTable = tableClient.getTableReference("WADPerformanceCountersTable");
TableQuery<TableServiceEntity> query = TableQuery.from(TableServiceEntity.class);
for (TableServiceEntity entity : cloudTable.execute(query)) {
System.out.println(entity.getPartitionKey()+"\t"+entity.getRowKey());
}
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
}
}
}
Hope it helps.