Skip to content

Commit c70ff8b

Browse files
committed
update samples
1 parent 40eca8e commit c70ff8b

2 files changed

Lines changed: 165 additions & 160 deletions

File tree

articles/storage/queues/monitor-queue-storage.md

Lines changed: 84 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ Azure Monitor provides the [.NET SDK](https://www.nuget.org/packages/microsoft.a
159159

160160
In these examples, replace the `<resource-ID>` placeholder with the resource ID of the entire storage account or the queue. You can find these resource IDs on the **Properties** pages of your storage account in the Azure portal.
161161

162-
These examples use `DefaultAzureCredential` from the `Azure.Identity` package, which supports passwordless authentication using your local developer credentials or a managed identity in Azure. Add a reference to the [Azure.Monitor.Query](https://www.nuget.org/packages/Azure.Monitor.Query) and [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) NuGet packages before running these samples.
162+
These examples use `DefaultAzureCredential` from the `Azure.Identity` package, which supports passwordless authentication using your local developer credentials or a managed identity in Azure. Before running these samples, install the [Azure.Monitor.Query](https://www.nuget.org/packages/Azure.Monitor.Query) and [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) NuGet packages:
163+
164+
```bash
165+
dotnet add package Azure.Monitor.Query
166+
dotnet add package Azure.Identity
167+
```
163168

164169
#### List the account-level metric definition
165170

@@ -170,28 +175,28 @@ using Azure.Identity;
170175
using Azure.Monitor.Query;
171176
using Azure.Monitor.Query.Models;
172177

173-
public static async Task ListStorageMetricDefinition()
178+
async Task ListStorageMetricDefinition()
179+
{
180+
var resourceId = "<resource-ID>";
181+
182+
var credential = new DefaultAzureCredential();
183+
var client = new MetricsQueryClient(credential);
184+
185+
// Get metric definitions for the resource. The metrics namespace is optional. If not specified, it will return metric definitions for all namespaces.
186+
var metricDefinitions = client.GetMetricDefinitionsAsync(resourceId, "<metrics-namespace>");
187+
188+
await foreach (var metricDefinition in metricDefinitions)
174189
{
175-
var resourceId = "<resource-ID>";
176-
177-
var credential = new DefaultAzureCredential();
178-
var client = new MetricsQueryClient(credential);
179-
180-
var metricDefinitions = client.GetMetricDefinitionsAsync(resourceId);
181-
182-
await foreach (var metricDefinition in metricDefinitions)
183-
{
184-
// Enumerate metric definition:
185-
// Id
186-
// Name
187-
// Unit
188-
// MetricAvailabilities
189-
// PrimaryAggregationType
190-
// Dimensions
191-
// IsDimensionRequired
192-
}
190+
// Enumerate metric definition:
191+
// Id
192+
// Name
193+
// Unit
194+
// MetricAvailabilities
195+
// PrimaryAggregationType
196+
// Dimensions
197+
// IsDimensionRequired
193198
}
194-
199+
}
195200
```
196201

197202
#### Read account-level metric values
@@ -203,36 +208,35 @@ using Azure.Identity;
203208
using Azure.Monitor.Query;
204209
using Azure.Monitor.Query.Models;
205210

206-
public static async Task ReadStorageMetricValue()
207-
{
208-
var resourceId = "<resource-ID>";
209-
210-
var credential = new DefaultAzureCredential();
211-
var client = new MetricsQueryClient(credential);
212-
213-
var response = await client.QueryResourceAsync(
214-
resourceId,
215-
new[] { "UsedCapacity" },
216-
new MetricsQueryOptions
217-
{
218-
TimeRange = new QueryTimeRange(TimeSpan.FromHours(3)),
219-
Granularity = TimeSpan.FromHours(1),
220-
Aggregations = { MetricAggregationType.Average }
221-
});
222-
223-
foreach (var metric in response.Value.Metrics)
211+
async Task ReadStorageMetricValue()
212+
{
213+
var resourceId = "<resource-ID>";
214+
215+
var credential = new DefaultAzureCredential();
216+
var client = new MetricsQueryClient(credential);
217+
218+
var response = await client.QueryResourceAsync(
219+
resourceId,
220+
new[] { "UsedCapacity" },
221+
new MetricsQueryOptions
224222
{
225-
// Enumerate metric value
226-
// Id
227-
// Name
228-
// Type
229-
// Unit
230-
// Timeseries
231-
// - Data
232-
// - Metadatavalues
233-
}
234-
}
223+
TimeRange = new QueryTimeRange(TimeSpan.FromHours(3)),
224+
Granularity = TimeSpan.FromHours(1),
225+
Aggregations = { MetricAggregationType.Average }
226+
});
235227

228+
foreach (var metric in response.Value.Metrics)
229+
{
230+
// Enumerate metric value
231+
// Id
232+
// Name
233+
// Type
234+
// Unit
235+
// Timeseries
236+
// - Data
237+
// - Metadatavalues
238+
}
239+
}
236240
```
237241

238242
#### Read multidimensional metric values
@@ -246,40 +250,39 @@ using Azure.Identity;
246250
using Azure.Monitor.Query;
247251
using Azure.Monitor.Query.Models;
248252

249-
public static async Task ReadStorageMetricValueTest()
250-
{
251-
// Resource ID for queue storage
252-
var resourceId = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}/queueServices/default";
253-
254-
var credential = new DefaultAzureCredential();
255-
var client = new MetricsQueryClient(credential);
256-
257-
// It's applicable to define a metadata filter when a metric supports dimensions.
258-
// More conditions can be added with the 'or' and 'and' operators, example: BlobType eq 'BlockBlob' or BlobType eq 'PageBlob'
259-
var response = await client.QueryResourceAsync(
260-
resourceId,
261-
new[] { "BlobCapacity" },
262-
new MetricsQueryOptions
263-
{
264-
TimeRange = new QueryTimeRange(TimeSpan.FromHours(3)),
265-
Granularity = TimeSpan.FromHours(1),
266-
Aggregations = { MetricAggregationType.Average },
267-
Filter = "BlobType eq 'BlockBlob'"
268-
});
269-
270-
foreach (var metric in response.Value.Metrics)
253+
async Task ReadStorageMetricValueTest()
254+
{
255+
// Resource ID for queue storage
256+
var resourceId = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}/queueServices/default";
257+
258+
var credential = new DefaultAzureCredential();
259+
var client = new MetricsQueryClient(credential);
260+
261+
// It's applicable to define a metadata filter when a metric supports dimensions.
262+
// More conditions can be added with the 'or' and 'and' operators, example: BlobType eq 'BlockBlob' or BlobType eq 'PageBlob'
263+
var response = await client.QueryResourceAsync(
264+
resourceId,
265+
new[] { "BlobCapacity" },
266+
new MetricsQueryOptions
271267
{
272-
// Enumerate metric value
273-
// Id
274-
// Name
275-
// Type
276-
// Unit
277-
// Timeseries
278-
// - Data
279-
// - Metadatavalues
280-
}
281-
}
268+
TimeRange = new QueryTimeRange(TimeSpan.FromHours(3)),
269+
Granularity = TimeSpan.FromHours(1),
270+
Aggregations = { MetricAggregationType.Average },
271+
Filter = "BlobType eq 'BlockBlob'"
272+
});
282273

274+
foreach (var metric in response.Value.Metrics)
275+
{
276+
// Enumerate metric value
277+
// Id
278+
// Name
279+
// Type
280+
// Unit
281+
// Timeseries
282+
// - Data
283+
// - Metadatavalues
284+
}
285+
}
283286
```
284287

285288
---

articles/storage/tables/monitor-table-storage.md

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ Azure Monitor provides the [.NET SDK](https://www.nuget.org/packages/microsoft.a
159159

160160
In these examples, replace the `<resource-ID>` placeholder with the resource ID of the entire storage account or the Table Storage service. You can find these resource IDs on the **Properties** pages of your storage account in the Azure portal.
161161

162-
These examples use `DefaultAzureCredential` from the `Azure.Identity` package, which supports passwordless authentication using your local developer credentials or a managed identity in Azure. Add a reference to the [Azure.Monitor.Query](https://www.nuget.org/packages/Azure.Monitor.Query) and [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) NuGet packages before running these samples.
162+
These examples use `DefaultAzureCredential` from the `Azure.Identity` package, which supports passwordless authentication using your local developer credentials or a managed identity in Azure. Before running these samples, install the [Azure.Monitor.Query](https://www.nuget.org/packages/Azure.Monitor.Query) and [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) NuGet packages:
163+
164+
```bash
165+
dotnet add package Azure.Monitor.Query
166+
dotnet add package Azure.Identity
167+
```
163168

164169
#### List the account-level metric definition
165170

@@ -170,28 +175,27 @@ using Azure.Identity;
170175
using Azure.Monitor.Query;
171176
using Azure.Monitor.Query.Models;
172177

173-
public static async Task ListStorageMetricDefinition()
174-
{
175-
var resourceId = "<resource-ID>";
178+
async Task ListStorageMetricDefinition()
179+
{
180+
var resourceId = "<resource-ID>";
176181

177-
var credential = new DefaultAzureCredential();
178-
var client = new MetricsQueryClient(credential);
182+
var credential = new DefaultAzureCredential();
183+
var client = new MetricsQueryClient(credential);
179184

180-
var metricDefinitions = client.GetMetricDefinitionsAsync(resourceId);
185+
var metricDefinitions = client.GetMetricDefinitionsAsync(resourceId, "<metrics-namespace>");
181186

182-
await foreach (var metricDefinition in metricDefinitions)
183-
{
184-
// Enumerate metric definition:
185-
// Id
186-
// Name
187-
// Unit
188-
// MetricAvailabilities
189-
// PrimaryAggregationType
190-
// Dimensions
191-
// IsDimensionRequired
192-
}
187+
await foreach (var metricDefinition in metricDefinitions)
188+
{
189+
// Enumerate metric definition:
190+
// Id
191+
// Name
192+
// Unit
193+
// MetricAvailabilities
194+
// PrimaryAggregationType
195+
// Dimensions
196+
// IsDimensionRequired
193197
}
194-
198+
}
195199
```
196200

