有什么方法可以监控 Azure 文件容量

Is there some way to monitor Azure Files capacity

我正在设置一些 Azure 文件,并希望监视文件的容量。我需要在哪里设置当特定文件的容量接近配额时的警报?

现在我正在使用 Log activity 和 Azure Metric 来监控 azure 资源并设置一些警报。

我想监控不同的文件容量,并在文件容量接近配额时设置一些警报。

更新 0806:

我们可以使用 application insights 和 azure monitor 来做到这一点。

1.Create an application insights from azure portal. After it completes creation, copy the instrumentation key.

2.Invisual studio,创建一个.net framework控制台项目(我使用的是.net framework 4.5)

3.Install 用于 azure 存储和应用程序见解的 nuget 包:

Microsoft.ApplicationInsights, version 2.10.0

WindowsAzure.Storage, version 9.3.3

4.Then 将代码写在Program.cs:

       class Program
        {
            private static List<CloudFile> files = new List<CloudFile>();

            static void Main(string[] args)
            {
                string account_name = "xx";
                string account_key = "xx";

                //use while to keep running the code
                while (true)
                {
                    CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(account_name, account_key), true);
                    CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
                    CloudFileShare fileShare = fileClient.GetShareReference("t88");

                    IEnumerable<IListFileItem> fileList = fileShare.GetRootDirectoryReference().ListFilesAndDirectories();

                    //clear the list
                    files.Clear();

                    //add all the files in the fileshare to the list
                    foreach (IListFileItem listItem in fileList)
                    {
                        if (listItem.GetType() == typeof(CloudFile))
                        {
                            files.Add((CloudFile)listItem);
                        }
                        else if (listItem.GetType() == typeof(CloudFileDirectory))
                        {
                            list_subdir(listItem);
                        }
                    }

                    Console.WriteLine(files.Count);

                    //the variable to store the total files' length in the fileshare
                    long file_length = 0;

                    //specify the threshold value, if the total size is more than the value, then send data to application insights.
                    long threshold_value = 99999; //here, I use bytes as unit. You can change it MB / GB properly as per your need.

                    //calculate the size(bytes here) of the total files in the fileshare
                    foreach (var f in files)
                    {
                        file_length += f.Properties.Length;
                        Console.WriteLine($"file name: {f.Name}, file size: {f.Properties.Length}");
                    }

                    TelemetryClient telemetryClient = new TelemetryClient { InstrumentationKey = "xxxx" };
                    //telemetryClient.GetMetric("file_length").TrackValue(file_length);
                    //telemetryClient.TrackTrace("aaaaa");


                    //add if statement here, means if the value is greater than threshold value, send the value to app insights
                    if (file_length > threshold_value)
                    {
                        //the metric name here is "file_length", you can change it to other values, but be sure that use the correct metric name in the query in azure monitor in next step.
                        telemetryClient.TrackMetric("file_length", file_length);
                    }

                    //wait for xx seconds, then calculate the size again.
                    System.Threading.Thread.Sleep(1000*30);
                }

            }


        public static List<CloudFile> list_subdir(IListFileItem list)
        {
            CloudFileDirectory fileDirectory = (CloudFileDirectory)list;
            IEnumerable<IListFileItem> fileList = fileDirectory.ListFilesAndDirectories();

            foreach (IListFileItem listItem in fileList)
            {
                if (listItem.GetType() == typeof(CloudFileDirectory))
                {
                    list_subdir(listItem);
                }
                else
                {
                    if (listItem.GetType() == typeof(CloudFile))
                    {
                        files.Add((CloudFile)listItem);
                    }
                }
            }
            return files;
        }

}

5.Nav 至 azure 门户 -> azure 监视器 -> 警报 -> 新警报规则: 对于资源,select 您使用的应用程序见解。

for condition, select "Custom log search" -> 然后在Search query中,填入如下query(注意:name为metric名称您在步骤 4 中定义的):

customMetrics 
| where name == "file_length" 
| top 1 by timestamp desc
| project value

然后在警报逻辑中:基于=结果数,运算符=大于,阈值=0。

然后 "Evaluated based on", select 适当的周期和频率,为了测试目的,您可以 select 周期为 10 分钟,频率为 5 分钟。单击 "Done" 按钮完成条件。

对于操作,请正确配置它,例如填写您的电子邮件地址和其他字段。

6.Run来自visual studio的控制台项目,如果文件共享中的总文件大小大于您指定的值,您将收到一个或多个(取决于期间和在步骤 5) 中设置的频率提醒电子邮件。


暂不支持该功能,敬请关注user feedback