简体   繁体   中英

azure storage metrics at container level

I am referring to documentation provided by azure at

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. 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.

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

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.

在此处输入图像描述

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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