@@ -357,181 +357,12 @@ You can also set the pricing plan on an existing Application Insights resource u
357
357
358
358
## Add a metric alert
359
359
360
- To set up a metric alert at the same time as your app resource, merge code like this into the template file:
361
-
362
- ``` JSON
363
- {
364
- parameters: { ... // existing parameters ...
365
- "responseTime" : {
366
- "type" : " int" ,
367
- "defaultValue" : 3 ,
368
- "minValue" : 1 ,
369
- "metadata" : {
370
- "description" : " Enter response time threshold in seconds."
371
- }
372
- },
373
- variables: { ... // existing variables ...
374
- // Alert names must be unique within resource group.
375
- "responseAlertName" : " [concat('ResponseTime-', toLower(parameters('appName')))]"
376
- },
377
- resources: { ... // existing resources ...
378
- {
379
- //
380
- // Metric alert on response time
381
- //
382
- "name" : " [variables('responseAlertName')]" ,
383
- "type" : " Microsoft.Insights/alertrules" ,
384
- "apiVersion" : " 2014-04-01" ,
385
- "location" : " [parameters('appLocation')]" ,
386
- // Ensure this resource is created after the app resource:
387
- "dependsOn" : [
388
- " [resourceId('Microsoft.Insights/components', parameters('appName'))]"
389
- ],
390
- "tags" : {
391
- "[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('appName')))]" : " Resource"
392
- },
393
- "properties" : {
394
- "name" : " [variables('responseAlertName')]" ,
395
- "description" : " response time alert" ,
396
- "isEnabled" : true ,
397
- "condition" : {
398
- "$type" : " Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client" ,
399
- "odata.type" : " Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition" ,
400
- "dataSource" : {
401
- "$type" : " Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client" ,
402
- "odata.type" : " Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource" ,
403
- "resourceUri" : " [resourceId('microsoft.insights/components', parameters('appName'))]" ,
404
- "metricName" : " request.duration"
405
- },
406
- "threshold" : " [parameters('responseTime')]" , //seconds
407
- "windowSize" : " PT15M" // Take action if changed state for 15 minutes
408
- },
409
- "actions" : [
410
- {
411
- "$type" : " Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client" ,
412
- "odata.type" : " Microsoft.Azure.Management.Insights.Models.RuleEmailAction" ,
413
- "sendToServiceOwners" : true ,
414
- "customEmails" : []
415
- }
416
- ]
417
- }
418
- }
419
- }
420
- ```
421
-
422
- When you invoke the template, you can optionally add this parameter:
423
-
424
- `-responseTime 2`
425
-
426
- You can of course parameterize other fields.
427
-
428
- To find out the type names and configuration details of other alert rules, create a rule manually and then inspect it in [ Azure Resource Manager] ( https://resources.azure.com/ ) .
360
+ To automate the creation of metric alerts consult the [ metric alerts template article] ( https://docs.microsoft.com/azure/azure-monitor/platform/alerts-metric-create-templates#template-for-a-simple-static-threshold-metric-alert )
429
361
430
362
431
363
## Add an availability test
432
364
433
- This example is for a ping test (to test a single page).
434
-
435
- ** There are two parts** in an availability test: the test itself, and the alert that notifies you of failures.
436
-
437
- Merge the following code into the template file that creates the app.
438
-
439
- ``` JSON
440
- {
441
- parameters: { ... // existing parameters here ...
442
- "pingURL" : { "type" : " string" },
443
- "pingText" : { "type" : " string" , defaultValue: "" }
444
- },
445
- variables: { ... // existing variables here ...
446
- "pingTestName" :" [concat('PingTest-', toLower(parameters('appName')))]" ,
447
- "pingAlertRuleName" : " [concat('PingAlert-', toLower(parameters('appName')), '-', subscription().subscriptionId)]"
448
- },
449
- resources: { ... // existing resources here ...
450
- { //
451
- // Availability test: part 1 configures the test
452
- //
453
- "name" : " [variables('pingTestName')]" ,
454
- "type" : " Microsoft.Insights/webtests" ,
455
- "apiVersion" : " 2014-04-01" ,
456
- "location" : " [parameters('appLocation')]" ,
457
- // Ensure this is created after the app resource:
458
- "dependsOn" : [
459
- " [resourceId('Microsoft.Insights/components', parameters('appName'))]"
460
- ],
461
- "tags" : {
462
- "[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('appName')))]" : " Resource"
463
- },
464
- "properties" : {
465
- "Name" : " [variables('pingTestName')]" ,
466
- "Description" : " Basic ping test" ,
467
- "Enabled" : true ,
468
- "Frequency" : 900 , // 15 minutes
469
- "Timeout" : 120 , // 2 minutes
470
- "Kind" : " ping" , // single URL test
471
- "RetryEnabled" : true ,
472
- "Locations" : [
473
- {
474
- "Id" : " us-va-ash-azr"
475
- },
476
- {
477
- "Id" : " emea-nl-ams-azr"
478
- },
479
- {
480
- "Id" : " apac-jp-kaw-edge"
481
- }
482
- ],
483
- "Configuration" : {
484
- "WebTest": "[concat('<WebTest Name=\"', variables('pingTestName'), '\" Enabled=\"True\" CssProjectStructure=\"\" CssIteration=\"\" Timeout=\"120\" WorkItemIds=\"\" xmlns=\"http://microsoft.com/schemas/VisualStudio/TeamTest/2010\" Description=\"\" CredentialUserName=\"\" CredentialPassword=\"\" PreAuthenticate=\"True\" Proxy=\"default\" StopOnError=\"False\" RecordedResultFile=\"\" ResultsLocale=\"\"> <Items> <Request Method=\"GET\" Version=\"1.1\" Url=\"', parameters('Url'), '\" ThinkTime=\"0\" Timeout=\"300\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /> </Items> <ValidationRules> <ValidationRule Classname=\"Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleFindText, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\" DisplayName=\"Find Text\" Description=\"Verifies the existence of the specified text in the response.\" Level=\"High\" ExecutionOrder=\"BeforeDependents\"> <RuleParameters> <RuleParameter Name=\"FindText\" Value=\"', parameters('pingText'), '\" /> <RuleParameter Name=\"IgnoreCase\" Value=\"False\" /> <RuleParameter Name=\"UseRegularExpression\" Value=\"False\" /> <RuleParameter Name=\"PassIfTextFound\" Value=\"True\" /> </RuleParameters> </ValidationRule> </ValidationRules> </WebTest>')]"
485
- },
486
- "SyntheticMonitorId" : " [variables('pingTestName')]"
487
- }
488
- },
489
-
490
- {
491
- //
492
- // Availability test: part 2, the alert rule
493
- //
494
- "name" : " [variables('pingAlertRuleName')]" ,
495
- "type" : " Microsoft.Insights/alertrules" ,
496
- "apiVersion" : " 2014-04-01" ,
497
- "location" : " [parameters('appLocation')]" ,
498
- "dependsOn" : [
499
- " [resourceId('Microsoft.Insights/webtests', variables('pingTestName'))]"
500
- ],
501
- "tags" : {
502
- "[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('appName')))]" : " Resource" ,
503
- "[concat('hidden-link:', resourceId('Microsoft.Insights/webtests', variables('pingTestName')))]" : " Resource"
504
- },
505
- "properties" : {
506
- "name" : " [variables('pingAlertRuleName')]" ,
507
- "description" : " alert for web test" ,
508
- "isEnabled" : true ,
509
- "condition" : {
510
- "$type" : " Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.LocationThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client" ,
511
- "odata.type" : " Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition" ,
512
- "dataSource" : {
513
- "$type" : " Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client" ,
514
- "odata.type" : " Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource" ,
515
- "resourceUri" : " [resourceId('microsoft.insights/webtests', variables('pingTestName'))]" ,
516
- "metricName" : " GSMT_AvRaW"
517
- },
518
- "windowSize" : " PT15M" , // Take action if changed state for 15 minutes
519
- "failedLocationCount" : 2
520
- },
521
- "actions" : [
522
- {
523
- "$type" : " Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client" ,
524
- "odata.type" : " Microsoft.Azure.Management.Insights.Models.RuleEmailAction" ,
525
- "sendToServiceOwners" : true ,
526
- "customEmails" : []
527
- }
528
- ]
529
- }
530
- }
531
- }
532
- ```
533
-
534
- To discover the codes for other test locations, or to automate the creation of more complex web tests, create an example manually and then parameterize the code from [ Azure Resource Manager] ( https://resources.azure.com/ ) .
365
+ To automate availability tests consult the [ metric alerts template article] ( https://docs.microsoft.com/azure/azure-monitor/platform/alerts-metric-create-templates#template-for-an-availability-test-along-with-a-metric-alert ) .
535
366
536
367
## Add more resources
537
368
0 commit comments