检查订阅中azure存储帐户中使用的空间

问题描述 投票:9回答:3

如何在我的订阅资源组中检查我在每个azure存储帐户中使用的空间大小。

我无法通过PowerShell,CLI,门户网站找到检查azure存储帐户中使用的空间的方法......

azure local-storage azure-storage azure-storage-blobs
3个回答
11
投票

Azure存储大小包括所有4种服务(Blob,队列,文件,表)。根据我的知识,目前还没有办法计算所有服务的总大小。

但是,您可以使用Azure指标获取Portal上使用的blob空间。请选择监控 - >指标

enter image description here

有关在Azure门户中监控存储帐户的更多信息,请参阅此link

此外,您可以使用PowerShell来获取blob。你可以使用一个很好的script


2
投票

Azure Storage Explorer有一个“目录统计”按钮。

导航到一个文件夹

enter image description here

单击按钮

enter image description here

总计显示在活动面板中

enter image description here


0
投票

这是一个.net core脚本,用于列出使用过去一小时的平均指标值的存储帐户使用情况。

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Microsoft.Azure.Management.CosmosDB.Fluent.Models;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.Monitor;
using Microsoft.Azure.Management.Monitor.Models;
using Microsoft.Rest.Azure.Authentication;

namespace storagelist
{
    class Program
    {
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            // to generate my.azureauth file run the follow command:
            // az ad sp create-for-rbac --sdk-auth > my.azureauth
            var azure = Azure.Authenticate("my.azureauth").WithDefaultSubscription();

            var accounts = azure.StorageAccounts.List();
            // can get values from my.azureauth
            var tenantId = "";
            var clientId = "";
            var clientSecret = "";
            var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret);
            MonitorManagementClient readOnlyClient = new MonitorManagementClient(serviceCreds);

            var oneHour = System.TimeSpan.FromHours(1);
            var startDate = DateTime.Now.AddHours(-oneHour.Hours).ToUniversalTime().ToString("o");
            string endDate = DateTime.Now.ToUniversalTime().ToString("o");
            string timeSpan = startDate + "/" + endDate;

            List<string> fileContents = new List<string>();

            foreach (var storage in accounts)
            {
                var response = await readOnlyClient.Metrics.ListAsync(
                resourceUri: storage.Id,
                timespan: timeSpan,
                interval: oneHour,
                metricnames: "UsedCapacity",

                aggregation: "Average",
                resultType: ResultType.Data,
                cancellationToken: CancellationToken.None);

                foreach (var metric in response.Value)
                {
                    foreach (var series in metric.Timeseries)
                    {
                        foreach (var point in series.Data)
                        {
                            if (point.Average.HasValue)
                            {
                                fileContents.Add($"{storage.Id}, {point.Average.Value}");
                                break;
                            }
                        }
                        break;
                    }
                    break;
                }
            }

            await File.WriteAllLinesAsync("./storage.csv", fileContents);
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.