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

workspaces.mddocs/

0

# Azure Monitor Workspaces

1

2

Azure Monitor Workspaces for Prometheus metrics collection and storage, providing managed Prometheus-compatible endpoints for container and Kubernetes monitoring with long-term retention and integration with Azure Monitor.

3

4

## Capabilities

5

6

### Workspace Management

7

8

Create, update, and manage Azure Monitor Workspaces for Prometheus metrics storage and querying.

9

10

```python { .api }

11

def create(resource_group_name: str, azure_monitor_workspace_name: str, azure_monitor_workspace_properties: AzureMonitorWorkspaceResource, **kwargs: Any) -> AzureMonitorWorkspaceResource:

12

"""

13

Create an Azure Monitor Workspace.

14

15

Parameters:

16

- resource_group_name: str - Name of the resource group

17

- azure_monitor_workspace_name: str - Name of the Azure Monitor workspace

18

- azure_monitor_workspace_properties: AzureMonitorWorkspaceResource - Workspace configuration

19

20

Returns:

21

AzureMonitorWorkspaceResource - The created workspace

22

"""

23

24

def get(resource_group_name: str, azure_monitor_workspace_name: str, **kwargs: Any) -> AzureMonitorWorkspaceResource:

25

"""

26

Returns an Azure Monitor Workspace.

27

28

Parameters:

29

- resource_group_name: str - Name of the resource group

30

- azure_monitor_workspace_name: str - Name of the Azure Monitor workspace

31

32

Returns:

33

AzureMonitorWorkspaceResource - The workspace details

34

"""

35

36

def update(resource_group_name: str, azure_monitor_workspace_name: str, azure_monitor_workspace_properties: AzureMonitorWorkspaceResourceForUpdate, **kwargs: Any) -> AzureMonitorWorkspaceResource:

37

"""

38

Updates part of an Azure Monitor Workspace.

39

40

Parameters:

41

- resource_group_name: str - Name of the resource group

42

- azure_monitor_workspace_name: str - Name of the Azure Monitor workspace

43

- azure_monitor_workspace_properties: AzureMonitorWorkspaceResourceForUpdate - Properties to update

44

45

Returns:

46

AzureMonitorWorkspaceResource - The updated workspace

47

"""

48

49

def begin_delete(resource_group_name: str, azure_monitor_workspace_name: str, **kwargs: Any) -> LROPoller[None]:

50

"""

51

Delete an Azure Monitor Workspace.

52

53

Parameters:

54

- resource_group_name: str - Name of the resource group

55

- azure_monitor_workspace_name: str - Name of the Azure Monitor workspace

56

57

Returns:

58

LROPoller[None] - Long-running operation poller for deletion

59

"""

60

```

61

62

### Workspace Listing

63

64

List Azure Monitor Workspaces within subscriptions and resource groups.

65

66

```python { .api }

67

def list_by_resource_group(resource_group_name: str, **kwargs: Any) -> ItemPaged[AzureMonitorWorkspaceResource]:

68

"""

69

Lists all workspaces in the specified resource group.

70

71

Parameters:

72

- resource_group_name: str - Name of the resource group

73

74

Returns:

75

ItemPaged[AzureMonitorWorkspaceResource] - List of workspaces

76

"""

77

78

def list_by_subscription(**kwargs: Any) -> ItemPaged[AzureMonitorWorkspaceResource]:

79

"""

80

Lists all workspaces in the specified subscription.

81

82

Returns:

83

ItemPaged[AzureMonitorWorkspaceResource] - List of workspaces

84

"""

85

```

86

87

## Usage Examples

88

89

### Creating an Azure Monitor Workspace

90

91

