【Azure 存储服务】调用REST API获取Stroage Account Table中所有的Entity计数 -- Count
作者:互联网
问题描述
在Storage Account的使用中,如果想获取Table中全部Entity的计数以及大小,如果是REST API方式,如何来获取呢?
问题解答
在Azure中,所有服务的Metrics部分,都可以通过Azure Monitor 的REST API来获取。当需要查看Stroage Account的Metrcis时候,可以参考使用 List Metrics 接口:
文档链接:https://docs.microsoft.com/en-us/rest/api/monitor/metrics/list?tabs=HTTP
当然,如果是在中国区使用,需要修改文中的Endpoint为: https://management.chinacloudapi.cn
所以,获取Storage Account中全部Table中Entity的总数API 为:
## 单独获取 TableEntityCount https://management.chinacloudapi.cn/subscriptions/<subscriptions>/resourceGroups/<resourceGroups>/providers/Microsoft.Storage/storageAccounts/<storageAccounts>
/tableServices/default/providers/microsoft.Insights/metrics?timespan=2022-09-03T08:30:00.000Z/2022-09-04T08:45:00.000Z&interval=PT15M
&metricnames=TableEntityCount&aggregation=average&metricNamespace=microsoft.storage%2Fstorageaccounts%2Ftableservices&autoadjusttimegrain=true
&validatedimensions=false&api-version=2021-05-01 ## 单独获取 TableCapacity https://management.chinacloudapi.cn/subscriptions/<subscriptions>/resourceGroups/<resourceGroups>/providers/Microsoft.Storage/storageAccounts/<storageAccounts>
/tableServices/default/providers/microsoft.Insights/metrics?timespan=2022-09-03T08:30:00.000Z/2022-09-04T08:45:00.000Z&interval=PT15M
&metricnames=TableCapacity&aggregation=average&metricNamespace=microsoft.storage%2Fstorageaccounts%2Ftableservices&autoadjusttimegrain=true
&validatedimensions=false&api-version=2021-05-01 ## 合并获取 TableCapacity 和 TableEntityCount https://management.chinacloudapi.cn/subscriptions/<subscriptions>/resourceGroups/<resourceGroups>/providers/Microsoft.Storage/storageAccounts/<storageAccounts>
/tableServices/default/providers/microsoft.Insights/metrics?timespan=2022-09-03T08:30:00.000Z/2022-09-04T08:45:00.000Z&interval=PT15M
&metricnames=TableCapacity,TableEntityCount&aggregation=average&metricNamespace=microsoft.storage%2Fstorageaccounts%2Ftableservices&autoadjusttimegrain=true
&validatedimensions=false&api-version=2021-05-01 ## 注意修改timespan
在调用以上接口时,必须获取 Authorization Bearer Token,否则会得到如下错误信息:
{ "error": { "code": "AuthenticationFailed", "message": "Authentication failed. The 'Authorization' header is missing." } }
获取Authorzation的方法请见:https://docs.microsoft.com/en-us/rest/api/monitor/metrics/list?tabs=HTTP#security 具体的步骤,可以参考旧博文:https://www.cnblogs.com/lulight/p/14279338.html
在Postman中验证结果如下:
参考资料
Microsoft.Storage/storageAccounts/tableServices:https://docs.microsoft.com/en-us/azure-stack/user/azure-stack-metrics-supported?view=azs-2206
Metrics - List : https://docs.microsoft.com/en-us/rest/api/monitor/metrics/list?tabs=HTTP#uri-parameters
标签:Count,Account,--,00.000,09,Storage,metrics,https,microsoft 来源: https://www.cnblogs.com/lulight/p/16655270.html