or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

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

tessl/pypi-azure-mgmt-monitor

Microsoft Azure Monitor Client Library for Python

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/azure-mgmt-monitor@7.0.x

To install, run

npx @tessl/cli install tessl/pypi-azure-mgmt-monitor@7.0.0

index.mddocs/

Azure Monitor Management Client

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.

Package Information

  • Package Name: azure-mgmt-monitor
  • Language: Python
  • Installation: pip install azure-mgmt-monitor
  • Version: 7.0.0

Core Imports

from azure.mgmt.monitor import MonitorManagementClient

For asynchronous operations:

from azure.mgmt.monitor.aio import MonitorManagementClient

Basic Usage

from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient

# Initialize the client
credential = DefaultAzureCredential()
subscription_id = "your-subscription-id"
client = MonitorManagementClient(credential, subscription_id)

# List all action groups in a resource group
resource_group_name = "your-resource-group"
action_groups = list(client.action_groups.list_by_resource_group(resource_group_name))

# Get metrics for a resource
resource_uri = "/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Compute/virtualMachines/{}".format(
    subscription_id, resource_group_name, "vm-name"
)
metrics = client.metrics.list(resource_uri, metricnames="Percentage CPU")

# Create a metric alert
from azure.mgmt.monitor.models import MetricAlertResource, MetricAlertAction
alert_rule = MetricAlertResource(
    location="global",
    description="High CPU usage alert",
    enabled=True,
    scopes=[resource_uri],
    evaluation_frequency="PT1M",
    window_size="PT5M",
    criteria={
        "odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
        "allOf": [{
            "name": "High CPU",
            "metricName": "Percentage CPU",
            "operator": "GreaterThan",
            "threshold": 80,
            "timeAggregation": "Average"
        }]
    }
)
client.metric_alerts.create_or_update(resource_group_name, "high-cpu-alert", alert_rule)

Architecture

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

  • MonitorManagementClient: Main client class providing access to all operations
  • Operations Groups: Specialized classes for different Azure Monitor services (action groups, alerts, metrics, etc.)
  • Models: Data structures representing Azure Monitor resources and configurations
  • Authentication: Integration with Azure Identity for secure access

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

Capabilities

Action Groups and Notifications

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.

# Core action group operations
client.action_groups.create_or_update(resource_group_name: str, action_group_name: str, action_group: ActionGroupResource) -> ActionGroupResource
client.action_groups.get(resource_group_name: str, action_group_name: str) -> ActionGroupResource
client.action_groups.delete(resource_group_name: str, action_group_name: str) -> None
client.action_groups.list_by_resource_group(resource_group_name: str) -> ItemPaged[ActionGroupResource]

Action Groups and Notifications

Activity Log Monitoring

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.

# Activity log operations
client.activity_logs.list(filter: str, select: Optional[str] = None) -> ItemPaged[EventData]
client.activity_log_alerts.create_or_update(resource_group_name: str, activity_log_alert_name: str, activity_log_alert_rule: ActivityLogAlertResource) -> ActivityLogAlertResource
client.tenant_activity_logs.list(filter: Optional[str] = None, select: Optional[str] = None) -> ItemPaged[EventData]
client.event_categories.list() -> ItemPaged[LocalizableString]
client.alert_rule_incidents.get(resource_group_name: str, rule_name: str, incident_name: str) -> Incident

Activity Log Monitoring

Metric Alerts and Monitoring

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

# Metric alert operations
client.metric_alerts.create_or_update(resource_group_name: str, rule_name: str, parameters: MetricAlertResource) -> MetricAlertResource
client.metric_alerts.get(resource_group_name: str, rule_name: str) -> MetricAlertResource
client.metric_alerts_status.list(resource_group_name: str, rule_name: str) -> MetricAlertStatusCollection

Metric Alerts and Monitoring

Metrics and Baselines

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

