-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.tf
More file actions
198 lines (155 loc) · 5.39 KB
/
monitor.tf
File metadata and controls
198 lines (155 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
## This code demonstrate how to setup Azure Redis Cache monitors
variable "cache" {
description = "The Azure Redis Cache alerts"
default = {
cache_name = "<replace this with cache name>"
service_name = "<replace this project name>"
environment = "<Stage/Production>"
scope = "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.Cache/Redis/<azure_redis_cache_name>"
cache_hit_threshold = 5000
cache_misses_threshold = 5000
cache_cpu_threshold = 50
cache_connected_clients_threshold = 5000
}
}
#============================================================================
provider "azurerm" {
version = "=2.0.0"
features {}
}
resource "azurerm_monitor_action_group" "main" {
name = "example-actiongroup"
resource_group_name = azurerm_resource_group.main.name
short_name = "exampleact"
email_receiver {
name = "ishantdevops"
email_address = "devops@example.com"
use_common_alert_schema = true
}
webhook_receiver {
name = "callmyapi"
service_uri = "http://example.com/alert"
}
}
### Cache Hits Alert
resource "azurerm_monitor_metric_alert" "cache_hit_alert" {
name = "${var.cache.service_name} ${var.cache.environment} - Cache Hits Alert"
resource_group_name = var.cache.cache_name
scopes = [var.cache.scope]
description = "${var.cache.service_name} Cache Hits Alert"
criteria {
metric_namespace = "Microsoft.Cache/redis"
metric_name = "cachehits"
aggregation = "Total"
operator = "GreaterThan"
threshold = var.cache.cache_hit_threshold
}
action {
action_group_id = azurerm_monitor_action_group.main.id
}
}
### Cache Misses Alert
resource "azurerm_monitor_metric_alert" "cache_miss_alert" {
name = "${var.cache.service_name} ${var.cache.environment} - Cache Miss Alert"
resource_group_name = var.cache.cache_name
scopes = [var.cache.scope]
description = "${var.cache.service_name} - Cache Miss Alert"
criteria {
metric_namespace = "Microsoft.Cache/redis"
metric_name = "cachemisses"
aggregation = "Total"
operator = "GreaterThan"
threshold = var.cache.cache_misses_threshold
}
action {
action_group_id = azurerm_monitor_action_group.main.id
}
}
### Cache Connection Alert
resource "azurerm_monitor_metric_alert" "cache_connected_clients" {
name = "${var.cache.service_name} ${var.cache.environment} - Cache Connected Clients"
resource_group_name = var.cache.cache_name
scopes = [var.cache.scope]
description = "${var.cache.service_name} - Cache Connected Clients"
criteria {
metric_namespace = "Microsoft.Cache/redis"
metric_name = "connectedclients"
aggregation = "Total"
operator = "GreaterThan"
threshold = var.cache.cache_connected_clients_threshold
}
action {
action_group_id = azurerm_monitor_action_group.main.id
}
}
### Cache CPU Alert
resource "azurerm_monitor_metric_alert" "cache_cpu" {
name = "${var.cache.service_name} ${var.cache.environment} - Cache CPU"
resource_group_name = var.cache.cache_name
scopes = [var.cache.scope]
description = "${var.cache.service_name} - Cache CPU"
criteria {
metric_namespace = "Microsoft.Cache/redis"
metric_name = "percentProcessorTime"
aggregation = "Total"
operator = "GreaterThan"
threshold = var.cache.cache_cpu_threshold
}
action {
action_group_id = azurerm_monitor_action_group.main.id
}
}
#==================Log Analytics for AKS==============================
resource "azurerm_resource_group" "example" {
name = "${var.prefix}-k8s-resources"
location = var.location
}
resource "azurerm_log_analytics_workspace" "example" {
name = "${var.prefix}-law"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku = "PerGB2018"
}
resource "azurerm_log_analytics_solution" "example" {
solution_name = "Containers"
workspace_resource_id = azurerm_log_analytics_workspace.example.id
workspace_name = azurerm_log_analytics_workspace.example.name
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
plan {
publisher = "Microsoft"
product = "OMSGallery/Containers"
}
}
resource "azurerm_kubernetes_cluster" "example" {
name = "${var.prefix}-k8s"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dns_prefix = "${var.prefix}-k8s"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
addon_profile {
aci_connector_linux {
enabled = false
}
azure_policy {
enabled = false
}
http_application_routing {
enabled = false
}
kube_dashboard {
enabled = true
}
oms_agent {
enabled = true
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
}
}
}