Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# azure get vm get cpu usage

private void test()
{
    string vmName = "myVM";
    string resourceId = "/subscriptions/{subscriptionId}/resourceGroups/ResourceGroupWest/providers/Microsoft.Compute/virtualMachines/" + vmName;
    var subscriptionId = "mySubscriptionID";
    var clientId = "myClientID";
    var secret = "myKey";
    var tenantId = "myTenantID";
    resourceId = resourceId.Replace("{subscriptionId}", subscriptionId);

    MonitorClient readOnlyClient = AuthenticateWithReadOnlyClient(tenantId, clientId, secret, subscriptionId).Result;

    string queryString = "name.value eq 'CpuPercentage'";
    ODataQuery<MetadataValue> odataQuery = new ODataQuery<MetadataValue>(queryString);
    var vals = readOnlyClient.Metrics.List(resourceId, odataQuery );
    foreach (MetricValue v in vals.Value[0].Timeseries[0].Data)
    {
        if (v.Average != null)
        {
            totalAverage += v.Average.Value;
        }
    }
    totalAverage = totalAverage / vals.Value[0].Timeseries[0].Data.Count;
}

private static async Task<MonitorClient> AuthenticateWithReadOnlyClient(string tenantId, string clientId, string secret, string subscriptionId)
{
    // Build the service credentials and Monitor client            
    var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, secret);            
    var monitorClient = new MonitorClient(serviceCreds);           
    monitorClient.SubscriptionId = subscriptionId;            
    return monitorClient;        
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: get picked item xamarin 
Csharp :: The anti-forgery cookie token and form field token do not match. 
Csharp :: C# system dont let write txt file 
Csharp :: Auto select file in Solution Explorer from its open tab 
Csharp :: C# oledb excel select column with space 
Csharp :: C# Implicitly typed variable 
Csharp :: c# half hour dropdown list 
Csharp :: unity download image from online 
Csharp :: c# wpf datagrid extra column 
Csharp :: unity move in x seconds to pos 
Csharp :: c# enum variable set to nonthing 
Csharp :: C# Fibonacci list 
Csharp :: enum in method as argument c# 
Csharp :: binaural generator 
Csharp :: process run teamviewer address parametr c# 
Csharp :: use Multiple forms in one Csharp panel in one Windows Form panel 
Csharp :: how to use span c# 
Csharp :: how to split string into a list ignoring number of spaces c# 
Csharp :: using == is inefficient unity 
Csharp :: c# check if username and password is true 
Csharp :: Set property of control on form by name 
Csharp :: how to do minus with button c# 
Csharp :: Maximum Points You Can Obtain from Cards 
Csharp :: unity blender shadow messed up 
Csharp :: c# check file similarities 
Csharp :: csvhelper driver c# nuget 
Csharp :: visual studio debug copy byte[] from watch 
Csharp :: DisplayUnitType revit 2022 
Csharp :: poems 
Csharp :: how to add logo in a unity game apk 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =