or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

device-operations.mdevent-hub-consumer-groups.mdfailover-operations.mdindex.mdmessage-routing.mdmonitoring-quotas.mdprivate-networking.mdresource-management.mdsecurity-management.mdutility-operations.md

monitoring-quotas.mddocs/

0

# Monitoring & Quotas

1

2

Comprehensive monitoring capabilities including IoT Hub quota management, usage metrics, endpoint health monitoring, and subscription-level quota tracking for capacity planning and operational oversight of IoT Hub deployments at scale.

3

4

## Capabilities

5

6

### IoT Hub Quota Metrics

7

8

Monitor IoT Hub resource usage against configured limits including message quotas, device limits, and feature-specific usage for capacity planning and threshold management.

9

10

```python { .api }

11

def get_quota_metrics(resource_group_name: str, resource_name: str, **kwargs) -> ItemPaged[IotHubQuotaMetricInfo]:

12

"""

13

Get quota usage metrics for the IoT hub including message limits and device counts.

14

15

Args:

16

resource_group_name: Name of the resource group

17

resource_name: Name of the IoT hub resource

18

19

Returns:

20

ItemPaged[IotHubQuotaMetricInfo]: Paginated quota metrics with current usage and limits

21

"""

22

```

23

24

### SKU and Capacity Information

25

26

Retrieve available pricing tiers and capacity options for IoT Hub scaling and cost optimization decisions.

27

28

```python { .api }

29

def get_valid_skus(resource_group_name: str, resource_name: str, **kwargs) -> ItemPaged[IotHubSkuDescription]:

30

"""

31

Get valid SKU options available for the IoT hub for scaling operations.

32

33

Args:

34

resource_group_name: Name of the resource group

35

resource_name: Name of the IoT hub resource

36

37

Returns:

38

ItemPaged[IotHubSkuDescription]: Available SKU tiers with capacity and pricing information

39

"""

40

```

41

42

### Endpoint Health Monitoring

43

44

Monitor the health status of routing endpoints including Event Hubs, Service Bus, and Storage endpoints to ensure reliable message delivery and identify connectivity issues.

45

46

```python { .api }

47

def get_endpoint_health(resource_group_name: str, iot_hub_name: str, **kwargs) -> Iterable[EndpointHealthData]:

48

"""

49

Get health status of all routing endpoints configured for the IoT hub.

50

51

Args:

52

resource_group_name: Name of the resource group

53

iot_hub_name: Name of the IoT hub resource

54

55

Returns:

56

Iterable[EndpointHealthData]: Health status for each endpoint with error details and timestamps

57

"""

58

```

59

60

### Subscription Quota Management

61

62

Monitor subscription-level quotas and limits for IoT Hub services to understand regional capacity constraints and plan multi-hub deployments.

63

64

```python { .api }

65

def get_subscription_quota() -> UserSubscriptionQuotaListResult:

66

"""

67

Get subscription quota information for IoT Hub services.

68

69

Returns:

70

UserSubscriptionQuotaListResult: Subscription-level quotas and usage limits for IoT Hub deployment

71

"""

72

```

73

74

## Usage Examples

75

76

### Monitoring IoT Hub quotas and usage

77

78

```python

79

from azure.identity import DefaultAzureCredential

80

from azure.mgmt.iothub import IotHubClient

81

82

# Initialize client

83

credential = DefaultAzureCredential()

84

client = IotHubClient(credential, "subscription-id")

85

86

resource_group = "myResourceGroup"

87

hub_name = "myIoTHub"

88

89

# Get comprehensive quota metrics

90

print(f"IoT Hub Quota Metrics for {hub_name}:")

91

print("=" * 50)

92

93

quota_metrics = client.iot_hub_resource.get_quota_metrics(resource_group, hub_name)

94

for metric in quota_metrics:

95

usage_percentage = (metric.current_value / metric.max_value * 100) if metric.max_value > 0 else 0

96

97

print(f"Metric: {metric.name}")

98

print(f" Current Usage: {metric.current_value:,}")

99

print(f" Maximum Limit: {metric.max_value:,}")

100

print(f" Usage Percentage: {usage_percentage:.1f}%")

101

102

# Alert on high usage

103

if usage_percentage > 80:

104

print(f" ⚠️ HIGH USAGE WARNING: {usage_percentage:.1f}%")

105

elif usage_percentage > 90:

106

print(f" 🚨 CRITICAL USAGE ALERT: {usage_percentage:.1f}%")

107

108

print()

109

110

# Check subscription-level quotas

111

print("Subscription Quota Information:")

112

print("=" * 40)

113

try:

114

subscription_quotas = client.resource_provider_common.get_subscription_quota()

115

for quota in subscription_quotas.value:

116

print(f"Quota Type: {quota.name}")

117

print(f" Limit: {quota.limit}")

118

print(f" Current Usage: {quota.current_value}")

119

if quota.unit:

120

print(f" Unit: {quota.unit}")

121

print()

122

except Exception as e:

123

print(f"Could not retrieve subscription quotas: {e}")

124

```

125

126

### SKU analysis and scaling recommendations

127

128

```python

129

def analyze_sku_options(resource_group: str, hub_name: str):

130

"""Analyze available SKUs and provide scaling recommendations."""

131

132

print(f"SKU Analysis for {hub_name}:")

133

print("=" * 40)

134

135

# Get current hub configuration

136

current_hub = client.iot_hub_resource.get(resource_group, hub_name)

137

current_sku = current_hub.sku

138

139

print(f"Current SKU: {current_sku.name}")

140

print(f"Current Capacity: {current_sku.capacity} units")

141

print(f"Current Tier: {current_sku.tier}")

142

print()

143

144

# Get available SKU options

145

print("Available SKU Options:")

146

valid_skus = client.iot_hub_resource.get_valid_skus(resource_group, hub_name)

147

148

sku_recommendations = []

149

for sku_info in valid_skus:

150

sku = sku_info.sku

151

capacity = sku_info.capacity

152

153

recommendation = {

154

"name": sku.name,

155

"tier": sku.tier,

156

"capacity": capacity.minimum if capacity else "N/A",

157

"max_capacity": capacity.maximum if capacity else "N/A",

158

"scale_type": capacity.scale_type if capacity else "N/A"

159

}

160

sku_recommendations.append(recommendation)

161

162

print(f" - {sku.name} ({sku.tier})")

163

if capacity:

164

print(f" Capacity Range: {capacity.minimum} - {capacity.maximum}")

165

print(f" Scale Type: {capacity.scale_type}")

166

print()

167

168

return sku_recommendations

169

170

# Analyze SKU options

171

sku_analysis = analyze_sku_options(resource_group, hub_name)

172

173

# Provide scaling recommendations based on usage

174

quota_metrics = list(client.iot_hub_resource.get_quota_metrics(resource_group, hub_name))

175

high_usage_metrics = [m for m in quota_metrics if (m.current_value / m.max_value * 100) > 75]

176

177

if high_usage_metrics:

178

print("Scaling Recommendations:")

179

print("=" * 30)

180

for metric in high_usage_metrics:

181

usage_pct = m.current_value / m.max_value * 100

182

print(f"⚠️ {metric.name}: {usage_pct:.1f}% usage")

183

184

print("\nConsider upgrading to a higher SKU tier or increasing capacity units")

185

else:

186

print("✅ Current capacity appears sufficient based on usage metrics")

187

```

188

189

### Comprehensive endpoint health monitoring

190

191

