Here’s the complete solution addressing all three focus areas that break after Azure Monitor agent redeployment:
Agent Resource Configuration:
The redeployment created a new agent instance with a new managed identity, which lost its resource associations. You need to reconfigure the agent:
- First, verify the agent’s managed identity has the correct roles:
az role assignment create \
--assignee <agent-managed-identity-id> \
--role "Monitoring Reader" \
--scope /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Devices/IotHubs/{hub}
- The agent also needs ‘Log Analytics Contributor’ if you’re sending metrics to a Log Analytics workspace:
az role assignment create \
--assignee <agent-managed-identity-id> \
--role "Log Analytics Contributor" \
--scope /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.OperationalInsights/workspaces/{workspace}
- Recreate the agent configuration file (/etc/opt/microsoft/azuremonitoragent/config.json) to include IoT Hub as a data source:
{
"dataSources": [
{
"type": "platformMetrics",
"resourceId": "/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Devices/IotHubs/{hub}",
"streams": ["Microsoft-InsightsMetrics"]
}
]
}
IoT Hub Metric Namespaces:
The metric namespace configuration likely changed during redeployment. IoT Hub uses specific namespaces that must be explicitly configured:
- Update your Data Collection Rule (DCR) to include the correct namespaces:
{
"properties": {
"dataSources": {
"platformTelemetry": [
{
"streams": ["Microsoft.Insights/metrics"],
"name": "iotHubPlatformMetrics",
"resourceId": "/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Devices/IotHubs/{hub}",
"metricNamespaces": [
"Microsoft.Devices/IotHubs"
]
}
]
},
"destinations": {
"azureMonitorMetrics": {
"name": "azureMonitorMetrics-default"
}
},
"dataFlows": [
{
"streams": ["Microsoft.Insights/metrics"],
"destinations": ["azureMonitorMetrics-default"]
}
]
}
}
The key is specifying ‘Microsoft.Devices/IotHubs’ as the metric namespace. This is different from the generic ‘Microsoft.Insights’ namespace and is often missed during redeployment.
Agent Permissions:
Beyond the Monitoring Reader role, the agent needs specific diagnostic settings permissions:
- Enable diagnostic settings on IoT Hub if not already enabled:
az monitor diagnostic-settings create \
--name iot-hub-diagnostics \
--resource /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Devices/IotHubs/{hub} \
--metrics '[{"category":"AllMetrics","enabled":true}]' \
--workspace /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.OperationalInsights/workspaces/{workspace}
- Grant the agent’s managed identity ‘Monitoring Metrics Publisher’ role (this is often missed):
az role assignment create \
--assignee <agent-managed-identity-id> \
--role "Monitoring Metrics Publisher" \
--scope /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Devices/IotHubs/{hub}
This role is required for the agent to WRITE metrics to Azure Monitor, not just read them.
Reassociate DCR with IoT Hub:
The critical step that’s usually missed:
az monitor data-collection rule association create \
--name iot-hub-dcr-association \
--rule-id /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Insights/dataCollectionRules/{dcr-name} \
--resource /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Devices/IotHubs/{hub}
Without this association, the DCR doesn’t know to collect metrics from your IoT Hub.
Verification Steps:
- Check DCR associations: `az monitor data-collection rule association list --resource
- Verify agent is collecting data: Check agent logs at /var/opt/microsoft/azuremonitoragent/log/mdsd.err
- Query metrics directly: `az monitor metrics list --resource --metric “d2c.telemetry.ingress.allProtocol”
If metrics appear in the direct query but not in dashboards, the issue is with the dashboard configuration, not the agent. If metrics don’t appear in the direct query, the agent isn’t collecting them properly.
After these changes, metrics should start flowing within 5-10 minutes. The three-day gap you’re experiencing is typical when the DCR association is missing - the agent is healthy but has no instruction to collect IoT Hub metrics.