0
# Diagnostics and Monitoring
1
2
Diagnostic capabilities, recommendations, health monitoring, and troubleshooting tools for web applications and services.
3
4
## Package Information
5
6
- **Package**: azure-mgmt-web
7
- **Modules**: `DiagnosticsOperations`, `RecommendationsOperations`, `ResourceHealthMetadataOperations`
8
- **Access**: `client.diagnostics`, `client.recommendations`, `client.resource_health_metadata`
9
10
## Core Imports
11
12
```python
13
from azure.mgmt.web import WebSiteManagementClient
14
from azure.mgmt.web.models import (
15
DetectorResponse, DiagnosticAnalysis, Recommendation,
16
ResourceHealthMetadata, DiagnosticCategory
17
)
18
from azure.identity import DefaultAzureCredential
19
```
20
21
## Basic Usage
22
23
```python
24
from azure.mgmt.web import WebSiteManagementClient
25
from azure.identity import DefaultAzureCredential
26
27
credential = DefaultAzureCredential()
28
client = WebSiteManagementClient(credential, subscription_id)
29
30
# Get recommendations for subscription
31
recommendations = client.recommendations.list()
32
for rec in recommendations:
33
print(f"Recommendation: {rec.name}, Level: {rec.level}")
34
35
# Get diagnostics for a web app
36
diagnostics = client.diagnostics.list_site_detector_responses(
37
resource_group_name="my-resource-group",
38
site_name="my-web-app"
39
)
40
```
41
42
## Diagnostic Operations
43
44
### List Site Detectors
45
46
Get all available diagnostic detectors for a web app.
47
48
```python { .api }
49
def list_site_detectors(
50
self,
51
resource_group_name: str,
52
site_name: str,
53
**kwargs
54
) -> List[DetectorDefinition]:
55
"""
56
List site diagnostic detectors.
57
58
Args:
59
resource_group_name: Name of the resource group
60
site_name: Name of the web app
61
62
Returns:
63
List of DetectorDefinition objects
64
"""
65
```
66
67
### Get Site Detector Response
68
69
Execute a specific diagnostic detector and get results.
70
71
```python { .api }
72
def get_site_detector_response(
73
self,
74
resource_group_name: str,
75
site_name: str,
76
detector_name: str,
77
**kwargs
78
) -> DetectorResponse:
79
"""
80
Get site detector response.
81
82
Args:
83
resource_group_name: Name of the resource group
84
site_name: Name of the web app
85
detector_name: Name of the detector
86
87
Returns:
88
DetectorResponse object
89
"""
90
```
91
92
### List Site Detector Responses
93
94
Get responses from all diagnostic detectors for a web app.
95
96
```python { .api }
97
def list_site_detector_responses(
98
self,
99
resource_group_name: str,
100
site_name: str,
101
**kwargs
102
) -> List[DetectorResponse]:
103
"""
104
List all site detector responses.
105
106
Args:
107
resource_group_name: Name of the resource group
108
site_name: Name of the web app
109
110
Returns:
111
List of DetectorResponse objects
112
"""
113
```
114
115
**Usage Example:**
116
117
```python
118
# List available detectors
119
detectors = client.diagnostics.list_site_detectors(
120
resource_group_name="my-resource-group",
121
site_name="my-web-app"
122
)
123
124
for detector in detectors:
125
print(f"Detector: {detector.name}, Display Name: {detector.display_name}")
126
127
# Run a specific detector
128
response = client.diagnostics.get_site_detector_response(
129
resource_group_name="my-resource-group",
130
site_name="my-web-app",
131
detector_name="availability"
132
)
133
134
print(f"Detector Status: {response.metadata.status}")
135
for insight in response.dataset:
136
print(f"Insight: {insight.rendering_properties.title}")
137
```
138
139
### Site Diagnostic Analysis
140
141
Get comprehensive diagnostic analysis for a web app.
142
143
```python { .api }
144
def list_site_analyses(
145
self,
146
resource_group_name: str,
147
site_name: str,
148
**kwargs
149
) -> List[AnalysisDefinition]:
150
"""
151
List site diagnostic analyses.
152
153
Args:
154
resource_group_name: Name of the resource group
155
site_name: Name of the web app
156
157
Returns:
158
List of AnalysisDefinition objects
159
"""
160
```
161
162
```python { .api }
163
def get_site_analysis(
164
self,
165
resource_group_name: str,
166
site_name: str,
167
analysis_name: str,
168
**kwargs
169
) -> DiagnosticAnalysis:
170
"""
171
Get site diagnostic analysis.
172
173
Args:
174
resource_group_name: Name of the resource group
175
site_name: Name of the web app
176
analysis_name:Name of the analysis
177
178
Returns:
179
DiagnosticAnalysis object
180
"""
181
```
182
183
### Hosting Environment Diagnostics
184
185
Get diagnostics for App Service Environments.
186
187
```python { .api }
188
def list_hosting_environment_detector_responses(
189
self,
190
resource_group_name: str,
191
name: str,
192
**kwargs
193
) -> List[DetectorResponse]:
194
"""
195
List hosting environment detector responses.
196
197
Args:
198
resource_group_name: Name of the resource group
199
name: Name of the hosting environment
200
201
Returns:
202
List of DetectorResponse objects
203
"""
204
```
205
206
```python { .api }
207
def get_hosting_environment_detector_response(
208
self,
209
resource_group_name: str,
210
name: str,
211
detector_name: str,
212
**kwargs
213
) -> DetectorResponse:
214
"""
215
Get hosting environment detector response.
216
217
Args:
218
resource_group_name: Name of the resource group
219
name: Name of the hosting environment
220
detector_name: Name of the detector
221
222
Returns:
223
DetectorResponse object
224
"""
225
```
226
227
## Recommendations
228
229
### List Recommendations
230
231
Get performance and configuration recommendations.
232
233
```python { .api }
234
def list(self, **kwargs) -> List[Recommendation]:
235
"""
236
List recommendations for the subscription.
237
238
Returns:
239
List of Recommendation objects
240
"""
241
```
242
243
```python { .api }
244
def list_recommended_rules_for_web_app(
245
self,
246
resource_group_name: str,
247
site_name: str,
248
**kwargs
249
) -> List[Recommendation]:
250
"""
251
List recommendations for a specific web app.
252
253
Args:
254
resource_group_name: Name of the resource group
255
site_name: Name of the web app
256
257
Returns:
258
List of Recommendation objects
259
"""
260
```
261
262
### Get Recommendation
263
264
Retrieve details for a specific recommendation.
265
266
```python { .api }
267
def get_rule_details_by_web_app(
268
self,
269
resource_group_name: str,
270
site_name: str,
271
name: str,
272
**kwargs
273
) -> Recommendation:
274
"""
275
Get recommendation details for a web app.
276
277
Args:
278
resource_group_name: Name of the resource group
279
site_name: Name of the web app
280
name: Recommendation name
281
282
Returns:
283
Recommendation object
284
"""
285
```
286
287
### Disable Recommendation
288
289
Disable a specific recommendation rule.
290
291
```python { .api }
292
def disable_recommendation_for_site(
293
self,
294
resource_group_name: str,
295
site_name: str,
296
name: str,
297
**kwargs
298
) -> None:
299
"""
300
Disable a recommendation for a site.
301
302
Args:
303
resource_group_name: Name of the resource group
304
site_name: Name of the web app
305
name: Recommendation name
306
"""
307
```
308
309
**Usage Example:**
310
311
```python
312
# Get recommendations for a web app
313
recommendations = client.recommendations.list_recommended_rules_for_web_app(
314
resource_group_name="my-resource-group",
315
site_name="my-web-app"
316
)
317
318
for recommendation in recommendations:
319
print(f"Rule: {recommendation.name}")
320
print(f"Level: {recommendation.level}")
321
print(f"Message: {recommendation.message}")
322
print(f"Category: {recommendation.category_tags}")
323
324
# Get detailed recommendation
325
details = client.recommendations.get_rule_details_by_web_app(
326
resource_group_name="my-resource-group",
327
site_name="my-web-app",
328
name=recommendation.name
329
)
330
print(f"Action: {details.action_name}")
331
332
# Disable non-critical recommendations
333
if recommendation.level == "Information":
334
client.recommendations.disable_recommendation_for_site(
335
resource_group_name="my-resource-group",
336
site_name="my-web-app",
337
name=recommendation.name
338
)
339
```
340
341
## Resource Health Metadata
342
343
### List Health Metadata
344
345
Get resource health information for services.
346
347
```python { .api }
348
def list(self, **kwargs) -> List[ResourceHealthMetadata]:
349
"""
350
List resource health metadata.
351
352
Returns:
353
List of ResourceHealthMetadata objects
354
"""
355
```
356
357
```python { .api }
358
def list_by_resource_group(
359
self,
360
resource_group_name: str,
361
**kwargs
362
) -> List[ResourceHealthMetadata]:
363
"""
364
List resource health metadata by resource group.
365
366
Args:
367
resource_group_name: Name of the resource group
368
369
Returns:
370
List of ResourceHealthMetadata objects
371
"""
372
```
373
374
```python { .api }
375
def list_by_site(
376
self,
377
resource_group_name: str,
378
name: str,
379
**kwargs
380
) -> List[ResourceHealthMetadata]:
381
"""
382
List resource health metadata for a site.
383
384
Args:
385
resource_group_name: Name of the resource group
386
name: Name of the site
387
388
Returns:
389
List of ResourceHealthMetadata objects
390
"""
391
```
392
393
**Usage Example:**
394
395
```python
396
# Get health metadata for a site
397
health_metadata = client.resource_health_metadata.list_by_site(
398
resource_group_name="my-resource-group",
399
name="my-web-app"
400
)
401
402
for metadata in health_metadata:
403
print(f"Category: {metadata.category}")
404
print(f"Title: {metadata.title}")
405
if metadata.signal_availability:
406
print("Health signals are available")
407
```
408
409
## Diagnostic Categories
410
411
### List Diagnostic Categories
412
413
Get available diagnostic categories for analysis.
414
415
```python { .api }
416
def list_site_diagnostic_categories(
417
self,
418
resource_group_name: str,
419
site_name: str,
420
**kwargs
421
) -> List[DiagnosticCategory]:
422
"""
423
List diagnostic categories for a site.
424
425
Args:
426
resource_group_name: Name of the resource group
427
site_name: Name of the web app
428
429
Returns:
430
List of DiagnosticCategory objects
431
"""
432
```
433
434
```python { .api }
435
def get_site_diagnostic_category(
436
self,
437
resource_group_name: str,
438
site_name: str,
439
diagnostic_category: str,
440
**kwargs
441
) -> DiagnosticCategory:
442
"""
443
Get specific diagnostic category for a site.
444
445
Args:
446
resource_group_name: Name of the resource group
447
site_name: Name of the web app
448
diagnostic_category: Category name
449
450
Returns:
451
DiagnosticCategory object
452
"""
453
```
454
455
**Usage Example:**
456
457
```python
458
# List diagnostic categories
459
categories = client.diagnostics.list_site_diagnostic_categories(
460
resource_group_name="my-resource-group",
461
site_name="my-web-app"
462
)
463
464
for category in categories:
465
print(f"Category: {category.name}, Description: {category.description}")
466
467
# Get specific category details
468
availability_category = client.diagnostics.get_site_diagnostic_category(
469
resource_group_name="my-resource-group",
470
site_name="my-web-app",
471
diagnostic_category="availability"
472
)
473
```
474
475
## Performance Monitoring
476
477
### Get Performance Counters
478
479
Retrieve performance counter data for a web app.
480
481
```python { .api }
482
def list_perfmon_counters(
483
self,
484
resource_group_name: str,
485
name: str,
486
**kwargs
487
) -> List[PerfMonCounterCollection]:
488
"""
489
List performance monitor counters.
490
491
Args:
492
resource_group_name: Name of the resource group
493
name: Name of the web app
494
495
Returns:
496
List of PerfMonCounterCollection objects
497
"""
498
```
499
500
### Get Site Metrics
501
502
Retrieve metrics and telemetry data.
503
504
```python { .api }
505
def list_site_processes(
506
self,
507
resource_group_name: str,
508
name: str,
509
**kwargs
510
) -> List[ProcessInfo]:
511
"""
512
List site processes.
513
514
Args:
515
resource_group_name: Name of the resource group
516
name: Name of the web app
517
518
Returns:
519
List of ProcessInfo objects
520
"""
521
```
522
523
**Usage Example:**
524
525
```python
526
# Get performance counters
527
perf_counters = client.diagnostics.list_perfmon_counters(
528
resource_group_name="my-resource-group",
529
name="my-web-app"
530
)
531
532
for counter in perf_counters:
533
print(f"Counter: {counter.name}, Value: {counter.value}")
534
535
# Get running processes
536
processes = client.diagnostics.list_site_processes(
537
resource_group_name="my-resource-group",
538
name="my-web-app"
539
)
540
541
for process in processes:
542
print(f"Process: {process.name}, CPU: {process.cpu_percent}%")
543
```
544
545
## Types
546
547
### DetectorResponse
548
549
```python { .api }
550
class DetectorResponse:
551
"""Response from a diagnostic detector."""
552
id: Optional[str]
553
name: Optional[str]
554
type: Optional[str]
555
metadata: Optional[DetectorInfo]
556
dataset: Optional[List[DiagnosticData]]
557
status: Optional[Status]
558
data_providers_metadata: Optional[List[DataProviderMetadata]]
559
suggested_utterances: Optional[SuggestedUtterances]
560
```
561
562
### Recommendation
563
564
```python { .api }
565
class Recommendation:
566
"""Performance or configuration recommendation."""
567
id: Optional[str]
568
name: Optional[str]
569
type: Optional[str]
570
creation_time: Optional[datetime]
571
recommendation_id: Optional[str]
572
resource_id: Optional[str]
573
resource_scope: Optional[str]
574
rule_name: Optional[str]
575
display_name: Optional[str]
576
message: Optional[str]
577
level: Optional[str] # Critical, Warning, Information, NonUrgentSuggestion
578
channels: Optional[str] # Notification, Api, Email, Webhook, All
579
category_tags: Optional[List[str]]
580
action_name: Optional[str]
581
enabled: Optional[int]
582
states: Optional[List[str]]
583
start_time: Optional[datetime]
584
end_time: Optional[datetime]
585
next_notification_time: Optional[datetime]
586
notification_expiration_time: Optional[datetime]
587
notified_time: Optional[datetime]
588
score: Optional[float]
589
is_dynamic: Optional[bool]
590
extension_name: Optional[str]
591
blade_name: Optional[str]
592
forward_link: Optional[str]
593
```
594
595
### ResourceHealthMetadata
596
597
```python { .api }
598
class ResourceHealthMetadata:
599
"""Resource health metadata information."""
600
id: Optional[str]
601
name: Optional[str]
602
type: Optional[str]
603
category: Optional[str]
604
title: Optional[str]
605
description: Optional[str]
606
signal_availability: Optional[bool]
607
```
608
609
### DiagnosticAnalysis
610
611
```python { .api }
612
class DiagnosticAnalysis:
613
"""Diagnostic analysis result."""
614
id: Optional[str]
615
name: Optional[str]
616
type: Optional[str]
617
start_time: Optional[datetime]
618
end_time: Optional[datetime]
619
abnormal_time_periods: Optional[List[AbnormalTimePeriod]]
620
payload: Optional[List[AnalysisData]]
621
non_correlative_detectors: Optional[List[DetectorDefinition]]
622
```
623
624
### DiagnosticCategory
625
626
```python { .api }
627
class DiagnosticCategory:
628
"""Diagnostic category information."""
629
id: Optional[str]
630
name: Optional[str]
631
type: Optional[str]
632
description: Optional[str]
633
```