```python

92

from azure.mgmt.monitor.models import (

93

AzureMonitorWorkspaceResource, AzureMonitorWorkspaceResourceProperties,

94

AzureMonitorWorkspaceDefaultIngestionSettings, AzureMonitorWorkspaceMetrics

95

)

96

97

# Define workspace properties

98

workspace_properties = AzureMonitorWorkspaceResourceProperties(

99

account_id="workspace-account-id",

100

default_ingestion_settings=AzureMonitorWorkspaceDefaultIngestionSettings(

101

data_collection_endpoint_resource_id=f"/subscriptions/{subscription_id}/resourceGroups/monitoring-rg/providers/Microsoft.Insights/dataCollectionEndpoints/prometheus-dce",

102

data_collection_rule_resource_id=f"/subscriptions/{subscription_id}/resourceGroups/monitoring-rg/providers/Microsoft.Insights/dataCollectionRules/prometheus-dcr"

103

),

104

metrics=AzureMonitorWorkspaceMetrics(

105

prometheus_query_endpoint="https://my-workspace.eastus.prometheus.monitor.azure.com",

106

internal_id="internal-workspace-id"

107

)

108

)

109

110

# Create Azure Monitor Workspace

111

workspace = AzureMonitorWorkspaceResource(

112

location="East US",

113

properties=workspace_properties

114

)

115

116

result = client.azure_monitor_workspaces.create(

117

resource_group_name="monitoring-rg",

118

azure_monitor_workspace_name="prometheus-workspace",

119

azure_monitor_workspace_properties=workspace

120

)

121

122

print(f"Workspace created: {result.id}")

123

print(f"Query endpoint: {result.properties.metrics.prometheus_query_endpoint}")

124

```

125

126

### Configuring Workspace for AKS Integration

127

128

```python

129

# Create workspace specifically for AKS Prometheus metrics

130

aks_workspace = AzureMonitorWorkspaceResource(

131

location="East US",

132

properties=AzureMonitorWorkspaceResourceProperties(

133

account_id=f"aks-prometheus-{subscription_id}",

134

default_ingestion_settings=AzureMonitorWorkspaceDefaultIngestionSettings(

135

data_collection_endpoint_resource_id=f"/subscriptions/{subscription_id}/resourceGroups/aks-rg/providers/Microsoft.Insights/dataCollectionEndpoints/aks-prometheus-dce",

136

data_collection_rule_resource_id=f"/subscriptions/{subscription_id}/resourceGroups/aks-rg/providers/Microsoft.Insights/dataCollectionRules/aks-prometheus-dcr"

137

)

138

)

139

)

140

141

aks_result = client.azure_monitor_workspaces.create(

142

resource_group_name="aks-rg",

143

azure_monitor_workspace_name="aks-prometheus-workspace",

144

azure_monitor_workspace_properties=aks_workspace

145

)

146

147

# The workspace can now be referenced in AKS addon configuration

148

print(f"AKS Workspace ID: {aks_result.id}")

149

print(f"Use this ID in AKS monitoring addon configuration")

150

```

151

152

### Updating Workspace Properties

153

154

```python

155

from azure.mgmt.monitor.models import AzureMonitorWorkspaceResourceForUpdate

156

157

# Update workspace tags and properties

158

workspace_update = AzureMonitorWorkspaceResourceForUpdate(

159

tags={

160

"Environment": "Production",

161

"Team": "Platform",

162

"CostCenter": "Engineering"

163

}

164

)

165

166

updated_workspace = client.azure_monitor_workspaces.update(

167

resource_group_name="monitoring-rg",

168

azure_monitor_workspace_name="prometheus-workspace",

169

azure_monitor_workspace_properties=workspace_update

170

)

171

172

print(f"Workspace updated: {updated_workspace.tags}")

173

```

174

175

### Listing and Monitoring Workspaces

176

177

```python

178

# List all workspaces in subscription

179

all_workspaces = client.azure_monitor_workspaces.list_by_subscription()

180

181

print("Azure Monitor Workspaces:")

182

for workspace in all_workspaces:

183

print(f" Name: {workspace.name}")

184

print(f" Location: {workspace.location}")

185

print(f" Resource Group: {workspace.id.split('/')[4]}")

186

if workspace.properties and workspace.properties.metrics:

187

print(f" Query Endpoint: {workspace.properties.metrics.prometheus_query_endpoint}")

188

print(f" Provisioning State: {workspace.properties.provisioning_state}")

189

print()

190

191

# List workspaces in specific resource group

192

rg_workspaces = client.azure_monitor_workspaces.list_by_resource_group("monitoring-rg")

193

print(f"Workspaces in monitoring-rg: {len(list(rg_workspaces))}")

194

```

195

196

### Workspace Deletion

197

198

