Data retrival through C# application

Goud Kanthi, Aniketh 1 Reputation point
2021-08-31T06:30:05.953+00:00

Hi,

I'm new to Azure, could anyone help me while I'm trying to build C# application to retrieve the VM Metrics data
Metrics are:

  1. CPU utlization
  2. RAM Usage
  3. Logical disk space used.

Can anyone help me with this.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,032 questions
{count} votes

1 answer

Sort by: Most helpful
  1. shiva patpi 13,366 Reputation points Microsoft Employee Moderator
    2021-09-02T01:38:55.303+00:00

    Hello @Goud Kanthi, Aniketh ,
    Thanks for your query !
    To retrieve those metrics first you might want to enable the diagnostics for that VM.

    Go to VM -> Monitoring -> Diagnostics Settings: (Follow the remaining steps)

    You can select the required metrics like below:
    Performance counters
    Collecting data for these counters:
    CPU
    Memory
    Disk
    Network

    Once you enable those , it will deploy an extension
    Microsoft.Azure.Performance.Diagnostics.AzurePerformanceDiagnostics

    As a part of enabling that extension , you will have to choose the storage account where all the required metrics will be stored.
    In that particular storage account , it will create corresponding tables with name WADMetricsPT* .

    Table data and columns looks like below:

    128503-image.png

    You will have to write a C#.net program using Azure API's to query that storage account tables data.

    Sample high level piece of code to connect to azure storage table and retrieve the data:

    <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;
    AccountName=[Name of storage account];AccountKey=[Access Key for storage account]">

    CloudStorageAccount cloudStorageAccount =
    CloudStorageAccount.Parse
    (ConfigurationManager.AppSettings["StorageConnectionString"]);
    CloudTableClient tableClient = cloudStorageAccount.CreateCloudTableClient();
    string tableName = "tablename"
    CloudTable cloudTable = tableClient.GetTableReference(tableName);
    TableOperation tableOperation = TableOperation.Retrieve(partitionKey, rowKey);
    TableResult tableResult = table.Execute(tableOperation);

    Please Note: You will have to query the corresponding Metrics which is available in CounterName Column

    Kindly let us know if you need additional help on this.

    Regards,
    Shiva.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.