我指的是azure提供的文档
我已经进行了更改,并使用 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();
//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());
});
});
}
}
通过使用上面的内容,我可以读取存储帐户级别的指标值,但如何找到容器级别的指标?例如如果我的存储帐户中有 3 个容器,我需要查找每个容器的指标,而不是完整存储帐户的指标。
请建议是否有其他方法可以在容器级别查找指标。
最佳答案
没有直接的方法可以做到这一点,但可以通过配置存储帐户的监视来实现这一点。请点击以下链接配置监控,
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
可以使用架构格式读取日志文件,并创建有用的指标。
关于java - 容器级别的 Azure 存储指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61012347/