0
# Analytics and Monitoring
1
2
Traffic analytics through heat maps, health monitoring configuration, and real user metrics for performance optimization. These capabilities provide insights into traffic patterns, endpoint health, and user experience to optimize Traffic Manager configurations.
3
4
## Capabilities
5
6
### Heat Map Analytics
7
8
Retrieves traffic analytics and performance data showing user traffic patterns, query volumes, and latency measurements across geographic regions.
9
10
```python { .api }
11
def get(
12
resource_group_name: str,
13
profile_name: str,
14
top_left: Optional[List[float]] = None,
15
bot_right: Optional[List[float]] = None
16
) -> HeatMapModel:
17
"""
18
Gets the latest heat map for a Traffic Manager profile.
19
20
Args:
21
resource_group_name (str): Name of the resource group
22
profile_name (str): Name of the Traffic Manager profile
23
top_left (List[float], optional): Top-left coordinates [latitude, longitude]
24
bot_right (List[float], optional): Bottom-right coordinates [latitude, longitude]
25
26
Returns:
27
HeatMapModel: Heat map data with traffic flows and latency information
28
"""
29
```
30
31
**Usage Examples:**
32
33
```python
34
# Get global heat map for entire profile
35
heat_map = client.heat_map.get(
36
resource_group_name="my-rg",
37
profile_name="my-profile"
38
)
39
40
print(f"Heat map period: {heat_map.start_time} to {heat_map.end_time}")
41
print(f"Endpoints analyzed: {len(heat_map.endpoints)}")
42
43
# Analyze traffic flows
44
for traffic_flow in heat_map.traffic_flows:
45
print(f"Source: {traffic_flow.source_ip} ({traffic_flow.latitude}, {traffic_flow.longitude})")
46
for query_exp in traffic_flow.query_experiences:
47
print(f" -> Endpoint {query_exp.endpoint_id}: {query_exp.query_count} queries, {query_exp.latency}ms avg")
48
49
# Get regional heat map (e.g., North America)
50
na_heat_map = client.heat_map.get(
51
resource_group_name="my-rg",
52
profile_name="my-profile",
53
top_left=[60.0, -130.0], # Northwest corner
54
bot_right=[25.0, -70.0] # Southeast corner
55
)
56
```
57
58
### Real User Metrics Management
59
60
Manages Real User Metrics (RUM) keys that enable client-side performance measurement collection from actual users.
61
62
```python { .api }
63
def create_or_update() -> UserMetricsModel:
64
"""
65
Creates or updates the subscription-level Real User Metrics key.
66
67
Returns:
68
UserMetricsModel: User metrics configuration with operation key
69
"""
70
71
def get() -> UserMetricsModel:
72
"""
73
Gets the subscription-level Real User Metrics key.
74
75
Returns:
76
UserMetricsModel: Current user metrics configuration
77
"""
78
79
def delete() -> DeleteOperationResult:
80
"""
81
Deletes the subscription-level Real User Metrics key.
82
83
Returns:
84
DeleteOperationResult: Operation result
85
"""
86
```
87
88
**Usage Examples:**
89
90
```python
91
# Enable Real User Metrics for subscription
92
rum_config = client.traffic_manager_user_metrics_keys.create_or_update()
93
print(f"RUM Key: {rum_config.key}")
94
95
# Use the key in client-side JavaScript
96
js_code = f"""
97
<script>
98
// Add to your web pages to collect real user metrics
99
window.trafficManagerConfig = {{
100
subscriptionKey: "{rum_config.key}"
101
}};
102
</script>
103
<script src="https://js.monitor.azure.com/scripts/c/ms.tm-4.0.0.min.js"></script>
104
"""
105
106
# Check current RUM configuration
107
current_rum = client.traffic_manager_user_metrics_keys.get()
108
if current_rum.key:
109
print("Real User Metrics is enabled")
110
else:
111
print("Real User Metrics is not configured")
112
113
# Disable Real User Metrics
114
delete_result = client.traffic_manager_user_metrics_keys.delete()
115
if delete_result.operation_result:
116
print("Real User Metrics disabled successfully")
117
```
118
119
## Analytics Data Models
120
121
### Heat Map Model
122
123
```python { .api }
124
class HeatMapModel:
125
"""Traffic Manager heat map analytics data."""
126
start_time: datetime # Heat map time window start
127
end_time: datetime # Heat map time window end
128
endpoints: List[HeatMapEndpoint] # Endpoints included in analysis
129
traffic_flows: List[TrafficFlow] # Traffic flow data points
130
131
class HeatMapEndpoint:
132
"""Sparse endpoint representation for heat maps."""
133
resource_id: str # ARM Resource ID
134
endpoint_id: int # Unique endpoint identifier for heat map
135
136
class TrafficFlow:
137
"""Heat map traffic flow properties."""
138
source_ip: str # Source IP address (masked for privacy)
139
latitude: float # Approximate source latitude
140
longitude: float # Approximate source longitude
141
query_experiences: List[QueryExperience] # Performance data for each endpoint
142
143
class QueryExperience:
144
"""Heat map query experience properties."""
145
endpoint_id: int # Target endpoint ID (required)
146
query_count: int # Number of queries (required)
147
latency: float # Average query latency in milliseconds
148
```
149
150
### User Metrics Model
151
152
```python { .api }
153
class UserMetricsModel:
154
"""Traffic Manager user metrics configuration."""
155
key: str # User metrics operation key for client integration
156
```
157
158
## Health Monitoring Configuration
159
160
Health monitoring is configured at the profile level through the `MonitorConfig` class but affects how endpoints are evaluated for traffic routing.
161
162
### Monitor Configuration Details
163
164
```python { .api }
165
class MonitorConfig:
166
"""Health monitoring configuration for endpoints."""
167
# Status and protocol
168
profile_monitor_status: ProfileMonitorStatus # Overall monitoring status
169
protocol: MonitorProtocol # Health check protocol
170
port: int # TCP port (1-65535)
171
path: str # Path for HTTP(S) checks
172
173
# Timing configuration
174
interval_in_seconds: int # Check interval (10 or 30)
175
timeout_in_seconds: int # Check timeout (5-10)
176
tolerated_number_of_failures: int # Allowed failures (0-9)
177
178
# Advanced monitoring
179
custom_headers: List[MonitorConfigCustomHeadersItem] # Custom headers
180
expected_status_code_ranges: List[MonitorConfigExpectedStatusCodeRangesItem] # Expected HTTP codes
181
182
class MonitorConfigCustomHeadersItem:
183
"""Custom header for health check requests."""
184
name: str # Header name (e.g., "Host", "Authorization")
185
value: str # Header value
186
187
class MonitorConfigExpectedStatusCodeRangesItem:
188
"""Expected HTTP status code range for health checks."""
189
min: int # Minimum status code (100-999)
190
max: int # Maximum status code (100-999)
191
```
192
193
### Health Monitoring Examples
194
195
```python
196
# Configure advanced health monitoring
197
monitor_config = MonitorConfig(
198
protocol="HTTPS",
199
port=443,
200
path="/api/health",
201
interval_in_seconds=30, # Check every 30 seconds
202
timeout_in_seconds=10, # 10 second timeout
203
tolerated_number_of_failures=3, # Allow 3 failures before marking unhealthy
204
custom_headers=[
205
{"name": "Host", "value": "api.example.com"},
206
{"name": "Authorization", "value": "Bearer health-check-token"},
207
{"name": "User-Agent", "value": "TrafficManager-HealthCheck/1.0"}
208
],
209
expected_status_code_ranges=[
210
{"min": 200, "max": 299}, # 2xx success codes
211
{"min": 401, "max": 401} # Allow 401 (auth required) as healthy
212
]
213
)
214
215
# Apply to profile
216
profile.monitor_config = monitor_config
217
```
218
219
## Monitoring Status Types
220
221
```python { .api }
222
class ProfileMonitorStatus(str, Enum):
223
"""Profile-level health monitoring status."""
224
CHECKING_ENDPOINTS = "CheckingEndpoints" # Health checks in progress
225
ONLINE = "Online" # All endpoints healthy
226
DEGRADED = "Degraded" # Some endpoints unhealthy
227
DISABLED = "Disabled" # Monitoring disabled
228
INACTIVE = "Inactive" # Profile inactive
229
230
class MonitorProtocol(str, Enum):
231
"""Health check protocols."""
232
HTTP = "HTTP" # HTTP health checks
233
HTTPS = "HTTPS" # HTTPS health checks
234
TCP = "TCP" # TCP port connectivity checks
235
```
236
237
## Analytics Best Practices
238
239
### Heat Map Analysis
240
241
1. **Regular Monitoring**: Check heat maps regularly to understand traffic patterns and user distribution
242
2. **Geographic Optimization**: Use heat map data to optimize endpoint placement and geographic routing
243
3. **Performance Tuning**: Identify high-latency regions and add endpoints to improve performance
244
4. **Capacity Planning**: Use query volume data for scaling decisions
245
246
### Real User Metrics Integration
247
248
1. **Client Integration**: Add RUM JavaScript to all pages that use Traffic Manager
249
2. **Privacy Compliance**: RUM data is automatically anonymized but review privacy policies
250
3. **Performance Insights**: Use RUM data to validate Traffic Manager routing decisions
251
4. **Optimization**: Combine RUM data with heat maps for comprehensive performance analysis
252
253
### Health Monitoring Optimization
254
255
1. **Appropriate Intervals**: Use 30-second intervals for most scenarios, 10-second for critical applications
256
2. **Failure Tolerance**: Set failure tolerance based on application criticality and expected variability
257
3. **Custom Headers**: Use custom headers for application-specific health checks
258
4. **Status Code Ranges**: Configure expected status codes to match application behavior