rest - Azure Microsoft Insights API 2016-09-01收集度量標準時出錯




azure rest api (2)

當指標名稱沒有“()”時,我可以重新編制問題。

我假設你提到沒有工作的網址並不對應你的錯誤信息。 正如你剛才提到的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

如果使用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;

請幫助我理解為什麼從過去幾天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 " }幾天后工作正常舊工作網址---> 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+ 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+

新的不工作的網址---> 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+

請幫我解決這個問題,在我的生產環境中造成巨大的問題。


問題出現在+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”))但我dono時下他們已經刪除%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 (so現在我已經改為SimpleDateFormat(“yyyy-MM-dd'T'HH:mm:ss.SSS”))







azure-resource-manager