简体   繁体   English

容器级别的 azure 存储指标

[英]azure storage metrics at container level

I am referring to documentation provided by azure at我指的是 azure 提供的文档

https://docs.microsoft.com/en-us/azure/storage/common/storage-metrics-in-azure-monitor#read-metric-values-with-the-net-sdk https://docs.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.我已经进行了更改,并使用 azure-mgmt-monitor 依赖项使代码适用于 java。 Here is the code这是代码

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();
    //DateTime must be in below format
    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());
            });
        });
    }
}

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?通过使用上述方法,我可以读取存储帐户级别的指标值,但是如何找到容器级别的指标? eg if I have 3 containers inside my storage account, I need to find the metrics for each container instead for complete storage account.例如,如果我的存储帐户中有 3 个容器,我需要找到每个容器的指标而不是完整的存储帐户。

Please suggest if there are other ways to find metrics at container level.请建议是否有其他方法可以在容器级别查找指标。

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://docs.microsoft.com/en-us/azure/storage/common/storage-monitor-storage-account https://docs.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.配置存储帐户进行监控后,它将在您的存储帐户中创建一个名为 $logs 的新容器。 This new container is not visible in azure portal but you can view and explore this new container using Azure Storage Explorer tool.这个新容器在 azure 门户中不可见,但您可以使用 Azure 存储资源管理器工具查看和探索这个新容器。 The link to download the tool is given below.下载该工具的链接如下。

https://azure.microsoft.com/en-us/features/storage-explorer/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. $logs 容器中的日志根据日期和时间在单独的文件夹中隔离。

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

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

where mm is always going to be 00.其中 mm 始终为 00。

在此处输入图像描述

The schema for logs can be found in azure documentation at location.日志架构可以在 azure 文档中找到。

https://docs.microsoft.com/en-us/rest/api/storageservices/storage-analytics-log-format https://docs.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.可以使用模式格式读取日志文件并创建有用的指标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM