Azure Microsoft Insights API 2016-09-01收集指标时出错

时间:2017-10-26 09:11:17

标签: rest azure azure-application-insights azure-resource-manager

请帮助我理解为什么从最近几天Azure Microsoft Insights API 2016-09-01发出以下错误{ "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 " } 几天前它工作正常老工作网址---&gt; 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+

新的无效网址---&gt; 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+

请帮我解决这个问题,这会导致我的生产环境出现大问题。

2 个答案:

答案 0 :(得分:0)

如果指标名称没有&#34;()&#34; ,我可以重新发出此问题。

enter image description here

我假设你提到不工作的URL不对应你的错误信息。正如您所提到的,2只URL资源组和虚拟机名称不相同,排除开始时间和结束时间。请尝试使用以下URL再次测试它。它在我身边正常工作。

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

如果可以使用C#SDK,我们可以使用Microsoft.Azure.Management.Monitor.Fluent,以下是我的演示代码,它可以正常使用。

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

答案 1 :(得分:0)

问题早于+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+得到支持(即java中我使用的是SimpleDateFormat(“yyyy-MM-dd'T'HH:mm:ss.SSSZ”))但我现在已经删除了% 2B0000所以只有这将工作+and+timeGrain+eq+duration%27PT5M%27+and+startTime+eq+2017-05-26T10%3A52%3A28.475+and+endTime+eq+2017-05-26T10%3A57%3A28.476(所以现在我已经改为SimpleDateFormat(“yyyy-MM-dd'T'HH:mm:ss.SSS”))