diff --git a/src/06_domains/cittadini-app/12_alert.tf b/src/06_domains/cittadini-app/12_alert.tf index 96cebd9..3c5fc5c 100644 --- a/src/06_domains/cittadini-app/12_alert.tf +++ b/src/06_domains/cittadini-app/12_alert.tf @@ -22,21 +22,21 @@ resource "azurerm_monitor_scheduled_query_rules_alert_v2" "Availability" { evaluation_frequency = "P1D" window_duration = "P1D" - scopes = [data.azurerm_log_analytics_workspace.log_analytics.id] + scopes = [data.azurerm_application_insights.application_insights.id] severity = 0 criteria { query = <<-QUERY let interval = totimespan(1m); - let tot = AzureDiagnostics - | where requestUri_s has 'cittadini' - | summarize tot = todouble(count()) by bin(TimeGenerated, interval); - let errors = AzureDiagnostics - | where requestUri_s has 'cittadini' - | where strcmp(httpStatusCode_s,"412") > 0 - | summarize not_ok = count() by bin(TimeGenerated, interval); + let tot = requests + | where operation_Name has 'cittadini' + | summarize tot = todouble(count()) by bin(timestamp, interval); + let errors = requests + | where operation_Name has 'cittadini' + | where strcmp(resultCode,"412") > 0 + | summarize not_ok = count() by bin(timestamp, interval); tot - | join kind=leftouter errors on TimeGenerated - | project TimeGenerated, availability = (tot - coalesce(not_ok, 0)) / tot, watermark=0.99 + | join kind=leftouter errors on timestamp + | project timestamp, availability = (tot - coalesce(not_ok, 0)) / tot, watermark=0.99 QUERY time_aggregation_method = "Average" threshold = 0.99 diff --git a/src/06_domains/cittadini-app/workbooks/OPEXWorkbook.json.tpl b/src/06_domains/cittadini-app/workbooks/OPEXWorkbook.json.tpl index 5b941fa..ad6a321 100644 --- a/src/06_domains/cittadini-app/workbooks/OPEXWorkbook.json.tpl +++ b/src/06_domains/cittadini-app/workbooks/OPEXWorkbook.json.tpl @@ -381,15 +381,15 @@ "type": 3, "content": { "version": "KqlItem/1.0", - "query": "let startTime = {timeRangeOverall:start};\nlet endTime = {timeRangeOverall:end};\nlet interval = totimespan({timeSpan:label});\n\nlet tot = AzureDiagnostics\n| where TimeGenerated between (startTime .. endTime) \n| where requestUri_s has 'cittadini'\n| summarize tot = todouble(count()) by bin(TimeGenerated, interval);\nlet errors = AzureDiagnostics\n| where requestUri_s has 'cittadini'\n| where strcmp(httpStatusCode_s, \"412\") > 0 \n| summarize not_ok = count() by bin(TimeGenerated, interval);\ntot\n| join kind=leftouter errors on TimeGenerated\n| project TimeGenerated, availability = (tot - coalesce(not_ok, 0))/tot, watermark=0.99", + "query": "let startTime = {timeRangeOverall:start};\nlet endTime = {timeRangeOverall:end};\nlet interval = totimespan({timeSpan:label});\n\nlet tot = requests\n | where timestamp between (startTime .. endTime) \n | where operation_Name has 'cittadini'\n | summarize tot = todouble(count()) by bin(timestamp, interval);\nlet errors = requests\n | where operation_Name has 'cittadini'\n | where strcmp(resultCode, \"412\") > 0 \n | summarize not_ok = count() by bin(timestamp, interval);\ntot\n| join kind=leftouter errors on timestamp\n| project timestamp, availability = (tot - coalesce(not_ok, 0)) / tot, watermark=0.99", "size": 0, "aggregation": 3, "showAnalytics": true, "title": "Availability @ AppGateway", "queryType": 0, - "resourceType": "microsoft.operationalinsights/workspaces", + "resourceType": "microsoft.insights/components", "crossComponentResources": [ - "/subscriptions/${subscription_id}/resourceGroups/${prefix}-${location_short}-core-monitor-rg/providers/Microsoft.OperationalInsights/workspaces/${prefix}-${location_short}-core-law" + "/subscriptions/${subscription_id}/resourceGroups/${prefix}-${location_short}-core-monitor-rg/providers/Microsoft.Insights/components/${prefix}-${location_short}-core-appinsights" ], "visualization": "timechart", "chartSettings": {