Skip to content

Commit 42b7b97

Browse files
format variables.tf
update readme Update Readme.md Update README.md Update README.md Redesigned README.md provide clarity regarding resourceIds and scaling dimensions update README; remove comments Update README.md and azure simple variables added attributes section to README.md
1 parent 6a8921c commit 42b7b97

File tree

5 files changed

+105
-38
lines changed

5 files changed

+105
-38
lines changed
Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,71 @@
11
# Azure Monitor
22

3-
This custom Terraform based `app-monitoring` module is recommended for monitoring Azure Resources externally servicing an App service (ex. App Service Plan, App Gateway, VM, etc.). For monitoring the `metrics` emitted at the App Service level, Azure Monitor relies on application insights. The `app-insights` module can be found here.
4-
5-
This module can be used by Cobalt Templates in order to map configurable `alert criteria` to individual Azure Resources offered by the Azure Monitor Service for monitoring. Monitored `alert criteria` comes in two forms, `metrics` and `logs`. This module introduces monitoring for `metrics` only. As a result, this module offers configurable `metric alert criteria`. How `metric alert criteria` is configured depends on the type of predefined metrics offered by the particular Azure Resource being referenced for monitoring. (ex. The App Service Plan Resource offers 'CpuMonitoring' as a configurable `metric`.)
3+
This Terraform based `app-monitoring` module grants templates the ability to define and assign `alert criteria` to "Azure Resources" using Microsoft's _**Azure Monitor**_ service. `alert criteria` is conditional logic that targets a list of one or more "Azure Resources" for the purposes of monitoring their behavior. `alert criteria` comes in two forms, `metrics` and `logs`. This module introduces `metrics` based monitoring only. As a result, `alert criteria` in the context of this module is refered to as `metric alert criteria`. The way `metric alert criteria` is configured depends entirely on the `metrics` options offered by the "Azure Resources" selected for monitoring. (ex. The App Service Plan resource offers 'CpuMonitoring' as a configurable `metric`.)
64

75
In addition to the `metric alert criteria`, this module introduces a configurable `action group` that when paired with `metric alert criteria` can be configured to trigger events like e-mail notifications.
86

9-
#### More on Azure Monitoring
7+
#### _More on Azure Monitoring_
108

