0
# Usage and Monitoring
1
2
Operations for querying usage statistics, quota information, and available Azure operations for monitoring and capacity planning. These capabilities help track resource consumption and plan for scaling search services.
3
4
## Capabilities
5
6
### Usage and Quota Information
7
8
Query usage statistics and quota limits for search services to monitor consumption and plan capacity requirements.
9
10
```python { .api }
11
def list_by_subscription(
12
location: str,
13
*,
14
client_request_id: Optional[str] = None,
15
**kwargs
16
) -> ItemPaged[QuotaUsageResult]:
17
"""
18
Get quota usage information for search services in a specific location.
19
20
Parameters:
21
location (str): Azure region to query usage for
22
client_request_id (str, optional): Client-generated request ID
23
24
Returns:
25
ItemPaged[QuotaUsageResult]: Usage and quota information for various search service resources
26
27
Raises:
28
HttpResponseError: Invalid location or access denied
29
"""
30
```
31
32
### Azure Operations Discovery
33
34
List all available Azure operations for the Search Management service to understand available APIs and capabilities.
35
36
```python { .api }
37
def list(**kwargs) -> ItemPaged[Operation]:
38
"""
39
List all available operations for the Azure Search Management service.
40
41
Returns:
42
ItemPaged[Operation]: All available operations with metadata
43
44
Raises:
45
HttpResponseError: Service error or access denied
46
"""
47
```
48
49
**Usage Example:**
50
51
```python
52
# Get usage information for a specific region
53
usage_info = client.usages.list_by_subscription(location="East US")
54
55
print("Search Service Usage in East US:")
56
for usage in usage_info:
57
print(f"Resource: {usage.name.localized_value}")
58
print(f" Current Usage: {usage.current_value} {usage.unit}")
59
print(f" Limit: {usage.limit} {usage.unit}")
60
61
# Calculate usage percentage
62
if usage.limit > 0:
63
percentage = (usage.current_value / usage.limit) * 100
64
print(f" Usage: {percentage:.1f}%")
65
66
# Alert if usage is high
67
if percentage > 80:
68
print(f" WARNING: High usage detected!")
69
70
print()
71
72
# List all available operations
73
operations = client.operations.list()
74
print("Available Azure Search Management Operations:")
75
for operation in operations:
76
print(f"Operation: {operation.name}")
77
print(f" Display Name: {operation.display.operation}")
78
print(f" Provider: {operation.display.provider}")
79
print(f" Resource: {operation.display.resource}")
80
print(f" Description: {operation.display.description}")
81
print(f" Origin: {operation.origin}")
82
print()
83
```
84
85
## Data Models
86
87
### QuotaUsageResult
88
89
Information about current usage and limits for search service resources.
90
91
```python { .api }
92
class QuotaUsageResult:
93
"""
94
Usage and quota information for a search service resource.
95
96
Attributes:
97
id (str): Usage resource ID
98
unit (str): Unit of measurement (e.g., "Count", "Bytes")
99
current_value (int): Current usage value
100
limit (int): Maximum allowed usage (quota limit)
101
name (QuotaUsageResultName): Resource name information
102
"""
103
104
class QuotaUsageResultName:
105
"""
106
Name information for a quota usage result.
107
108
Attributes:
109
value (str): Resource name identifier
110
localized_value (str): Human-readable localized name
111
"""
112
```
113
114
### Operation
115
116
Information about available Azure operations for the Search Management service.
117
118
```python { .api }
119
class Operation:
120
"""
121
Azure operation metadata for Search Management service.
122
123
Attributes:
124
name (str): Operation name (e.g., "Microsoft.Search/searchServices/read")
125
display (OperationDisplay): Display information for the operation
126
origin (Origin): Origin of the operation
127
is_data_action (bool): Whether this is a data plane action
128
action_type (ActionType): Type of action
129
"""
130
131
class OperationDisplay:
132
"""
133
Display information for an Azure operation.
134
135
Attributes:
136
provider (str): Resource provider name
137
resource (str): Resource type
138
operation (str): Operation name
139
description (str): Operation description
140
"""
141
```
142
143
### Supporting Enums
144
145
```python { .api }
146
class Origin(str, Enum):
147
"""Operation origin values."""
148
USER = "user"
149
SYSTEM = "system"
150
USER_SYSTEM = "user,system"
151
152
class ActionType(str, Enum):
153
"""Action type values."""
154
INTERNAL = "internal"
155
```
156
157
## Monitoring Scenarios
158
159
### Quota Monitoring and Alerting
160
161
```python
162
def monitor_search_quotas(regions: List[str], alert_threshold: float = 80.0):
163
"""
164
Monitor search service quotas across multiple regions and alert on high usage.
165
166
Args:
167
regions: List of Azure regions to monitor
168
alert_threshold: Usage percentage threshold for alerts (default 80%)
169
"""
170
171
alerts = []
172
173
for region in regions:
174
print(f"\nChecking quotas in {region}:")
175
176
try:
177
usage_info = client.usages.list_by_subscription(location=region)
178
179
for usage in usage_info:
180
resource_name = usage.name.localized_value
181
current = usage.current_value
182
limit = usage.limit
183
184
if limit > 0:
185
percentage = (current / limit) * 100
186
print(f" {resource_name}: {current}/{limit} ({percentage:.1f}%)")
187
188
# Check if usage exceeds threshold
189
if percentage >= alert_threshold:
190
alert = {
191
"region": region,
192
"resource": resource_name,
193
"usage": current,
194
"limit": limit,
195
"percentage": percentage
196
}
197
alerts.append(alert)
198
print(f" π¨ ALERT: Usage above {alert_threshold}%!")
199
else:
200
print(f" {resource_name}: {current} (no limit)")
201
202
except Exception as e:
203
print(f" Error getting usage for {region}: {e}")
204
205
return alerts
206
207
# Monitor quotas in key regions
208
regions_to_monitor = ["East US", "West US 2", "North Europe", "Southeast Asia"]
209
alerts = monitor_search_quotas(regions_to_monitor, alert_threshold=75.0)
210
211
# Process alerts
212
if alerts:
213
print(f"\nπ¨ Found {len(alerts)} quota alerts:")
214
for alert in alerts:
215
print(f" {alert['region']}: {alert['resource']} at {alert['percentage']:.1f}%")
216
else:
217
print("\nβ All quotas within acceptable limits")
218
```
219
220
### Capacity Planning
221
222
```python
223
def analyze_capacity_trends(regions: List[str]):
224
"""
225
Analyze current capacity usage for capacity planning.
226
"""
227
228
capacity_data = {}
229
230
for region in regions:
231
print(f"\nCapacity Analysis for {region}:")
232
233
usage_info = client.usages.list_by_subscription(location=region)
234
region_data = {}
235
236
for usage in usage_info:
237
resource_name = usage.name.localized_value
238
current = usage.current_value
239
limit = usage.limit
240
241
region_data[resource_name] = {
242
"current": current,
243
"limit": limit,
244
"available": limit - current if limit > 0 else "unlimited"
245
}
246
247
if limit > 0:
248
percentage = (current / limit) * 100
249
remaining = limit - current
250
251
print(f" {resource_name}:")
252
print(f" Used: {current}/{limit} ({percentage:.1f}%)")
253
print(f" Available: {remaining}")
254
255
# Capacity recommendations
256
if percentage > 90:
257
print(f" π CRITICAL: Consider requesting quota increase")
258
elif percentage > 70:
259
print(f" β οΈ WARNING: Monitor closely, may need more capacity soon")
260
elif percentage < 20:
261
print(f" π° INFO: Significant unused capacity available")
262
263
capacity_data[region] = region_data
264
265
return capacity_data
266
267
# Analyze capacity across regions
268
capacity_analysis = analyze_capacity_trends(["East US", "West US 2"])
269
```
270
271
### Service Operation Discovery
272
273
```python
274
def discover_available_operations():
275
"""
276
Discover and categorize all available Azure Search Management operations.
277
"""
278
279
operations = client.operations.list()
280
281
# Categorize operations
282
categories = {}
283
284
for operation in operations:
285
# Extract category from operation name
286
parts = operation.name.split('/')
287
if len(parts) >= 3:
288
category = parts[2] if parts[2] != 'searchServices' else parts[3] if len(parts) > 3 else 'general'
289
else:
290
category = 'general'
291
292
if category not in categories:
293
categories[category] = []
294
295
categories[category].append({
296
'name': operation.name,
297
'display_name': operation.display.operation,
298
'description': operation.display.description,
299
'resource': operation.display.resource,
300
'origin': operation.origin
301
})
302
303
# Display categorized operations
304
print("Available Azure Search Management Operations:\n")
305
306
for category, ops in categories.items():
307
print(f"π {category.upper()}:")
308
for op in ops:
309
print(f" β’ {op['display_name']}")
310
print(f" {op['description']}")
311
print(f" API: {op['name']}")
312
print()
313
314
return categories
315
316
# Discover all available operations
317
available_operations = discover_available_operations()
318
```
319
320
### Usage Reporting
321
322
```python
323
def generate_usage_report(regions: List[str], output_file: str = None):
324
"""
325
Generate a comprehensive usage report for search services.
326
"""
327
328
report_data = {
329
"timestamp": datetime.now().isoformat(),
330
"regions": {},
331
"summary": {}
332
}
333
334
total_usage = {}
335
total_limits = {}
336
337
for region in regions:
338
print(f"Generating report for {region}...")
339
340
usage_info = client.usages.list_by_subscription(location=region)
341
region_usage = {}
342
343
for usage in usage_info:
344
resource_name = usage.name.value
345
localized_name = usage.name.localized_value
346
347
region_usage[resource_name] = {
348
"name": localized_name,
349
"current": usage.current_value,
350
"limit": usage.limit,
351
"unit": usage.unit,
352
"percentage": (usage.current_value / usage.limit * 100) if usage.limit > 0 else 0
353
}
354
355
# Accumulate totals
356
if resource_name not in total_usage:
357
total_usage[resource_name] = 0
358
total_limits[resource_name] = 0
359
360
total_usage[resource_name] += usage.current_value
361
total_limits[resource_name] += usage.limit
362
363
report_data["regions"][region] = region_usage
364
365
# Generate summary
366
for resource_name in total_usage:
367
report_data["summary"][resource_name] = {
368
"total_usage": total_usage[resource_name],
369
"total_limit": total_limits[resource_name],
370
"percentage": (total_usage[resource_name] / total_limits[resource_name] * 100) if total_limits[resource_name] > 0 else 0
371
}
372
373
# Output report
374
if output_file:
375
import json
376
with open(output_file, 'w') as f:
377
json.dump(report_data, f, indent=2)
378
print(f"Report saved to {output_file}")
379
380
return report_data
381
382
# Generate usage report
383
from datetime import datetime
384
report = generate_usage_report(
385
regions=["East US", "West US 2", "North Europe"],
386
output_file="search_usage_report.json"
387
)
388
```