Horje
c# azure get vm get cpu usage Code Example
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;        
}




Csharp

Related
c# e-mail send Code Example c# e-mail send Code Example
Hovercraft Physics in Unity Code Example Hovercraft Physics in Unity Code Example
tab key navigation C# winforms Code Example tab key navigation C# winforms Code Example
.net core string compare ignore case and accents Code Example .net core string compare ignore case and accents Code Example
unity get object position on screen Code Example unity get object position on screen Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11