```python

192

def monitor_endpoint_health(resource_group: str, hub_name: str):

193

"""Monitor health of all routing endpoints with detailed reporting."""

194

195

print(f"Endpoint Health Report for {hub_name}:")

196

print("=" * 50)

197

198

try:

199

endpoint_health = client.iot_hub_resource.get_endpoint_health(resource_group, hub_name)

200

201

healthy_endpoints = []

202

unhealthy_endpoints = []

203

204

for endpoint in endpoint_health:

205

endpoint_info = {

206

"id": endpoint.endpoint_id,

207

"status": endpoint.health_status,

208

"last_error": endpoint.last_known_error,

209

"last_error_time": endpoint.last_known_error_time,

210

"last_success": endpoint.last_successful_send_attempt_time,

211

"last_attempt": endpoint.last_send_attempt_time

212

}

213

214

if endpoint.health_status == "Healthy":

215

healthy_endpoints.append(endpoint_info)

216

else:

217

unhealthy_endpoints.append(endpoint_info)

218

219

print(f"Endpoint: {endpoint.endpoint_id}")

220

print(f" Status: {endpoint.health_status}")

221

222

if endpoint.last_known_error:

223

print(f" Last Error: {endpoint.last_known_error}")

224

if endpoint.last_known_error_time:

225

print(f" Error Time: {endpoint.last_known_error_time}")

226

227

if endpoint.last_successful_send_attempt_time:

228

print(f" Last Success: {endpoint.last_successful_send_attempt_time}")

229

230

if endpoint.last_send_attempt_time:

231

print(f" Last Attempt: {endpoint.last_send_attempt_time}")

232

233

print()

234

235

# Summary

236

total_endpoints = len(healthy_endpoints) + len(unhealthy_endpoints)

237

print(f"Health Summary:")

238

print(f" Total Endpoints: {total_endpoints}")

239

print(f" Healthy: {len(healthy_endpoints)}")

240

print(f" Unhealthy: {len(unhealthy_endpoints)}")

241

242

if unhealthy_endpoints:

243

print(f"\n🚨 Unhealthy Endpoints Requiring Attention:")

244

for endpoint in unhealthy_endpoints:

245

print(f" - {endpoint['id']}: {endpoint['status']}")

246

if endpoint['last_error']:

247

print(f" Error: {endpoint['last_error']}")

248

else:

249

print(f"\n✅ All endpoints are healthy")

250

251

return {"healthy": healthy_endpoints, "unhealthy": unhealthy_endpoints}

252

253

except Exception as e:

254

print(f"Failed to retrieve endpoint health: {e}")

255

return None

256

257

# Monitor endpoint health

258

health_report = monitor_endpoint_health(resource_group, hub_name)

259

```

260

261

### Automated monitoring and alerting setup

262

263

```python

264

import json

265

from datetime import datetime, timedelta

266

267

def create_monitoring_report(resource_group: str, hub_name: str):

268

"""Create comprehensive monitoring report with alerts and recommendations."""

269

270

report = {

271

"hub_name": hub_name,

272

"timestamp": datetime.utcnow().isoformat(),

273

"quota_metrics": {},

274

"endpoint_health": {},

275

"alerts": [],

276

"recommendations": []

277

}

278

279

# Collect quota metrics

280

quota_metrics = list(client.iot_hub_resource.get_quota_metrics(resource_group, hub_name))

281

for metric in quota_metrics:

282

usage_pct = (metric.current_value / metric.max_value * 100) if metric.max_value > 0 else 0

283

284

report["quota_metrics"][metric.name] = {

285

"current": metric.current_value,

286

"maximum": metric.max_value,

287

"usage_percentage": usage_pct

288

}

289

290

# Generate alerts

291

if usage_pct > 90:

292

report["alerts"].append({

293

"severity": "critical",

294

"type": "quota_usage",

295

"metric": metric.name,

296

"message": f"Critical usage: {usage_pct:.1f}%"

297

})

298

elif usage_pct > 80:

299

report["alerts"].append({

300

"severity": "warning",

301

"type": "quota_usage",

302

"metric": metric.name,

303

"message": f"High usage: {usage_pct:.1f}%"

304

})

305

306

# Collect endpoint health

307

try:

308

endpoint_health = list(client.iot_hub_resource.get_endpoint_health(resource_group, hub_name))

309

for endpoint in endpoint_health:

310

report["endpoint_health"][endpoint.endpoint_id] = {

311

"status": endpoint.health_status,

312

"last_error": endpoint.last_known_error,

313

"last_success": endpoint.last_successful_send_attempt_time.isoformat() if endpoint.last_successful_send_attempt_time else None

314

}

315

316

if endpoint.health_status != "Healthy":

317

report["alerts"].append({

318

"severity": "warning",

319

"type": "endpoint_health",

320

"endpoint": endpoint.endpoint_id,

321

"message": f"Endpoint unhealthy: {endpoint.health_status}"

322

})

323

except Exception as e:

324

report["endpoint_health_error"] = str(e)

325

326

# Generate recommendations

327

high_usage_metrics = [name for name, data in report["quota_metrics"].items()

328

if data["usage_percentage"] > 75]

329

if high_usage_metrics:

330

report["recommendations"].append({

331

"type": "scaling",

332

"message": "Consider upgrading SKU or increasing capacity",

333

"affected_metrics": high_usage_metrics

334

})

335

336

unhealthy_endpoints = [endpoint for endpoint, data in report["endpoint_health"].items()

337

if data["status"] != "Healthy"]

338

if unhealthy_endpoints:

339

report["recommendations"].append({

340

"type": "endpoint_maintenance",

341

"message": "Investigate and repair unhealthy endpoints",

342

"affected_endpoints": unhealthy_endpoints

343

})

344

345

return report

346

347

# Generate monitoring report

348

monitoring_report = create_monitoring_report(resource_group, hub_name)

349

350

# Save report to file

351

with open(f"iot_hub_monitoring_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json", "w") as f:

352

json.dump(monitoring_report, f, indent=2, default=str)

353

354

# Print summary

355

print("Monitoring Report Summary:")

356

print(f" Alerts: {len(monitoring_report['alerts'])}")

357

print(f" Recommendations: {len(monitoring_report['recommendations'])}")

358

359

if monitoring_report['alerts']:

360

print("\nActive Alerts:")

361

for alert in monitoring_report['alerts']:

362

print(f" {alert['severity'].upper()}: {alert['message']}")

363

```