# Metrics operations
client.metrics.list(resource_uri: str, timespan: Optional[str] = None, interval: Optional[str] = None, metricnames: Optional[str] = None, aggregation: Optional[str] = None) -> Response
client.metric_definitions.list(resource_uri: str, metricnamespace: Optional[str] = None) -> ItemPaged[MetricDefinition]
client.baselines.list(resource_uri: str, metricnames: Optional[str] = None, metricnamespace: Optional[str] = None) -> ItemPaged[SingleMetricBaseline]

Metrics and Baselines

Autoscaling

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

# Autoscale operations
client.autoscale_settings.create_or_update(resource_group_name: str, autoscale_setting_name: str, parameters: AutoscaleSettingResource) -> AutoscaleSettingResource
client.predictive_metric.get(resource_group_name: str, autoscale_setting_name: str, timespan: str, interval: str, metricnamespace: str, metricname: str, aggregation: str) -> PredictiveResponse

Autoscaling

Data Collection

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

# Data collection operations
client.data_collection_rules.create(resource_group_name: str, data_collection_rule_name: str, body: Optional[DataCollectionRuleResource] = None) -> DataCollectionRuleResource
client.data_collection_endpoints.create(resource_group_name: str, data_collection_endpoint_name: str, body: Optional[DataCollectionEndpointResource] = None) -> DataCollectionEndpointResource
client.data_collection_rule_associations.create(resource_uri: str, association_name: str, body: Optional[DataCollectionRuleAssociationProxyOnlyResource] = None) -> DataCollectionRuleAssociationProxyOnlyResource

Data Collection

Log Analytics and Query Rules

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

# Query rules operations
client.scheduled_query_rules.create_or_update(resource_group_name: str, rule_name: str, parameters: ScheduledQueryRuleResource) -> ScheduledQueryRuleResource
client.log_profiles.create_or_update(log_profile_name: str, parameters: LogProfileResource) -> LogProfileResource

Log Analytics and Query Rules

Azure Monitor Workspaces

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

# Workspace operations
client.azure_monitor_workspaces.create(resource_group_name: str, azure_monitor_workspace_name: str, azure_monitor_workspace_properties: AzureMonitorWorkspaceResource) -> AzureMonitorWorkspaceResource
client.azure_monitor_workspaces.get(resource_group_name: str, azure_monitor_workspace_name: str) -> AzureMonitorWorkspaceResource

Azure Monitor Workspaces

Common Types

class MonitorManagementClient:
    """Main client class for Azure Monitor management operations."""
    def __init__(self, credential: TokenCredential, subscription_id: str, base_url: Optional[str] = None, **kwargs: Any) -> None: ...
    def close(self) -> None: ...
    def __enter__(self) -> Self: ...
    def __exit__(self, *exc_details: Any) -> None: ...

# Core resource types
class ActionGroupResource:
    """Action group resource definition."""
    location: str
    group_short_name: str
    enabled: bool
    email_receivers: Optional[List[EmailReceiver]]
    sms_receivers: Optional[List[SmsReceiver]]
    webhook_receivers: Optional[List[WebhookReceiver]]
    # ... other receiver types

class MetricAlertResource:
    """Metric alert rule resource."""
    location: str
    description: Optional[str]
    enabled: bool
    scopes: List[str]
    evaluation_frequency: str
    window_size: str
    criteria: MetricAlertCriteria
    actions: Optional[List[MetricAlertAction]]

class AutoscaleSettingResource:
    """Autoscale setting resource."""
    location: str
    profiles: List[AutoscaleProfile]
    enabled: Optional[bool]
    target_resource_uri: Optional[str]
    target_resource_location: Optional[str]

class DataCollectionRuleResource:
    """Data collection rule resource."""
    location: str
    data_sources: Optional[DataCollectionRuleDataSources]
    destinations: Optional[DataCollectionRuleDestinations]
    data_flows: Optional[List[DataFlow]]

class Incident:
    """Alert rule incident representing activation status."""
    name: Optional[str]
    rule_name: Optional[str] 
    is_active: Optional[bool]
    activated_time: Optional[datetime]
    resolved_time: Optional[datetime]

class LocalizableString:
    """Localizable string value."""
    value: str
    localized_value: Optional[str]

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