本文介绍了WebJobs SDK在AzureWebJobsDashboard连接中创建的Blob的清理机制是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure WebJob SDK将在AzureWebJobsStorageAzureWebJobsDashboard应用程序设置中定义的存储连接字符串用于其日志记录和仪表板.

Azure WebJob SDK uses the storage connection string defined in the AzureWebJobsStorage and AzureWebJobsDashboard app settings for its logging and dashboard.

WebJob SDK在AzureWebJobsStorage中创建以下blob容器:

WebJob SDK creates the following blob container in AzureWebJobsStorage:

  • azure-webjobs-hosts

WebJob SDK在AzureWebJobsDashboard

WebJob SDK creates the following blob containers in AzureWebJobsDashboard

  • azure-jobs-host-output
  • azure-webjobs-hosts
  • azure-jobs-host-output
  • azure-webjobs-hosts

在运行WebJob时,在上面的Blob容器中创建了许多Blob.如果没有清理机制,则容器可能会膨胀或饱和.

Many blobs are created in the above blob containers as the WebJob runs. The containers can be bloated or saturated if there is no clean-up mechanism.

上述blob容器的清理机制是什么?

What is the cleanup mechanism for the above blob containers?

更新

以下答案是一种解决方法.在这一点上,没有内置的机制来清理WebJobs日志.随着作业的长期运行,日志可能堆积得非常大.开发人员必须自行创建清理机制. Azure Functions是实施此类清理过程的好方法.下面的答案中提供了一个示例.

The answer below is a workaround. At this point, there is no built-in mechanism to clean up the WebJobs logs. The logs can pile up quite large as the Job runs in a long term. Developers must create the cleanup mechanism on their own. Azure Functions is a good way of implementing such cleanup process. An example is provided in the below answer.

推荐答案

我还没有找到一种方法. GitHub上有一个与此主题相关的未解决问题,但尚未结束.

I haven’t found a way to do it. There is an open issue on GitHub which related to this topic, but haven’t been closed.

无法设置网络日志记录保留策略

在GitHub上的类似问题中,我们发现Azure WebJob SDK已更改了将日志保存到Azure表存储的多个表的方式.我们可以轻松地每月删除表格.到目前为止,对于在Azure Blob存储中写入的日志,还没有按月分组.

In a similar issue on GitHub we found that Azure WebJob SDK have changed a way of saving logs to multi tables of Azure Table Storage. We can easily delete the table per month. For logs writen in Azure Blob Storage haven’t been grouped by month until now.

WebJobs.日志记录需要支持日志清除/保留策略

要删除较旧的WebJob日志,建议您创建一个时间触发的WebJob来删除所需的日志.

To delete the older WebJob log, I suggest you create a time triggered WebJob to delete the logs which you wanted.

以下代码供您参考.

// Parse the connection string and return a reference to the storage account.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

// Create the table client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve a reference to a container.
var container = blobClient.GetContainerReference("azure-webjobs-hosts");
// Query out all the blobs which created after 30 days
var blobs = container.GetDirectoryReference("output-logs").ListBlobs().OfType<CloudBlob>()
    .Where(b => b.Properties.LastModified < new DateTimeOffset(DateTime.Now.AddDays(-30)));
// Delete these blobs
foreach (var item in blobs)
{
    item.DeleteIfExists();
}

这篇关于WebJobs SDK在AzureWebJobsDashboard连接中创建的Blob的清理机制是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:28