11-
"Azure Monitor maximizes the availability and performance of your applications by delivering a comprehensive solution for collecting, analyzing, and acting on telemetry from your cloud and on-premises environments. ..All data collected by Azure Monitor fits into one of two fundamental types, metrics and logs. Metrics are numerical values that describe some aspect of a system at a particular point in time. They are lightweight and capable of supporting near real-time scenarios. Logs contain different kinds of data organized into records with different sets of properties for each type." - Source: [Azure Monitor Overview](https://docs.microsoft.com/en-us/azure/azure-monitor/overview)
9+
> "Azure Monitor maximizes the availability and performance of your applications by delivering a comprehensive solution for collecting, analyzing, and acting on telemetry from your cloud and on-premises environments.
10+
> All data collected by Azure Monitor fits into one of two fundamental types, metrics and logs. Metrics are numerical values that describe some aspect of a system at a particular point in time. They are lightweight and capable of supporting near real-time scenarios. Logs contain different kinds of data organized into records with different sets of properties for each type." - Source: Microsoft's [Azure Monitor Service Overview](https://docs.microsoft.com/en-us/azure/azure-monitor/overview)
1211
13-
The list of `metrics` available for configuration entirely depends on the Azure Resource chosen to be monitored. Please visit [Supported Metrics](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported) for a complete list of metrics supported by the Azure Monitor service.
12+
This module deploys the _**Azure Monitor**_ service in order to offer visibility into the behavior of your deployed "Azure Resources". This module is recommended for `metrics` based monitoring of any "Azure Resource" deployed alongside App Services (ex. App Service Plan, App Gateway, VM, etc.). The list of `metrics` available for configuration depends entirely on the Azure Resource chosen to be monitored. For more information on how `metrics` work, please visit Microsoft's [alerts-metric-overview](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric-overview) documentation.
1413

15-
#### More on Terraform Resources
14+
For monitoring of an App Service, the [app-insights](../app-insights) module is instead recommended. The [app-insights](../app-insights) module leverages an _**Azure Monitor**_ service called [application insights](https://www.terraform.io/docs/providers/azurerm/r/application_insights.html).
1615

17-
Terraform resources used to define the `app-monitoring` module include the following:
16+
## Characteristics
1817

19-
- `azurerm_monitor_metric_alert` - https://www.terraform.io/docs/providers/azurerm/r/monitor_metric_alert.html
18+
An instance of the `app-monitoring` module deploys the _**Azure Monitor**_ service in order to provide templates with the following:
2019

21-
- `azurerm_monitor_action_group` - https://www.terraform.io/docs/providers/azurerm/r/monitor_action_group.html
20+
- Ability to deploy Azure Monitor within a single resource group.
2221

23-
## Characteristics
22+
- Ability to deploy Azure Monitor with a single set of configurable `metric alert criteria` targeting one or more Azure resources.
2423

25-
A Terraform module in Cobalt that leverages the "Azure Monitor Service" in order to provide Cobalt Templates with the following characteristics:
24+
- Ability to deploy Azure Monitor with a single set of configurable `metric alert criteria` tied to a single `action group`.
2625

27-
- Ability to deploy Azure Monitor in the same resource group as the Service Plan.
26+
## Definition
2827

29-
- Ability to deploy Azure Monitor with configurable `metric alert criteria` targeting Azure resources.
28+
App Monitoring definition example:
3029

31-
- Ability to deploy Azure Monitor with configurable `metric alert criteria` tied to a single action group.
30+
```terraform
31+
resource "azurerm_monitor_action_group" "appmonitoring" {
32+
count = "${var.action_group_email_receiver == "" ? 0 : 1}"
33+
name = "${var.action_group_name}"
34+
resource_group_name = "${var.resource_group_name}"
35+
short_name = "${var.action_group_short_name}"
36+
}
3237
33-
## Default Behavior
38+
resource "azurerm_monitor_metric_alert" "appmonitoring" {
39+
count = "${var.action_group_email_receiver == "" ? 0 : 1}"
40+
name = "${var.metric_alert_name}"
41+
resource_group_name = "${azurerm_monitor_action_group.appmonitoring.resource_group_name}"
42+
scopes = ["${var.resource_ids}"]
43+
44+
criteria {
45+
metric_namespace = "${var.metric_alert_criteria_namespace}"
46+
metric_name = "${var.metric_alert_criteria_name}"
47+
aggregation = "${var.metric_alert_criteria_aggregation}"
48+
operator = "${var.metric_alert_criteria_operator}"
49+
threshold = "${var.metric_alert_criteria_threshold}"
50+
}
51+
52+
action {
53+
action_group_id = "${azurerm_monitor_action_group.appmonitoring.id}"
54+
}
55+
}
56+
```
3457

35-
The `metric alert criteria` is configured to deploy "CPU Resource Monitoring" for an App Service Plan Resource that emits alerts at configurable CPU thresholds. The `action group` is configured to send e-mails upon every alert. If a template does not provide an e-mail, this module deploys nothing.
58+
Terraform resources used to define the `app-monitoring` module include the following:
3659

37-
### Module Usage
60+
- [azurerm_monitor_metric_alert](https://www.terraform.io/docs/providers/azurerm/r/monitor_metric_alert.html)
3861

39-
- Service Plan Module : infra/modules/providers/azure/service-plan
40-
- App Monitoring Module : infra/modules/providers/azure/app-monitoring
62+
- [azurerm_monitor_action_group](https://www.terraform.io/docs/providers/azurerm/r/monitor_action_group.html)
4163

42-
```
64+
## Usage
65+
66+
App Monitoring usage example:
67+
68+
```terraform
4369
variable "resource_group_name" {
4470
value = "test-rg"
4571
}
@@ -56,7 +82,7 @@ module "service_plan" {
5682
5783
module "app_monitoring" {
5884
source = "../../modules/providers/azure/app-monitoring"
59-
resource_group_name = "${azurerm_resource_group.svcplan.name}"
85+
resource_group_name = "${module.service_plan.resource_group_name}"
6086
resource_ids = ["${module.service_plan.app_service_plan_id}"]
6187
action_group_name = "${var.action_group_name}"
6288
action_group_email_receiver = "${var.action_group_email_receiver}"
@@ -66,15 +92,39 @@ module "app_monitoring" {
6692
metric_alert_criteria_aggregation = "${var.metric_alert_criteria_aggregation}"
6793
metric_alert_criteria_operator = "${var.metric_alert_criteria_operator}"
6894
metric_alert_criteria_threshold = "${var.metric_alert_criteria_threshold}"
95+
scaling_values = "${var.scaling_values}"
6996
}
7097
```
7198

72-
## Output
99+
#### Configuring `resource_ids`
73100

74-
Once the deployments are completed successfully, the output for the current module will be in the format mentioned below:
101+
Please visit _**Azure Monitor's**_ [monitoring at scale](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric-overview#monitoring-at-scale-using-metric-alerts-in-azure-monitor.) page for more information on choosing multiple "Azure Resources".
75102

76-
```
77-
Outputs:
103+
- Resource IDs can either be a list of VM IDs or a single Azure Resource ID.
104+
105+
#### Configuring `metric alert criteria`
106+
107+
Please visit _**Azure Monitor's**_ [Supported Metrics](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported) page for a complete list of supported metrics per "Azure Resource".
108+
109+
1. View the list of 'metrics' offered by the namespace of your chosen "Azure Resource".
110+
2. Choose a metric.
111+
3. Define the metric's criteria (i.e. Conditional logic being applied to an "Azure Resource".)
112+
4. Apply that criteria to your chosen or newly created template.
113+
114+
#### Configuring `action group`
115+
116+
Please visit _**Azure Monitor's**_ [action-groups](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/action-groups) page for more information on e-mail action groups.
117+
118+
1. Choose an appropriate e-mail address to receive alert notifications.
119+
2. Choose an appropriate name for the 'action group' that will hold the e-mail address. (ex. "E-mail Alert Group")
120+
3. Apply the e-mail address and name to your chosen or newly created template.
121+
122+
## Argument Reference
123+
124+
Supported arguments for this module are available in [variables.tf](variables.tf).
125+
126+
## Attributes Reference
127+
128+
The following attributes are exported:
78129

79-
rule_resource_id = xxxx5ba9-f5xx-xx94-93xx-xxxx0d40xxxx
80-
```
130+
- `rule_resource_id`: The ID of the metric alert.

infra/modules/providers/azure/app-monitoring/main.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
locals {
2+
scaling_name = "Instance"
3+
scaling_operator = "Include"
4+
}
5+
16
resource "azurerm_monitor_action_group" "appmonitoring" {
27
count = "${var.action_group_email_receiver == "" ? 0 : 1}"
38
name = "${var.action_group_name}"
@@ -11,7 +16,7 @@ resource "azurerm_monitor_action_group" "appmonitoring" {
1116
}
1217

1318
resource "azurerm_monitor_metric_alert" "appmonitoring" {
14-
count = "${var.action_group_email_receiver == "" ? 0 : 1}"
19+
count = "${var.action_group_email_receiver == "" ? 0 : 1}"
1520
name = "${var.metric_alert_name}"
1621
resource_group_name = "${azurerm_monitor_action_group.appmonitoring.resource_group_name}"
1722
scopes = ["${var.resource_ids}"]
@@ -24,9 +29,9 @@ resource "azurerm_monitor_metric_alert" "appmonitoring" {
2429
threshold = "${var.metric_alert_criteria_threshold}"
2530

2631
dimension {
27-
name = "Instance"
28-
operator = "Include"
29-
values = ["*"]
32+
name = "${local.scaling_name}"
33+
operator = "${local.scaling_operator}"
34+
values = "${var.scaling_values}"
3035
}
3136
}
3237

infra/modules/providers/azure/app-monitoring/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ variable "metric_alert_criteria_threshold" {
6161
description = "The criteria threshold value that activates the metric alert."
6262
type = "string"
6363
}
64+
65+
variable "scaling_values" {
66+
description = "App instance names made available from app service plan scaling options."
67+
type = "list"
68+
}

infra/templates/azure-simple/appdev.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ module "app_monitoring" {
5353
metric_alert_criteria_aggregation = "${var.metric_alert_criteria_aggregation}"
5454
metric_alert_criteria_operator = "${var.metric_alert_criteria_operator}"
5555
metric_alert_criteria_threshold = "${var.metric_alert_criteria_threshold}"
56+
scaling_values = "${var.scaling_values}"
5657
}

infra/templates/azure-simple/variables.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ variable "action_group_name" {
5252
default = "Simple Default Action Group"
5353
}
5454

55-
variable "action_group_email_receiver" {
56-
description = "The e-mail receiver for an alert rule resource."
57-
type = "string"
58-
default = ""
59-
}
55+
variable "action_group_email_receiver" {
56+
description = "The e-mail receiver for an alert rule resource."
57+
type = "string"
58+
default = ""
59+
}
6060

6161
variable "metric_alert_criteria_namespace" {
6262
description = "A monitored resource namespace with configurable metric alert criteria."
@@ -91,7 +91,13 @@ variable "metric_alert_criteria_operator" {
9191
variable "metric_alert_criteria_threshold" {
9292
description = "The criteria threshold value that activates the metric alert."
9393
type = "string"
94-
default = "10"
94+
default = "50"
95+
}
96+
97+
variable "scaling_values" {
98+
description = "Targets app instances made available from app service plan scaling options."
99+
type = "list"
100+
default = ["*"]
95101
}
96102

97103
# App Service

0 commit comments

Comments
 (0)