Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
645 views
in Technique[技术] by (71.8m points)

rest - Azure Microsoft Insights API 2016-09-01 Error while collecting Metrics

Please help me to understand why from last few days Azure Microsoft Insights API 2016-09-01 is giving the following error{ "code": "BadRequest", "message": "only conditions of the form '<name> eq <value>' are allowed, where <name> = 'timeGrain', 'startTime', 'endTime', 'name.value', 'aggregationType', 'debugRegion' : ( name.value eq 'Disk Write Bytes' ) and timeGrain eq duration'PT5M' and startTime eq 2017-10-25T13:27:49.620 0000 and endTime eq 2017-10-25T13:32:49.620 0000 " } few days back it was working fine Old working URL---> https://management.azure.com/subscriptions/452529bb-083b-411a-a5c2-30c735222/resourceGroups/Preprod2-Resource-Group/providers/Microsoft.Compute/virtualMachines/mw-mcs-test3/providers/microsoft.insights/metrics?api-version=2016-09-01&$filter=%28+name.value+eq+%27Disk+Write+Operations%2FSec%27+or++name.value+eq+%27Percentage+CPU%27+or++name.value+eq+%27Network+In%27+or++name.value+eq+%27Network+Out%27+or++name.value+eq+%27Disk+Read+Operations%2FSec%27+or++name.value+eq+%27Disk+Read+Bytes%27+or++name.value+eq+%27Disk+Write+Bytes%27++%29+and+timeGrain+eq+duration%27PT5M%27+and+startTime+eq+2017-05-26T10%3A52%3A28.475%2B0000+and+endTime+eq+2017-05-26T10%3A57%3A28.476%2B0000+

New not working URL--->https://management.azure.com/subscriptions/452529bb-083b-411a-a5c2-30c735222/resourceGroups/MWatchLab-dev-kafka-bridge-oldcore-357248/providers/Microsoft.Compute/virtualMachines/dev-kafka-bridge-oldcore/providers/microsoft.insights/metrics?api-version=2016-09-01&$filter=%28+name.value+eq+%27Disk+Write+Operations%2FSec%27+or++name.value+eq+%27Percentage+CPU%27+or++name.value+eq+%27Network+In%27+or++name.value+eq+%27Network+Out%27+or++name.value+eq+%27Disk+Read+Operations%2FSec%27+or++name.value+eq+%27Disk+Read+Bytes%27+or++name.value+eq+%27Disk+Write+Bytes%27++%29+and+timeGrain+eq+duration%27PT5M%27+and+startTime+eq+2017-10-26T05%3A28%3A34.919%2B0000+and+endTime+eq+2017-10-26T05%3A33%3A34.919%2B0000+

Please help me fix this its is causing huge issues in my production environment.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I can repro the issue when there is no "()" for the metrics names.

enter image description here

I assume that you mentioned not working URL is not corresponding your error info. As you mentioned 2 URL just resource group and virtual machine name are not the same exclude start time and end time. Please have a try to use the following URL to test it again. it works correctly on my side.

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourcegroup}/providers/Microsoft.Compute/virtualMachines/{machineName}/providers/microsoft.insights/metrics?$filter=(%20name.value%20eq%20'Disk%20Write%20Operations/Sec'%20or%20%20name.value%20eq%20'Percentage%20CPU'%20or%20%20name.value%20eq%20'Network%20In'%20or%20%20name.value%20eq%20'Network%20Out'%20or%20%20name.value%20eq%20'Disk%20Read%20Operations/Sec'%20or%20%20name.value%20eq%20'Disk%20Read%20Bytes'%20or%20%20name.value%20eq%20'Disk%20Write%20Bytes'%20%20)%20and%20timeGrain%20eq%20duration'PT5M'%20and%20startTime%20eq%202017-10-26T05:28:34.919Z%20and%20endTime%20eq%202017-10-26T05:33:34.919&api-version=2016-09-01

enter image description here

If use C# SDK is acceptable, we could use Microsoft.Azure.Management.Monitor.Fluent to that, following is my demo code, it works correctly on my side.

var azureTenantId = "tenant id";
var azureSecretKey = "secret key";
var azureAppId = "client id";
var subscriptionId = "subscription id";
var resourceGroup = "resource group";
var machineName = "machine name";
var serviceCreds = ApplicationTokenProvider.LoginSilentAsync(azureTenantId, azureAppId, azureSecretKey).Result;
MonitorClient monitorClient = new MonitorClient(serviceCreds) { SubscriptionId = subscriptionId };
 var resourceUrl = $"subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{machineName}";
 var metricNames = "(name.value eq 'Disk Write Operations/Sec' or  name.value eq 'Percentage CPU' or  name.value eq 'Network In' or  name.value eq 'Network Out' or  name.value eq 'Disk Read Operations/Sec' or  name.value eq 'Disk Read Bytes' or  name.value eq 'Disk Write Bytes')"; 
 string timeGrain = " and timeGrain eq duration'PT5M'";
 string startDate = " and startTime eq 2017-10-26T05:28:34.919Z";
 string endDate = " and endTime eq 2017-10-26T05:33:34.919Z";
 var odataFilterMetrics = new ODataQuery<MetricInner>(
                $"{metricNames}{timeGrain}{startDate}{endDate}");

 var metrics = monitorClient.Metrics.ListWithHttpMessagesAsync(resourceUrl, odataFilterMetrics).Result;

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...