问题描述
通过 az rest --method get 如何获得Event Hub Entity 级的统计指标?
问题解答
查阅文档 https://learn.microsoft.com/en-us/rest/api/monitor/metrics/list?tabs=HTTP , 可以通过 filter 参数指定 EntityName eq '*' 或者 EntityName eq '<entity-name>'。
Windows系统的CMD中,使用AZ CLI测试:
# EntityName eq '*' az rest --debug --method get --url "/subscriptions/<your subscription id>/resourceGroups/<your resource group> /providers/Microsoft.EventHub/namespaces/<event-hub-name>/providers/microsoft.Insights/metrics? timespan=2022-08-31T07:03:32.960Z/2022-08-31T07:57:34.794Z &interval=PT5M&metricnames=IncomingRequests&aggregation=total &metricNamespace=microsoft.eventhub%2Fnamespaces&top=10 &orderby=total desc& $filter=EntityName eq '*' &api-version=2019-07-01" # EntityName eq 'entity-name' az rest --method get --url "/subscriptions/<your subscription id>/resourceGroups/<your resource group> /providers/Microsoft.EventHub/namespaces/<event-hub-name>/providers/microsoft.Insights/metrics? timespan=2022-08-31T07:03:32.960Z/2022-08-31T07:57:34.794Z &interval=PT5M&metricnames=IncomingRequests&aggregation=total &metricNamespace=microsoft.eventhub%2Fnamespaces&top=10 &orderby=total desc &$filter=EntityName eq 'kafka-test' &api-version=2019-07-01"
Linux系统中,需要对url参数中的$filter进行转义,变为 $filter 。
az rest --debug --method get --url "/subscriptions/<your subscription id>/resourceGroups/<your resource group> /providers/Microsoft.EventHub/namespaces/<event-hub-name>/providers/microsoft.Insights/metrics? timespan=2022-08-31T07:03:32.960Z/2022-08-31T07:57:34.794Z &interval=PT1M &metricnames=SuccessfulRequests &aggregation=total &metricNamespace=microsoft.eventhub%2Fnamespaces &top=10 &orderby=total asc &\$filter=EntityName eq 'kafka-test' &api-version=2019-07-01"
参考资料
Metrics - List:https://learn.microsoft.com/en-us/rest/api/monitor/metrics/list?tabs=HTTP