GET https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/myRG/providers/Microsoft.Insights/autoscalesettings/vmss1-Autoscale-775/predictiveMetrics?timespan=2021-10-14T22:00:00.000Z/2021-10-16T22:00:00.000Z&interval=PT1H&metricNamespace=Microsoft.Compute/virtualMachineScaleSets&metricName=PercentageCPU&aggregation=Total&api-version=2022-10-01
import java.time.Duration;
/**
* Samples for PredictiveMetric Get.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/monitor/resource-manager/Microsoft.Insights/stable/2022-10-01/examples/GetPredictiveMetric.json
*/
/**
* Sample code: Get Metric for data.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void getMetricForData(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getPredictiveMetrics().getWithResponse("myRG",
"vmss1-Autoscale-775", "2021-10-14T22:00:00.000Z/2021-10-16T22:00:00.000Z", Duration.parse("PT1H"),
"Microsoft.Compute/virtualMachineScaleSets", "PercentageCPU", "Total", com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
import isodate
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python get_predictive_metric.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.predictive_metric.get(
resource_group_name="myRG",
autoscale_setting_name="vmss1-Autoscale-775",
timespan="2021-10-14T22:00:00.000Z/2021-10-16T22:00:00.000Z",
interval=isodate.parse_duration("PT1H"),
metric_namespace="Microsoft.Compute/virtualMachineScaleSets",
metric_name="PercentageCPU",
aggregation="Total",
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2022-10-01/examples/GetPredictiveMetric.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2022-10-01/examples/GetPredictiveMetric.json
func ExamplePredictiveMetricClient_Get() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewPredictiveMetricClient().Get(ctx, "myRG", "vmss1-Autoscale-775", "2021-10-14T22:00:00.000Z/2021-10-16T22:00:00.000Z", "PT1H", "Microsoft.Compute/virtualMachineScaleSets", "PercentageCPU", "Total", nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.PredictiveResponse = armmonitor.PredictiveResponse{
// Data: []*armmonitor.PredictiveValue{
// {
// TimeStamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-10-14T22:00:00.000Z"); return t}()),
// Value: to.Ptr[float64](123),
// },
// {
// TimeStamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-10-14T22:02:00.000Z"); return t}()),
// Value: to.Ptr[float64](120),
// },
// {
// TimeStamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-10-14T22:02:00.000Z"); return t}()),
// Value: to.Ptr[float64](88),
// },
// {
// TimeStamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-10-14T22:03:00.000Z"); return t}()),
// Value: to.Ptr[float64](100),
// }},
// Interval: to.Ptr("PT1H"),
// MetricName: to.Ptr("PercentageCPU"),
// TargetResourceID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myRG/providers/Microsoft.Compute/virtualMachineScaleSets/vmss1"),
// Timespan: to.Ptr("2021-10-14T22:00:00.000Z/2021-10-16T22:00:00.000Z"),
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to get predictive autoscale metric future data
*
* @summary get predictive autoscale metric future data
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2022-10-01/examples/GetPredictiveMetric.json
*/
async function getMetricForData() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "myRG";
const autoscaleSettingName = "vmss1-Autoscale-775";
const timespan = "2021-10-14T22:00:00.000Z/2021-10-16T22:00:00.000Z";
const interval = "PT1H";
const metricNamespace = "Microsoft.Compute/virtualMachineScaleSets";
const metricName = "PercentageCPU";
const aggregation = "Total";
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.predictiveMetric.get(
resourceGroupName,
autoscaleSettingName,
timespan,
interval,
metricNamespace,
metricName,
aggregation,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2022-10-01/examples/GetPredictiveMetric.json
// this example is just showing the usage of "PredictiveMetric_Get" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this AutoscaleSettingResource created on azure
// for more information of creating AutoscaleSettingResource, please refer to the document of AutoscaleSettingResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "myRG";
string autoscaleSettingName = "vmss1-Autoscale-775";
ResourceIdentifier autoscaleSettingResourceId = AutoscaleSettingResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, autoscaleSettingName);
AutoscaleSettingResource autoscaleSetting = client.GetAutoscaleSettingResource(autoscaleSettingResourceId);
// invoke the operation
string timespan = "2021-10-14T22:00:00.000Z/2021-10-16T22:00:00.000Z";
TimeSpan interval = XmlConvert.ToTimeSpan("PT1H");
string metricNamespace = "Microsoft.Compute/virtualMachineScaleSets";
string metricName = "PercentageCPU";
string aggregation = "Total";
AutoscaleSettingPredicativeResult result = await autoscaleSetting.GetPredictiveMetricAsync(timespan, interval, metricNamespace, metricName, aggregation);
Console.WriteLine($"Succeeded: {result}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue