【发布时间】:2020-07-15 15:36:18
【问题描述】:
我指的是 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 个容器,我需要找到每个容器的指标而不是完整的存储帐户。
请建议是否有其他方法可以在容器级别查找指标。
【问题讨论】:
-
据我所知,我们无法获得 Azure 存储容器的指标。我们只能获取 Azure 存储帐户级别或 Azure 存储容器级别的指标。更多详情请参考docs.microsoft.com/en-us/azure/storage/common/…
-
我找到了一个解决方案,我们可以为存储帐户启用存储分析,该存储帐户将创建一个名为 $logs 的容器,然后使用这些日志来构建您的指标,因为日志包含每一个细节.
标签: java azure azure-blob-storage azure-sdk azure-storage-account