197201
#### Read account-level metric values
@@ -203,36 +207,35 @@ using Azure.Identity;
203207
using Azure.Monitor.Query;
204208
using Azure.Monitor.Query.Models;
205209

206-
public static async Task ReadStorageMetricValue()
207-
{
208-
var resourceId = "<resource-ID>";
209-
210-
var credential = new DefaultAzureCredential();
211-
var client = new MetricsQueryClient(credential);
212-
213-
var response = await client.QueryResourceAsync(
214-
resourceId,
215-
new[] { "UsedCapacity" },
216-
new MetricsQueryOptions
217-
{
218-
TimeRange = new QueryTimeRange(TimeSpan.FromHours(3)),
219-
Granularity = TimeSpan.FromHours(1),
220-
Aggregations = { MetricAggregationType.Average }
221-
});
222-
223-
foreach (var metric in response.Value.Metrics)
210+
async Task ReadStorageMetricValue()
211+
{
212+
var resourceId = "<resource-ID>";
213+
214+
var credential = new DefaultAzureCredential();
215+
var client = new MetricsQueryClient(credential);
216+
217+
var response = await client.QueryResourceAsync(
218+
resourceId,
219+
new[] { "UsedCapacity" },
220+
new MetricsQueryOptions
224221
{
225-
// Enumerate metric value
226-
// Id
227-
// Name
228-
// Type
229-
// Unit
230-
// Timeseries
231-
// - Data
232-
// - Metadatavalues
233-
}
234-
}
222+
TimeRange = new QueryTimeRange(TimeSpan.FromHours(3)),
223+
Granularity = TimeSpan.FromHours(1),
224+
Aggregations = { MetricAggregationType.Average }
225+
});
235226

