|
| 1 | +locals { |
| 2 | + # Define common scope as a local variable |
| 3 | + common_scope = [ |
| 4 | + { |
| 5 | + label = "kube_cluster_name" |
| 6 | + operator = "equals" |
| 7 | + values = ["gold"] |
| 8 | + }, |
| 9 | + { |
| 10 | + label = "kube_namespace_name" |
| 11 | + operator = "equals" |
| 12 | + values = ["abc123-dev"] |
| 13 | + }, |
| 14 | + { |
| 15 | + label = "kube_deployment_name" |
| 16 | + operator = "equals" |
| 17 | + values = ["project-wordpress"] |
| 18 | + } |
| 19 | + ] |
| 20 | + |
| 21 | + # Define environments |
| 22 | + environments = { |
| 23 | + dev = "abc123-dev" |
| 24 | + test = "abc123-test" |
| 25 | + prod = "abc123-prod" |
| 26 | + } |
| 27 | + |
| 28 | + # Define pod metrics |
| 29 | + pod_metrics = { |
| 30 | + "Pod CPU Usage" = { |
| 31 | + metric = "sysdig_program_cpu_cores_used_percent" |
| 32 | + description = "Alert when 'sysdig_program_cpu_cores_used_percent' exceeds threshold" |
| 33 | + enabled = true |
| 34 | + severity = "high" |
| 35 | + group_aggregation = "avg" |
| 36 | + time_aggregation = "avg" |
| 37 | + operator = ">" |
| 38 | + threshold = 80 |
| 39 | + notification_subject = "Pod CPU Usage Alert Status" |
| 40 | + range_seconds = 60 |
| 41 | + } |
| 42 | + |
| 43 | + "Pod Memory Usage" = { |
| 44 | + metric = "sysdig_program_memory_used_percent" |
| 45 | + description = "Alert when 'sysdig_program_memory_used_percent' exceeds threshold" |
| 46 | + enabled = true |
| 47 | + severity = "high" |
| 48 | + group_aggregation = "avg" |
| 49 | + time_aggregation = "avg" |
| 50 | + operator = ">" |
| 51 | + threshold = 80 |
| 52 | + notification_subject = "Pod Memory Usage Alert Status" |
| 53 | + range_seconds = 60 |
| 54 | + } |
| 55 | + |
| 56 | + "Pod Restarts" = { |
| 57 | + metric = "kube_pod_sysdig_restart_count" |
| 58 | + description = "Alert when 'kube_pod_sysdig_restart_count' exceeds threshold" |
| 59 | + enabled = true |
| 60 | + severity = "high" |
| 61 | + group_aggregation = "max" |
| 62 | + time_aggregation = "avg" |
| 63 | + operator = ">" |
| 64 | + threshold = 5 |
| 65 | + notification_subject = "Pod Restart Alert Status" |
| 66 | + range_seconds = 300 |
| 67 | + } |
| 68 | + |
| 69 | + "HTTP Error Count" = { |
| 70 | + metric = "sysdig_container_net_http_error_count" |
| 71 | + description = "Alert when 'sysdig_container_net_http_error_count' exceeds the threshold" |
| 72 | + enabled = true |
| 73 | + severity = "high" |
| 74 | + group_aggregation = "avg" |
| 75 | + time_aggregation = "avg" |
| 76 | + operator = ">" |
| 77 | + threshold = 25 |
| 78 | + notification_subject = "Pod HTTP Error Count Alert" |
| 79 | + range_seconds = 300 |
| 80 | + } |
| 81 | + |
| 82 | + "Replica Count Below Minimum" = { |
| 83 | + metric = "kube_deployment_status_replicas" |
| 84 | + description = "Alert when 'kube_deployment_status_replicas' falls below the threshold" |
| 85 | + enabled = true |
| 86 | + severity = "high" |
| 87 | + group_aggregation = "avg" |
| 88 | + time_aggregation = "avg" |
| 89 | + operator = "<" |
| 90 | + threshold = 3 |
| 91 | + notification_subject = "Replica Count Alert" |
| 92 | + range_seconds = 60 |
| 93 | + } |
| 94 | + |
| 95 | + "Pod Ready Status" = { |
| 96 | + metric = "kube_pod_sysdig_status_ready" |
| 97 | + description = "Alert when 'kube_pod_sysdig_status_ready' falls below the threshold" |
| 98 | + enabled = true |
| 99 | + severity = "high" |
| 100 | + group_aggregation = "avg" |
| 101 | + time_aggregation = "avg" |
| 102 | + operator = "<" |
| 103 | + threshold = 1 |
| 104 | + notification_subject = "Pod Ready Status Alert" |
| 105 | + range_seconds = 60 |
| 106 | + } |
| 107 | + |
| 108 | + "Pod Unready Status" = { |
| 109 | + metric = "kube_pod_sysdig_status_ready" |
| 110 | + description = "Alert when 'kube_pod_sysdig_status_ready' is unready for more than 5 minutes" |
| 111 | + enabled = true |
| 112 | + severity = "high" |
| 113 | + group_aggregation = "avg" |
| 114 | + time_aggregation = "avg" |
| 115 | + operator = "<" |
| 116 | + threshold = 1 |
| 117 | + notification_subject = "Pod Unready Status Alert" |
| 118 | + range_seconds = 300 |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + all_metrics = merge([ |
| 123 | + for env, ns in local.environments : { |
| 124 | + for metric_name, metric_info in local.pod_metrics : "${env}-${metric_name}" => { |
| 125 | + name = "${env} - ${metric_name}" |
| 126 | + namespace_name = ns |
| 127 | + metric = metric_info.metric |
| 128 | + description = metric_info.description |
| 129 | + enabled = metric_info.enabled |
| 130 | + severity = metric_info.severity |
| 131 | + group_aggregation = metric_info.group_aggregation |
| 132 | + time_aggregation = metric_info.time_aggregation |
| 133 | + operator = metric_info.operator |
| 134 | + threshold = metric_info.threshold |
| 135 | + notification_subject = metric_info.notification_subject |
| 136 | + range_seconds = metric_info.range_seconds |
| 137 | + } |
| 138 | + } |
| 139 | + ]...) |
| 140 | + |
| 141 | +} |
0 commit comments