Azure存储容器级别的指标

huangapple go评论81阅读模式
英文:

azure storage metrics at container level

问题

我参考了 Azure 在以下文档中提供的信息:

https://learn.microsoft.com/en-us/azure/storage/common/storage-metrics-in-azure-monitor#read-metric-values-with-the-net-sdk

我已经进行了更改,并使用 azure-mgmt-monitor 依赖项使代码在 Java 中运行。以下是代码示例:

public void listStorageMetricDefinition() {
    String resourceId = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}";
    String subscriptionId = "*****************************";
    String tenantId = "*****************************";
    String applicationId = "*****************************";
    String accessKey = "*****************************";

    ApplicationTokenCredentials credentials = (ApplicationTokenCredentials) new ApplicationTokenCredentials(
            applicationId, tenantId, accessKey, AzureEnvironment.AZURE).withDefaultSubscriptionId(subscriptionId);
    MonitorManagementClientImpl clientImpl = new MonitorManagementClientImpl(credentials);

    Date startTime = DateTime.now().minusMinutes(30).toDate();
    Date endTime = DateTime.now().toDate();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    String startInterval = dateFormat.format(startTime);
    String endInterval = dateFormat.format(endTime);
    String timespan = startInterval + "/" + endInterval;
    Period interval = Period.minutes(1);
    String metricNames = "Egress";
    String aggregation = "Total";
    Integer top = null;
    String orderby = null;
    String filter = null;
    String metricNamespace = null;

    ResponseInner response = clientImpl.metrics().list(resourceId, timespan, interval, metricNames, aggregation,
            top, orderby, filter, null, metricNamespace);
    List<MetricInner> value = response.value();
    for (MetricInner metric : value) {
        System.out.println("id " + metric.id());
        System.out.println("name " + metric.name().value());
        System.out.println("type " + metric.type());
        System.out.println("unit " + metric.unit());
        List<TimeSeriesElement> timeseries = metric.timeseries();
        timeseries.forEach(ts -> {
            ts.data().forEach(dt -> {
                System.out.println(dt.timeStamp() + "--" + dt.total());
            });
        });
    }
}

通过上述代码,我能够读取存储帐户级别的指标值,但是如何在容器级别找到指标呢?例如,如果我的存储帐户中有 3 个容器,我需要为每个容器查找指标,而不是为整个存储帐户查找。

请建议如何以其他方式在容器级别查找指标。

英文:

I am referring to documentation provided by azure at

https://learn.microsoft.com/en-us/azure/storage/common/storage-metrics-in-azure-monitor#read-metric-values-with-the-net-sdk

I have made changes and make the code work for java using azure-mgmt-monitor dependency. Here is the code

public void listStorageMetricDefinition() {
String resourceId = &quot;/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}&quot;;
String subscriptionId = &quot;*****************************&quot;;
String tenantId = &quot;*****************************&quot;;
String applicationId = &quot;*****************************&quot;;
String accessKey = &quot;*****************************&quot;;
ApplicationTokenCredentials credentials = (ApplicationTokenCredentials) new ApplicationTokenCredentials(
applicationId, tenantId, accessKey, AzureEnvironment.AZURE).withDefaultSubscriptionId(subscriptionId);
MonitorManagementClientImpl clientImpl = new MonitorManagementClientImpl(credentials);
Date startTime = DateTime.now().minusMinutes(30).toDate();
Date endTime = DateTime.now().toDate();
//DateTime must be in below format
SimpleDateFormat dateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd&#39;T&#39;HH:mm:ss&quot;);
dateFormat.setTimeZone(TimeZone.getTimeZone(&quot;UTC&quot;));
String startInterval = dateFormat.format(startTime);
String endInterval = dateFormat.format(endTime);
String timespan = startInterval + &quot;/&quot; + endInterval;
Period interval = Period.minutes(1);
String metricNames = &quot;Egress&quot;;
String aggregation = &quot;Total&quot;;
Integer top = null;
String orderby = null;
String filter = null;
String metricNamespace = null;
ResponseInner response = clientImpl.metrics().list(resourceId, timespan, interval, metricNames, aggregation,
top, orderby, filter, null, metricNamespace);
List&lt;MetricInner&gt; value = response.value();
for (MetricInner metric : value) {
System.out.println(&quot;id &quot; + metric.id());
System.out.println(&quot;name &quot; + metric.name().value());
System.out.println(&quot;type &quot; + metric.type());
System.out.println(&quot;unit &quot; + metric.unit());
List&lt;TimeSeriesElement&gt; timeseries = metric.timeseries();
timeseries.forEach(ts -&gt; {
ts.data().forEach(dt -&gt; {
System.out.println(dt.timeStamp() + &quot;--&quot; + dt.total());
});
});
}
}

By using above I am able to read the metrics values at storage account level, but how can I find the metrics at container level? e.g. if I have 3 containers inside my storage account, I need to find the metrics for each container instead for complete storage account.

Please suggest if there are other ways to find metrics at container level.

答案1

得分: 0

这没有直接的方法来完成此操作,但可以通过配置存储帐户的监视来实现。请按照下面的链接来配置监视,

https://learn.microsoft.com/en-us/azure/storage/common/storage-monitor-storage-account

一旦为存储帐户配置了监视,它将在您的存储帐户中创建一个名为 $logs 的新容器。这个新容器在 Azure 门户中不可见,但您可以使用 Azure 存储资源管理器工具查看和浏览这个新容器。以下是下载该工具的链接。

https://azure.microsoft.com/en-us/features/storage-explorer/

$logs 容器内部的日志根据日期和时间分隔在单独的文件夹中。

/blob/yyyy/MM/dd/HHmm/000000.log

/blob/yyyy/MM/dd/HHmm/000001.log

其中 mm 的值始终为 00。

日志的模式可以在 Azure 文档的以下位置找到。

https://learn.microsoft.com/en-us/rest/api/storageservices/storage-analytics-log-format

可以使用模式格式读取日志文件,并从中创建有用的指标。

英文:

There is not direct way of doing this, but one can achieve this by configuring monitoring for the storage account. Follow the below link to configure monitoring,

https://learn.microsoft.com/en-us/azure/storage/common/storage-monitor-storage-account

Once storage account is configured for monitoring, it will create a new container with name $logs in your storage account. This new container is not visible in azure portal but you can view and explore this new container using Azure Storage Explorer tool. The link to download the tool is given below.

https://azure.microsoft.com/en-us/features/storage-explorer/

The logs inside the $logs container are segregated on the basis of date and time in separate folders.

/blob/yyyy/MM/dd/HHmm/000000.log

/blob/yyyy/MM/dd/HHmm/000001.log

where mm is always going to be 00.

Azure存储容器级别的指标

The schema for logs can be found in azure documentation at location.

https://learn.microsoft.com/en-us/rest/api/storageservices/storage-analytics-log-format

One can read the log file using the schema format and create useful metrics out if it.

huangapple
  • 本文由 发表于 2020年4月3日 20:52:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/61012347.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定