or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

action-groups.mdactivity-logs.mdautoscaling.mddata-collection.mdindex.mdlog-analytics.mdmetric-alerts.mdmetrics.mdworkspaces.md

index.mddocs/

0

# Azure Monitor Management Client

1

2

Microsoft Azure Monitor Client Library for Python provides comprehensive management capabilities for Azure Monitor, Microsoft's monitoring and observability service. This library offers a complete interface to manage and interact with Azure monitoring resources including action groups, activity log alerts, autoscale settings, metric alerts, data collection rules and endpoints, scheduled query rules, and Azure Monitor workspaces.

3

4

## Package Information

5

6

- **Package Name**: azure-mgmt-monitor

7

- **Language**: Python

8

- **Installation**: `pip install azure-mgmt-monitor`

9

- **Version**: 7.0.0

10

11

## Core Imports

12

13

```python

14

from azure.mgmt.monitor import MonitorManagementClient

15

```

16

17

For asynchronous operations:

18

19

```python

20

from azure.mgmt.monitor.aio import MonitorManagementClient

21

```

22

23

## Basic Usage

24

25

```python

26

from azure.identity import DefaultAzureCredential

27

from azure.mgmt.monitor import MonitorManagementClient

28

29

# Initialize the client

30

credential = DefaultAzureCredential()

31

subscription_id = "your-subscription-id"

32

client = MonitorManagementClient(credential, subscription_id)

33

34

# List all action groups in a resource group

35

resource_group_name = "your-resource-group"

36

action_groups = list(client.action_groups.list_by_resource_group(resource_group_name))

37

38

# Get metrics for a resource

39

resource_uri = "/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Compute/virtualMachines/{}".format(

40

subscription_id, resource_group_name, "vm-name"

41

)

42

metrics = client.metrics.list(resource_uri, metricnames="Percentage CPU")

43

44

# Create a metric alert

45

from azure.mgmt.monitor.models import MetricAlertResource, MetricAlertAction

46

alert_rule = MetricAlertResource(

47

location="global",

48

description="High CPU usage alert",

49

enabled=True,

50

scopes=[resource_uri],

51

evaluation_frequency="PT1M",

52

window_size="PT5M",

53

criteria={

54

"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",

55

"allOf": [{

56

"name": "High CPU",

57

"metricName": "Percentage CPU",

58

"operator": "GreaterThan",

59

"threshold": 80,

60

"timeAggregation": "Average"

61

}]

62

}

63

)

64

client.metric_alerts.create_or_update(resource_group_name, "high-cpu-alert", alert_rule)

65

```

66

67

## Architecture

68

69

The Azure Monitor Management Client is organized around operation groups that correspond to different Azure Monitor services:

70

71

- **MonitorManagementClient**: Main client class providing access to all operations

72

- **Operations Groups**: Specialized classes for different Azure Monitor services (action groups, alerts, metrics, etc.)

73

- **Models**: Data structures representing Azure Monitor resources and configurations

74

- **Authentication**: Integration with Azure Identity for secure access

75

76

The client supports both synchronous and asynchronous operations through separate modules.

77

78

## Capabilities

79

80

### Action Groups and Notifications

81

82

Manages action groups for sending notifications and triggering automated actions when alerts are fired. Supports email, SMS, webhooks, Azure Functions, Logic Apps, and other notification channels.

83

84

```python { .api }

85

# Core action group operations

86

client.action_groups.create_or_update(resource_group_name: str, action_group_name: str, action_group: ActionGroupResource) -> ActionGroupResource

87

client.action_groups.get(resource_group_name: str, action_group_name: str) -> ActionGroupResource

88

client.action_groups.delete(resource_group_name: str, action_group_name: str) -> None

89

client.action_groups.list_by_resource_group(resource_group_name: str) -> ItemPaged[ActionGroupResource]

90

```

91

92

[Action Groups and Notifications](./action-groups.md)

93

94

### Activity Log Monitoring

95

96

Provides access to Azure activity logs, management of activity log alert rules, classic alert rule incidents, and event categories for monitoring subscription-level events and administrative operations.

97

98

```python { .api }

99

# Activity log operations

100

client.activity_logs.list(filter: str, select: Optional[str] = None) -> ItemPaged[EventData]

101

client.activity_log_alerts.create_or_update(resource_group_name: str, activity_log_alert_name: str, activity_log_alert_rule: ActivityLogAlertResource) -> ActivityLogAlertResource

102

client.tenant_activity_logs.list(filter: Optional[str] = None, select: Optional[str] = None) -> ItemPaged[EventData]

103

client.event_categories.list() -> ItemPaged[LocalizableString]

104

client.alert_rule_incidents.get(resource_group_name: str, rule_name: str, incident_name: str) -> Incident

105

```

106

107

[Activity Log Monitoring](./activity-logs.md)

108

109

### Metric Alerts and Monitoring

110

111

Manages metric alert rules for monitoring resource metrics and triggering actions based on metric thresholds, with support for dynamic thresholds and multi-resource alerts.

112

113

```python { .api }

114

# Metric alert operations

115

client.metric_alerts.create_or_update(resource_group_name: str, rule_name: str, parameters: MetricAlertResource) -> MetricAlertResource

116

client.metric_alerts.get(resource_group_name: str, rule_name: str) -> MetricAlertResource

117

client.metric_alerts_status.list(resource_group_name: str, rule_name: str) -> MetricAlertStatusCollection

118

```

119

120

[Metric Alerts and Monitoring](./metric-alerts.md)

121

122

### Metrics and Baselines

123

124