364

365

## Types

366

367

### IotHubQuotaMetricInfo

368

Quota usage information including current consumption and maximum limits for capacity planning and threshold monitoring.

369

370

```python

371

class IotHubQuotaMetricInfo:

372

"""IoT Hub quota and usage metrics."""

373

name: str # Metric name (e.g., "TotalMessages", "TotalDeviceCount")

374

current_value: int # Current usage value

375

max_value: int # Maximum allowed value for this metric

376

```

377

378

### IotHubSkuDescription

379

Available SKU options with capacity constraints and scaling capabilities for IoT Hub tier management.

380

381

```python

382

class IotHubSkuDescription:

383

"""IoT Hub SKU availability and capacity information."""

384

resource_type: str # Resource type identifier

385

sku: IotHubSkuInfo # SKU details including name and tier

386

capacity: IotHubCapacity # Capacity constraints and scaling options

387

```

388

389

### IotHubCapacity

390

Capacity configuration including minimum, maximum, and scaling type constraints for hub sizing decisions.

391

392

```python

393

class IotHubCapacity:

394

"""IoT Hub capacity constraints."""

395

minimum: int # Minimum capacity units

396

maximum: int # Maximum capacity units

397

default: int # Default capacity units

398

scale_type: IotHubScaleType # Scaling type: Manual, Automatic, or None

399

```

400

401

### EndpointHealthData

402

Health monitoring information for routing endpoints including status, error details, and timing information.

403

404

```python

405

class EndpointHealthData:

406

"""Routing endpoint health status and monitoring data."""

407

endpoint_id: str # Endpoint identifier

408

health_status: EndpointHealthStatus # Health status: Healthy, Unhealthy, Degraded, Dead, Unknown

409

last_known_error: str # Last error message if any

410

last_known_error_time: datetime # Timestamp of last error

411

last_successful_send_attempt_time: datetime # Timestamp of last successful message send

412

last_send_attempt_time: datetime # Timestamp of last send attempt

413

```

414

415

### UserSubscriptionQuotaListResult

416

Subscription-level quota information for IoT Hub service limits and regional capacity constraints.

417

418

```python

419

class UserSubscriptionQuotaListResult:

420

"""Subscription quota information."""

421

value: List[UserSubscriptionQuota] # List of subscription-level quota entries

422

next_link: str # Link to next page if paginated

423

```

424

425

### UserSubscriptionQuota

426

Individual subscription quota entry with limit and usage information for service capacity management.

427

428

```python

429

class UserSubscriptionQuota:

430

"""Individual subscription quota details."""

431

name: str # Quota name and identifier

432

limit: int # Maximum allowed value

433

current_value: int # Current usage against quota

434

unit: str # Unit of measurement

435

```