Skip to content

Commit

Permalink
fix: adjust cpu widget
Browse files Browse the repository at this point in the history
  • Loading branch information
aramkarapetian committed Oct 5, 2023
1 parent ee05683 commit 3fedbd9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
**/builds/*

# .tfstate files
*.tfstate
*.tfstate.*
**/*.tfstate
**/*.tfstate.*

# Crash log files
crash.log
Expand All @@ -29,6 +29,7 @@ override.tf.json
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

.DS_Store
**/.DS_Store

.terraform.lock.hcl
**/.terraform.lock.hcl
**/.terraform
2 changes: 1 addition & 1 deletion modules/dashboard/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ locals {
widget_default_values = merge(
{
region = "eu-central-1"
period = 300
period = 60
stat = "Sum"
namespace = "default"
width = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ locals {
anomaly_detection_metrics = [for index, row in local.metrics_with_defaults : try(row.anomaly_detection, false) ? [{
expression = "ANOMALY_DETECTION_BAND(m${index + 1}, 2)"
id = "ad${index + 1}"
label = "anomaly_detection (${row.MetricName})"
label = "Anomaly Band"
}] : [] if try(row.anomaly_detection, false)]


Expand Down
4 changes: 2 additions & 2 deletions modules/dashboard/modules/widgets/container/cpu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ No requirements.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | n/a | `string` | `null` | no |
| <a name="input_anomaly_detection"></a> [anomaly\_detection](#input\_anomaly\_detection) | Allow to enable anomaly detection on widget metrics | `bool` | `false` | no |
| <a name="input_anomaly_detection"></a> [anomaly\_detection](#input\_anomaly\_detection) | Allow to enable anomaly detection on widget metrics | `bool` | `true` | no |
| <a name="input_cluster"></a> [cluster](#input\_cluster) | n/a | `string` | n/a | yes |
| <a name="input_container"></a> [container](#input\_container) | n/a | `string` | n/a | yes |
| <a name="input_coordinates"></a> [coordinates](#input\_coordinates) | position | <pre>object({<br> x : number<br> y : number<br> width : number<br> height : number<br> })</pre> | n/a | yes |
| <a name="input_data_source_uid"></a> [data\_source\_uid](#input\_data\_source\_uid) | The grafana dashboard widget item data source id | `string` | n/a | yes |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | n/a | `string` | `"default"` | no |
| <a name="input_period"></a> [period](#input\_period) | stats | `number` | `300` | no |
| <a name="input_period"></a> [period](#input\_period) | stats | `number` | `60` | no |
| <a name="input_platform"></a> [platform](#input\_platform) | The platform/service/adapter to create dashboard on. for now only cloudwatch and grafana supported | `string` | `"cloudwatch"` | no |

## Outputs
Expand Down
17 changes: 8 additions & 9 deletions modules/dashboard/modules/widgets/container/cpu/base.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ module "base" {

coordinates = var.coordinates

name = "CPU / ${var.container}"
name = "CPU"

defaults = {
MetricNamespace = "ContainerInsights"
ClusterName = var.cluster
Namespace = var.namespace
PodName = var.container
accountId = var.account_id
anomaly_detection = var.anomaly_detection
MetricNamespace = "ContainerInsights"
ClusterName = var.cluster
Namespace = var.namespace
PodName = var.container
accountId = var.account_id
}

period = var.period

metrics = [
{ MetricName = "pod_cpu_usage_total", label = "Current" },
{ MetricName = "pod_cpu_limit", color = "#d62728", label = "Limit" }
{ MetricName = "pod_cpu_limit", color = "#FF0F3C", label = "Limit" },
{ MetricName = "pod_cpu_usage_total", color = "#007CEF", label = "Current", anomaly_detection = true }
]
}
4 changes: 2 additions & 2 deletions modules/dashboard/modules/widgets/container/cpu/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ variable "coordinates" {
# stats
variable "period" {
type = number
default = 300
default = 60
}

variable "anomaly_detection" {
type = bool
default = false
default = true
description = "Allow to enable anomaly detection on widget metrics"
}
3 changes: 1 addition & 2 deletions modules/dashboard/widgets-container.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ module "container_cpu_widget" {
cluster = local.container_cpu[count.index].cluster
namespace = local.container_cpu[count.index].namespace

account_id = try(local.container_cpu[count.index].accountId, data.aws_caller_identity.project.account_id)
anomaly_detection = try(local.container_cpu[count.index].anomaly_detection, false)
account_id = try(local.container_cpu[count.index].accountId, data.aws_caller_identity.project.account_id)
}

module "container_memory_widget" {
Expand Down

0 comments on commit 3fedbd9

Please sign in to comment.