From e4af2a9887e573a510ad2d7ece87bb0c7f130c08 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Tue, 10 Dec 2024 15:17:20 +0100 Subject: [PATCH 1/4] Work on monitoring module --- monitoring/README.md | 72 ++++++++++++++++++++++++++++++++++++++++++ monitoring/main.tf | 75 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 monitoring/README.md create mode 100644 monitoring/main.tf diff --git a/monitoring/README.md b/monitoring/README.md new file mode 100644 index 00000000..aec8e99e --- /dev/null +++ b/monitoring/README.md @@ -0,0 +1,72 @@ +--- +display_name: Monitoring +description: Monitoring of workspace resources +maintainer_github: coder +verified: true +tags: [monitoring] +--- + +# Monitoring + +This module adds monitoring of workspace resources. + +```tf +module "monitoring" { + source = "registry.coder.com/modules/monitoring/coder" + version = "1.0.0" + agent_id = coder_agent.dev.id +} +``` + +## Examples + +```tf +module "monitoring" { + source = "registry.coder.com/modules/monitoring/coder" + version = "1.0.0" + agent_id = coder_agent.dev.id +} +``` + +### Enable/Disable + +You can customize the monitoring by setting the `enabled`, `memory_enabled`, and `disk_enabled` variables. + +```tf +module "monitoring" { + source = "registry.coder.com/modules/monitoring/coder" + version = "1.0.0" + agent_id = coder_agent.dev.id + enabled = false + memory_enabled = true + disk_enabled = false +} +``` + +### Customize Thresholds + +You can customize the thresholds by setting the `threshold`, `memory_threshold`, and `disk_threshold` variables. + +```tf +module "monitoring" { + source = "registry.coder.com/modules/monitoring/coder" + version = "1.0.0" + agent_id = coder_agent.dev.id + threshold = 90 + memory_threshold = 95 + disk_threshold = 90 +} +``` + +### Customize Disks + +You can customize the disks by setting the `disks` variable. + +```tf +module "monitoring" { + source = "registry.coder.com/modules/monitoring/coder" + version = "1.0.0" + agent_id = coder_agent.dev.id + disks = ["/"] +} +``` \ No newline at end of file diff --git a/monitoring/main.tf b/monitoring/main.tf new file mode 100644 index 00000000..47fff0c1 --- /dev/null +++ b/monitoring/main.tf @@ -0,0 +1,75 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + coder = { + source = "coder/coder" + version = ">= 0.11" + } + } +} + +variable "description" { + default = "Monitoring of workspace resources" + description = "Monitoring of workspace resources" +} + +variable "threshold" { + type = number + description = "The threshold for the monitoring, used for all resources unless overridden by *_threshold." + default = 90 +} + +variable "memory_threshold" { + type = number + description = "The threshold for the memory monitoring." + default = 90 +} + +variable "disk_threshold" { + type = number + description = "The threshold for the disk monitoring." + default = 90 +} + +variable "disks" { + type = list(string) + description = "The disks to monitor." + default = ["/"] +} + +variable "enabled" { + type = bool + description = "Whether the monitoring is enabled." + default = true +} + +variable "memory_enabled" { + type = bool + description = "Whether the memory monitoring is enabled." + default = false +} + +variable "disk_enabled" { + type = bool + description = "Whether the disk monitoring is enabled." + default = true +} + +variable "agent_id" { + type = string + description = "The ID of the agent to monitor." +} + +data "coder_monitoring" "resources" { + name = "monitoring" + description = var.description + threshold = var.threshold + memory_threshold = var.memory_threshold + disk_threshold = var.disk_threshold + disks = var.disks + enabled = var.enabled + memory_enabled = var.memory_enabled + disk_enabled = var.disk_enabled + agent_id = var.agent_id +} \ No newline at end of file From 84bf63705f015928585f24de39ba46089148c758 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Tue, 10 Dec 2024 15:21:20 +0100 Subject: [PATCH 2/4] Work on monitoring module --- monitoring/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitoring/main.tf b/monitoring/main.tf index 47fff0c1..efbf34f4 100644 --- a/monitoring/main.tf +++ b/monitoring/main.tf @@ -61,7 +61,7 @@ variable "agent_id" { description = "The ID of the agent to monitor." } -data "coder_monitoring" "resources" { +data "coder_monitoring" "monitoring" { name = "monitoring" description = var.description threshold = var.threshold From 9c049bd555893a72975e154d139ce8835686edd3 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Tue, 10 Dec 2024 15:39:53 +0100 Subject: [PATCH 3/4] improve desription and default values --- monitoring/main.tf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/monitoring/main.tf b/monitoring/main.tf index efbf34f4..070878e9 100644 --- a/monitoring/main.tf +++ b/monitoring/main.tf @@ -16,25 +16,25 @@ variable "description" { variable "threshold" { type = number - description = "The threshold for the monitoring, used for all resources unless overridden by *_threshold." + description = "The threshold for the monitoring, used for all resources unless overridden by *_threshold - expressed as a percentage." default = 90 } variable "memory_threshold" { type = number - description = "The threshold for the memory monitoring." + description = "The threshold for the memory monitoring - expressed as a percentage." default = 90 } variable "disk_threshold" { type = number - description = "The threshold for the disk monitoring." + description = "The threshold for the disk monitoring - expressed as a percentage." default = 90 } variable "disks" { type = list(string) - description = "The disks to monitor." + description = "The disks to monitor. e.g. ['/', '/home']" default = ["/"] } @@ -47,7 +47,7 @@ variable "enabled" { variable "memory_enabled" { type = bool description = "Whether the memory monitoring is enabled." - default = false + default = true } variable "disk_enabled" { From 1a101ecc10a257482f69fbd74e952b94b465016a Mon Sep 17 00:00:00 2001 From: defelmnq Date: Tue, 10 Dec 2024 15:42:02 +0100 Subject: [PATCH 4/4] improve versions set --- monitoring/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/main.tf b/monitoring/main.tf index 070878e9..112872e9 100644 --- a/monitoring/main.tf +++ b/monitoring/main.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 1.0" + required_version = ">= 1.0.25" required_providers { coder = { source = "coder/coder" - version = ">= 0.11" + version = ">= 2.0.2" } } }