```python

199

# Delete workspace (long-running operation)

200

delete_operation = client.azure_monitor_workspaces.begin_delete(

201

resource_group_name="monitoring-rg",

202

azure_monitor_workspace_name="old-prometheus-workspace"

203

)

204

205

print("Deleting workspace...")

206

delete_operation.wait() # Wait for completion

207

print("Workspace deleted successfully")

208

```

209

210

## Integration Examples

211

212

### AKS Cluster Configuration

213

214

```python

215

# Example of how the workspace would be used in AKS configuration

216

# (This would typically be done through ARM templates or Azure CLI)

217

218

workspace_resource_id = result.id

219

220

aks_addon_config = {

221

"monitoring": {

222

"enabled": True,

223

"config": {

224

"omsagent": {

225

"enabled": True,

226

"config": {

227

"logAnalyticsWorkspaceResourceID": f"/subscriptions/{subscription_id}/resourceGroups/monitoring-rg/providers/Microsoft.OperationalInsights/workspaces/aks-logs"

228

}

229

},

230

"azureMonitorWorkspaceResourceId": workspace_resource_id

231

}

232

}

233

}

234

235

print(f"AKS addon configuration:")

236

print(f"Workspace ID: {workspace_resource_id}")

237

```

238

239

### Grafana Integration

240

241

```python

242

# The workspace query endpoint can be used with Grafana

243

query_endpoint = result.properties.metrics.prometheus_query_endpoint

244

245

grafana_datasource_config = {

246

"name": "Azure Monitor Workspace",

247

"type": "prometheus",

248

"url": query_endpoint,

249

"access": "proxy",

250

"basicAuth": False,

251

"jsonData": {

252

"httpMethod": "POST",

253

"manageAlerts": True,

254

"prometheusType": "Prometheus",

255

"prometheusVersion": "2.40.0"

256

}

257

}

258

259

print("Grafana data source configuration:")

260

print(f"URL: {query_endpoint}")

261

```

262

263

## Types

264

265

```python { .api }

266

class AzureMonitorWorkspaceResource:

267

"""Azure Monitor Workspace resource."""

268

location: str # Resource location

269

properties: Optional[AzureMonitorWorkspaceResourceProperties] # Workspace properties

270

etag: Optional[str] # Resource etag

271

id: Optional[str] # Resource ID

272

name: Optional[str] # Resource name

273

type: Optional[str] # Resource type

274

system_data: Optional[SystemData] # System metadata

275

tags: Optional[Dict[str, str]] # Resource tags

276

277

class AzureMonitorWorkspaceResourceProperties:

278

"""Azure Monitor Workspace properties."""

279

account_id: Optional[str] # Workspace account ID

280

metrics: Optional[AzureMonitorWorkspaceMetrics] # Metrics configuration

281

provisioning_state: Optional[str] # Provisioning state

282

public_network_access: Optional[PublicNetworkAccess] # Public network access

283

default_ingestion_settings: Optional[AzureMonitorWorkspaceDefaultIngestionSettings] # Default ingestion settings

284

285

class AzureMonitorWorkspaceMetrics:

286

"""Workspace metrics configuration."""

287

internal_id: Optional[str] # Internal workspace ID

288

prometheus_query_endpoint: Optional[str] # Prometheus query endpoint URL

289

290

class AzureMonitorWorkspaceDefaultIngestionSettings:

291

"""Default ingestion settings."""

292

data_collection_endpoint_resource_id: Optional[str] # Data collection endpoint ID

293

data_collection_rule_resource_id: Optional[str] # Data collection rule ID

294

295

class AzureMonitorWorkspaceResourceForUpdate:

296

"""Workspace resource for updates."""

297

tags: Optional[Dict[str, str]] # Resource tags to update

298

299

class SystemData:

300

"""System metadata."""

301

created_by: Optional[str] # Created by user/service

302

created_by_type: Optional[CreatedByType] # Creator type

303

created_at: Optional[datetime] # Creation timestamp

304

last_modified_by: Optional[str] # Last modified by user/service

305

last_modified_by_type: Optional[CreatedByType] # Last modifier type

306

last_modified_at: Optional[datetime] # Last modification timestamp

307

308

PublicNetworkAccess = Union["Enabled", "Disabled"]

309

CreatedByType = Union["User", "Application", "ManagedIdentity", "Key"]

310

```