227+
foreach (var metric in response.Value.Metrics)
228+
{
229+
// Enumerate metric value
230+
// Id
231+
// Name
232+
// Type
233+
// Unit
234+
// Timeseries
235+
// - Data
236+
// - Metadatavalues
237+
}
238+
}
236239
```
237240

238241
#### Read multidimensional metric values
@@ -246,40 +249,39 @@ using Azure.Identity;
246249
using Azure.Monitor.Query;
247250
using Azure.Monitor.Query.Models;
248251

249-
public static async Task ReadStorageMetricValueTest()
250-
{
251-
// Resource ID for table storage
252-
var resourceId = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}/tableServices/default";
253-
254-
var credential = new DefaultAzureCredential();
255-
var client = new MetricsQueryClient(credential);
256-
257-
// It's applicable to define a metadata filter when a metric supports dimensions.
258-
// More conditions can be added with the 'or' and 'and' operators, example: BlobType eq 'BlockBlob' or BlobType eq 'PageBlob'
259-
var response = await client.QueryResourceAsync(
260-
resourceId,
261-
new[] { "BlobCapacity" },
262-
new MetricsQueryOptions
263-
{
264-
TimeRange = new QueryTimeRange(TimeSpan.FromHours(3)),
265-
Granularity = TimeSpan.FromHours(1),
266-
Aggregations = { MetricAggregationType.Average },
267-
Filter = "BlobType eq 'BlockBlob'"
268-
});
269-
270-
foreach (var metric in response.Value.Metrics)
252+
async Task ReadStorageMetricValueTest()
253+
{
254+
// Resource ID for table storage
255+
var resourceId = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}/tableServices/default";
256+
257+
var credential = new DefaultAzureCredential();
258+
var client = new MetricsQueryClient(credential);
259+
260+
// It's applicable to define a metadata filter when a metric supports dimensions.
261+
// More conditions can be added with the 'or' and 'and' operators, example: BlobType eq 'BlockBlob' or BlobType eq 'PageBlob'
262+
var response = await client.QueryResourceAsync(
263+
resourceId,
264+
new[] { "BlobCapacity" },
265+
new MetricsQueryOptions
271266
{
272-
// Enumerate metric value
273-
// Id
274-
// Name
275-
// Type
276-
// Unit
277-
// Timeseries
278-
// - Data
279-
// - Metadatavalues
280-
}
281-
}
267+
TimeRange = new QueryTimeRange(TimeSpan.FromHours(3)),
268+
Granularity = TimeSpan.FromHours(1),
269+
Aggregations = { MetricAggregationType.Average },
270+
Filter = "BlobType eq 'BlockBlob'"
271+
});
282272

273+
foreach (var metric in response.Value.Metrics)
274+
{
275+
// Enumerate metric value
276+
// Id
277+
// Name
278+
// Type
279+
// Unit
280+
// Timeseries
281+
// - Data
282+
// - Metadatavalues
283+
}
284+
}
283285
```
284286

285287
---

0 commit comments

Comments
 (0)