Registry / azure / azure-mgmt-monitor

azure-mgmt-monitor

JSON →
library7.0.0pypypi✓ verified 25d ago

The Microsoft Azure Monitor Client Library for Python allows you to manage Azure Monitor resources, including metric definitions, metrics, activity logs, diagnostic settings, and alerts. It's part of the Azure SDK for Python, which follows a predictable release cadence with frequent updates across its many client libraries.

pip install azure-mgmt-monitor azure-identity
INSTALL
IMPORT
SIG · AZURE-MGMT-MONITOR
A
azure-mgmt-monitor
azurepythonv7.0.0
Install
4.0s avg
Import
655ms
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.690s · 46MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.620s · 46MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MonitorManagementClient
from azure.mgmt.monitor import MonitorManagementClient
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
MetricDefinition
from azure.mgmt.monitor.models import MetricDefinition
Models are typically found in the 'models' submodule.

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then use `MonitorManagementClient` to list diagnostic settings categories available at the subscription level. This helps verify client instantiation and basic API interaction.

import os from azure.identity import DefaultAzureCredential from azure.mgmt.monitor import MonitorManagementClient # Set your Azure Subscription ID as an environment variable or replace 'YOUR_SUBSCRIPTION_ID' subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID") if subscription_id == "YOUR_SUBSCRIPTION_ID": print("WARNING: Please set the AZURE_SUBSCRIPTION_ID environment variable ") print(" or replace 'YOUR_SUBSCRIPTION_ID' in the code.") # Attempt to proceed for demonstration, but subsequent calls will likely fail. try: # Authenticate using DefaultAzureCredential. This will try various methods # (environment variables, managed identity, Azure CLI, VS Code, etc.) credential = DefaultAzureCredential() # Create a Monitor Management client monitor_client = MonitorManagementClient(credential, subscription_id) print(f"Listing diagnostic settings categories for subscription '{subscription_id}'...") # The resource_uri can be a subscription, resource group, or specific resource. # For listing categories, the subscription-level URI is sufficient. resource_uri = f"/subscriptions/{subscription_id}" categories = monitor_client.diagnostic_settings_categories.list(resource_uri=resource_uri) found_categories = False for category in categories: print(f" - Category Name: {category.name}, Type: {category.category_type}") found_categories = True if not found_categories: print("No diagnostic settings categories found (or subscription ID/permissions are invalid).") except Exception as e: print(f"An error occurred: {e}") print("Please ensure you are authenticated (e.g., by running `az login`) ") print("and that your AZURE_SUBSCRIPTION_ID environment variable is correctly set.")
Debug
Known issues
breakingMajor API changes from 'Track 1' (older) to 'Track 2' (current) versions. This includes different client constructors, model structures, and method signatures.
fix
For versions <7.0.0, refer to the older documentation. For >=7.0.0, use `azure.identity` for authentication and note the client methods `begin_long_running_operation()` for async operations and direct iteration for paged lists. Most breaking changes were in the 1.x -> 2.x transition for `azure-mgmt-monitor` (and similar for other `azure-mgmt-*` libraries), with 7.0.0 being a stable Track 2 release.
affects: <7.0.0
gotchaAuthentication requires a credential object. Relying solely on older methods (e.g., hardcoded service principal credentials) is discouraged.
fix
Always use the `azure-identity` library. `DefaultAzureCredential` is recommended for local development and `ManagedIdentityCredential` or `ServicePrincipalCredential` (with environment variables) for production. Ensure you are logged in via `az login` for `AzureCliCredential` to work, or set up appropriate environment variables for other credential types.
affects: All
gotchaMany Azure Monitor operations require full Azure Resource IDs (ARNs) rather than just resource names or GUIDs.
fix
Always construct or retrieve the full resource ID in the format `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}` for operations that target specific resources. The `resource_uri` parameter is common for this.
affects: All
gotchaAsynchronous clients are available for all management libraries, often denoted by an `Async` suffix (e.g., `MonitorManagementClientAsync`). Mixing synchronous and asynchronous code can lead to issues.
fix
Choose either the synchronous or asynchronous client (`MonitorManagementClient` or `MonitorManagementClientAsync`) at the beginning and stick to it. Asynchronous clients require an `async`/`await` context.
affects: All
Upgrade
Version history
7.0.0latest on PyPI · released Jul 28, 2025
Audit
Dependencies
azure-identityrequiredRequired for authentication with Azure services. It provides various credential types like DefaultAzureCredential.
azure-mgmt-corerequiredCommon base for all Azure management (track 2) client libraries.
Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
1
Resources
azure-mgmt-monitor — pip install azure-mgmt-monitor · libregistry