azure-monitor-query-py

Solid

Azure Monitor Query SDK for Python. Use for querying Log Analytics workspaces and Azure Monitor metrics. Triggers: "azure-monitor-query", "LogsQueryClient", "MetricsQueryClient", "Log Analytics", "Kusto queries", "Azure metrics".

DevOps & Infrastructure 2,418 stars 270 forks Updated yesterday MIT

Install

View on GitHub

Quality Score: 96/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Azure Monitor Query SDK for Python Query logs and metrics from Azure Monitor and Log Analytics workspaces. ## Installation ```bash pip install azure-monitor-query ``` ## Environment Variables ```bash # Log Analytics AZURE_LOG_ANALYTICS_WORKSPACE_ID=<workspace-id> # Metrics AZURE_METRICS_RESOURCE_URI=/subscriptions/<sub>/resourceGroups/<rg>/providers/<provider>/<type>/<name> ``` ## Authentication ```python from azure.identity import DefaultAzureCredential credential = DefaultAzureCredential() ``` ## Logs Query Client ### Basic Query ```python from azure.monitor.query import LogsQueryClient from datetime import timedelta client = LogsQueryClient(credential) query = """ AppRequests | where TimeGenerated > ago(1h) | summarize count() by bin(TimeGenerated, 5m), ResultCode | order by TimeGenerated desc """ response = client.query_workspace( workspace_id=os.environ["AZURE_LOG_ANALYTICS_WORKSPACE_ID"], query=query, timespan=timedelta(hours=1) ) for table in response.tables: for row in table.rows: print(row) ``` ### Query with Time Range ```python from datetime import datetime, timezone response = client.query_workspace( workspace_id=workspace_id, query="AppRequests | take 10", timespan=( datetime(2024, 1, 1, tzinfo=timezone.utc), datetime(2024, 1, 2, tzinfo=timezone.utc) ) ) ``` ### Convert to DataFrame ```python import pandas as pd response = client.query_workspace(workspace_id, query, timespan=timedelta...

Details

Author
microsoft
Repository
microsoft/skills
Created
4 months ago
Last Updated
yesterday
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category