Retrieves metric values, definitions, and baselines for Azure resources, supporting filtering, aggregation, and subscription-level metric queries.

125

126

```python { .api }

127

# Metrics operations

128

client.metrics.list(resource_uri: str, timespan: Optional[str] = None, interval: Optional[str] = None, metricnames: Optional[str] = None, aggregation: Optional[str] = None) -> Response

129

client.metric_definitions.list(resource_uri: str, metricnamespace: Optional[str] = None) -> ItemPaged[MetricDefinition]

130

client.baselines.list(resource_uri: str, metricnames: Optional[str] = None, metricnamespace: Optional[str] = None) -> ItemPaged[SingleMetricBaseline]

131

```

132

133

[Metrics and Baselines](./metrics.md)

134

135

### Autoscaling

136

137

Manages autoscale settings for automatically scaling resources based on metrics, schedules, and predictive scaling policies.

138

139

```python { .api }

140

# Autoscale operations

141

client.autoscale_settings.create_or_update(resource_group_name: str, autoscale_setting_name: str, parameters: AutoscaleSettingResource) -> AutoscaleSettingResource

142

client.predictive_metric.get(resource_group_name: str, autoscale_setting_name: str, timespan: str, interval: str, metricnamespace: str, metricname: str, aggregation: str) -> PredictiveResponse

143

```

144

145

[Autoscaling](./autoscaling.md)

146

147

### Data Collection

148

149

Manages data collection rules, endpoints, and associations for Azure Monitor Agent, enabling custom log and metric collection from virtual machines and other resources.

150

151

```python { .api }

152

# Data collection operations

153

client.data_collection_rules.create(resource_group_name: str, data_collection_rule_name: str, body: Optional[DataCollectionRuleResource] = None) -> DataCollectionRuleResource

154

client.data_collection_endpoints.create(resource_group_name: str, data_collection_endpoint_name: str, body: Optional[DataCollectionEndpointResource] = None) -> DataCollectionEndpointResource

155

client.data_collection_rule_associations.create(resource_uri: str, association_name: str, body: Optional[DataCollectionRuleAssociationProxyOnlyResource] = None) -> DataCollectionRuleAssociationProxyOnlyResource

156

```

157

158

[Data Collection](./data-collection.md)

159

160

### Log Analytics and Query Rules

161

162

Manages scheduled query rules for log-based alerting and log profiles for activity log export (deprecated feature).

163

164

```python { .api }

165

# Query rules operations

166

client.scheduled_query_rules.create_or_update(resource_group_name: str, rule_name: str, parameters: ScheduledQueryRuleResource) -> ScheduledQueryRuleResource

167

client.log_profiles.create_or_update(log_profile_name: str, parameters: LogProfileResource) -> LogProfileResource

168

```

169

170

[Log Analytics and Query Rules](./log-analytics.md)

171

172

### Azure Monitor Workspaces

173

174

Manages Azure Monitor Workspaces for Prometheus metrics collection and storage, supporting workspace creation, configuration, and lifecycle management.

175

176

```python { .api }

177

# Workspace operations

178

client.azure_monitor_workspaces.create(resource_group_name: str, azure_monitor_workspace_name: str, azure_monitor_workspace_properties: AzureMonitorWorkspaceResource) -> AzureMonitorWorkspaceResource

179

client.azure_monitor_workspaces.get(resource_group_name: str, azure_monitor_workspace_name: str) -> AzureMonitorWorkspaceResource

180

```

181

182

[Azure Monitor Workspaces](./workspaces.md)

183

184

## Common Types

185

186

```python { .api }

187

class MonitorManagementClient:

188

"""Main client class for Azure Monitor management operations."""

189

def __init__(self, credential: TokenCredential, subscription_id: str, base_url: Optional[str] = None, **kwargs: Any) -> None: ...

190

def close(self) -> None: ...

191

def __enter__(self) -> Self: ...

192

def __exit__(self, *exc_details: Any) -> None: ...

193

194

# Core resource types

195

class ActionGroupResource:

196

"""Action group resource definition."""

197

location: str

198

group_short_name: str

199

enabled: bool

200

email_receivers: Optional[List[EmailReceiver]]

201

sms_receivers: Optional[List[SmsReceiver]]

202

webhook_receivers: Optional[List[WebhookReceiver]]

203

# ... other receiver types

204

205

class MetricAlertResource:

206

"""Metric alert rule resource."""

207

location: str

208

description: Optional[str]

209

enabled: bool

210

scopes: List[str]

211

evaluation_frequency: str

212

window_size: str

213

criteria: MetricAlertCriteria

214

actions: Optional[List[MetricAlertAction]]

215

216

class AutoscaleSettingResource:

217

"""Autoscale setting resource."""

218

location: str

219

profiles: List[AutoscaleProfile]

220

enabled: Optional[bool]

221

target_resource_uri: Optional[str]

222

target_resource_location: Optional[str]

223

224

class DataCollectionRuleResource:

225

"""Data collection rule resource."""

226

location: str

227

data_sources: Optional[DataCollectionRuleDataSources]

228

destinations: Optional[DataCollectionRuleDestinations]

229

data_flows: Optional[List[DataFlow]]

230

231

class Incident:

232

"""Alert rule incident representing activation status."""

233

name: Optional[str]

234

rule_name: Optional[str]

235

is_active: Optional[bool]

236

activated_time: Optional[datetime]

237

resolved_time: Optional[datetime]

238

239

class LocalizableString:

240

"""Localizable string value."""

241

value: str

242

localized_value: Optional[str]

243

244

# Authentication requirement

245

TokenCredential = TypeVar('TokenCredential') # From azure.core.credentials

246

```