0

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.hasNe‌​xt(LazySegmentedIter‌​ator.java:113) at TestStorage.main(TestStorage.java:225) Caused by: com.microsoft.azure.storage.table.TableServiceException: Bad Request

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Prit
  • 73
  • 1
  • 10

1 Answers1

1

@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.

  1. 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>.

  2. Use the GUI tool Micorsoft Azure Storage Explorer to find & view the table WADPerformanceCounter.

enter image description here

  1. 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.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Thanks @Peter Pan -MSFT. There was typo in table name. I was querying to $WADPerformanceCountersTable. It should be WADPerformanceCountersTable. – Prit Aug 31 '16 at 12:30
  • Can we get DiagnosticConnection string or Storage Account name of cloud service using some API? – Prit Aug 31 '16 at 12:56
  • @Prit, The DiagnosticConnection string is configured in the serviceconfiguration.cscfg file, like this ``. There seems not to be any public API for extracting the connection string from the serviceconfiguration.cscfg file. – Peter Pan Sep 01 '16 at 06:30