From 881ea6742c82358b943c479c3eb96af47fbbee21 Mon Sep 17 00:00:00 2001 From: Benjamin DUPUIS Date: Fri, 16 Feb 2024 10:46:23 +0100 Subject: [PATCH] Add hostmetrics/process --- docs/severity.md | 8 ++ modules/hostmetrics-process/README.md | 114 ++++++++++++++++++ modules/hostmetrics-process/common-filters.tf | 1 + modules/hostmetrics-process/common-locals.tf | 1 + modules/hostmetrics-process/common-modules.tf | 1 + .../hostmetrics-process/common-variables.tf | 1 + .../hostmetrics-process/common-versions.tf | 1 + .../conf/00-heartbeat.yaml | 13 ++ modules/hostmetrics-process/conf/readme.yaml | 14 +++ modules/hostmetrics-process/detectors-gen.tf | 28 +++++ modules/hostmetrics-process/outputs.tf | 5 + modules/hostmetrics-process/tags.tf | 3 + modules/hostmetrics-process/variables-gen.tf | 44 +++++++ 13 files changed, 234 insertions(+) create mode 100644 modules/hostmetrics-process/README.md create mode 120000 modules/hostmetrics-process/common-filters.tf create mode 120000 modules/hostmetrics-process/common-locals.tf create mode 120000 modules/hostmetrics-process/common-modules.tf create mode 120000 modules/hostmetrics-process/common-variables.tf create mode 120000 modules/hostmetrics-process/common-versions.tf create mode 100644 modules/hostmetrics-process/conf/00-heartbeat.yaml create mode 100644 modules/hostmetrics-process/conf/readme.yaml create mode 100644 modules/hostmetrics-process/detectors-gen.tf create mode 100644 modules/hostmetrics-process/outputs.tf create mode 100644 modules/hostmetrics-process/tags.tf create mode 100644 modules/hostmetrics-process/variables-gen.tf diff --git a/docs/severity.md b/docs/severity.md index 7b69755a7..88d9f02ce 100644 --- a/docs/severity.md +++ b/docs/severity.md @@ -10,6 +10,7 @@ - [fame_azure-update-center](#fame_azure-update-center) - [fame_azure-vm-backup](#fame_azure-vm-backup) - [fame_azure-vpn](#fame_azure-vpn) +- [hostmetrics-process](#hostmetrics-process) - [integration_aws-alb](#integration_aws-alb) - [integration_aws-amazonmq-rabbitmq](#integration_aws-amazonmq-rabbitmq) - [integration_aws-apigateway](#integration_aws-apigateway) @@ -174,6 +175,13 @@ |Azure VPN total flow count|X|-|-|-|-| +## hostmetrics-process + +|Detector|Critical|Major|Minor|Warning|Info| +|---|---|---|---|---|---| +|Process heartbeat|X|-|-|-|-| + + ## integration_aws-alb |Detector|Critical|Major|Minor|Warning|Info| diff --git a/modules/hostmetrics-process/README.md b/modules/hostmetrics-process/README.md new file mode 100644 index 000000000..6f6f046f4 --- /dev/null +++ b/modules/hostmetrics-process/README.md @@ -0,0 +1,114 @@ +# HOSTMETRICS-PROCESS SignalFx detectors + + + +:link: **Contents** + +- [How to use this module?](#how-to-use-this-module) +- [What are the available detectors in this module?](#what-are-the-available-detectors-in-this-module) +- [How to collect required metrics?](#how-to-collect-required-metrics) + - [Metrics](#metrics) +- [Notes](#notes) +- [Related documentation](#related-documentation) + + + +## How to use this module? + +This directory defines a [Terraform](https://www.terraform.io/) +[module](https://www.terraform.io/language/modules/syntax) you can use in your +existing [stack](https://github.com/claranet/terraform-signalfx-detectors/wiki/Getting-started#stack) by adding a +`module` configuration and setting its `source` parameter to URL of this folder: + +```hcl +module "signalfx-detectors-hostmetrics-process" { + source = "github.com/claranet/terraform-signalfx-detectors.git//modules/hostmetrics-process?ref={revision}" + + environment = var.environment + notifications = local.notifications +} +``` + +Note the following parameters: + +* `source`: Use this parameter to specify the URL of the module. The double slash (`//`) is intentional and required. + Terraform uses it to specify subfolders within a Git repo (see [module + sources](https://www.terraform.io/language/modules/sources)). The `ref` parameter specifies a specific Git tag in + this repository. It is recommended to use the latest "pinned" version in place of `{revision}`. Avoid using a branch + like `master` except for testing purpose. Note that every modules in this repository are available on the Terraform + [registry](https://registry.terraform.io/modules/claranet/detectors/signalfx) and we recommend using it as source + instead of `git` which is more flexible but less future-proof. + +* `environment`: Use this parameter to specify the + [environment](https://github.com/claranet/terraform-signalfx-detectors/wiki/Getting-started#environment) used by this + instance of the module. + Its value will be added to the `prefixes` list at the start of the [detector + name](https://github.com/claranet/terraform-signalfx-detectors/wiki/Templating#example). + In general, it will also be used in the `filtering` internal sub-module to [apply + filters](https://github.com/claranet/terraform-signalfx-detectors/wiki/Guidance#filtering) based on our default + [tagging convention](https://github.com/claranet/terraform-signalfx-detectors/wiki/Tagging-convention) by default. + +* `notifications`: Use this parameter to define where alerts should be sent depending on their severity. It consists + of a Terraform [object](https://www.terraform.io/language/expressions/type-constraints#object) where each key represents an available + [detector rule severity](https://docs.splunk.com/observability/alerts-detectors-notifications/create-detectors-for-alerts.html#severity) + and its value is a list of recipients. Every recipients must respect the [detector notification + format](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs/resources/detector#notification-format). + Check the [notification binding](https://github.com/claranet/terraform-signalfx-detectors/wiki/Notifications-binding) + documentation to understand the recommended role of each severity. + +These 3 parameters along with all variables defined in [common-variables.tf](common-variables.tf) are common to all +[modules](../) in this repository. Other variables, specific to this module, are available in +[variables-gen.tf](variables-gen.tf). +In general, the default configuration "works" but all of these Terraform +[variables](https://www.terraform.io/language/values/variables) make it possible to +customize the detectors behavior to better fit your needs. + +Most of them represent usual tips and rules detailed in the +[guidance](https://github.com/claranet/terraform-signalfx-detectors/wiki/Guidance) documentation and listed in the +common [variables](https://github.com/claranet/terraform-signalfx-detectors/wiki/Variables) dedicated documentation. + +Feel free to explore the [wiki](https://github.com/claranet/terraform-signalfx-detectors/wiki) for more information about +general usage of this repository. + +## What are the available detectors in this module? + +This module creates the following SignalFx detectors which could contain one or multiple alerting rules: + +|Detector|Critical|Major|Minor|Warning|Info| +|---|---|---|---|---|---| +|Process heartbeat|X|-|-|-|-| + +## How to collect required metrics? + +This module deploys detectors using metrics reported by the +[Splunk Observability organization](https://docs.splunk.com/Observability/admin/org-metrics.html) always available out the box. + +Check the [Related documentation](#related-documentation) section for more detailed and specific information about this module dependencies. + + + +### Metrics + + +Here is the list of required metrics for detectors in this module. + +* `process.cpu.time` + + +## Notes + +By default, only `critical` rule is enabled. This allows the detector to check if the service has, at least, +one process running. + +Optionally, this is possible to enable `warning` rule to check if the service has a minimal amount of process +running (i.e. I need 5 "foo" processes for my api to run correctly, so I will update +`processes_threshold_warning` to `5` and `processes_disabled_warning` to `null`). + + +## Related documentation + +* [Terraform SignalFx provider](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs) +* [Terraform SignalFx detector](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs/resources/detector) +* [Splunk Observability integrations](https://docs.splunk.com/Observability/gdi/get-data-in/integrations.html) +* [Host metrics receiver](https://docs.splunk.com/observability/en/gdi/opentelemetry/components/host-metrics-receiver.html#process) +* [Splunk Observability integration](https://docs.splunk.com/Observability/gdi/processes/processes.html) diff --git a/modules/hostmetrics-process/common-filters.tf b/modules/hostmetrics-process/common-filters.tf new file mode 120000 index 000000000..4df54e41e --- /dev/null +++ b/modules/hostmetrics-process/common-filters.tf @@ -0,0 +1 @@ +../../common/module/filters-smart-agent.tf \ No newline at end of file diff --git a/modules/hostmetrics-process/common-locals.tf b/modules/hostmetrics-process/common-locals.tf new file mode 120000 index 000000000..5672d21ab --- /dev/null +++ b/modules/hostmetrics-process/common-locals.tf @@ -0,0 +1 @@ +../../common/module/locals.tf \ No newline at end of file diff --git a/modules/hostmetrics-process/common-modules.tf b/modules/hostmetrics-process/common-modules.tf new file mode 120000 index 000000000..8c81ef377 --- /dev/null +++ b/modules/hostmetrics-process/common-modules.tf @@ -0,0 +1 @@ +../../common/module/modules.tf \ No newline at end of file diff --git a/modules/hostmetrics-process/common-variables.tf b/modules/hostmetrics-process/common-variables.tf new file mode 120000 index 000000000..f3037a584 --- /dev/null +++ b/modules/hostmetrics-process/common-variables.tf @@ -0,0 +1 @@ +../../common/module/variables.tf \ No newline at end of file diff --git a/modules/hostmetrics-process/common-versions.tf b/modules/hostmetrics-process/common-versions.tf new file mode 120000 index 000000000..fa7f5509f --- /dev/null +++ b/modules/hostmetrics-process/common-versions.tf @@ -0,0 +1 @@ +../../common/module/versions.tf \ No newline at end of file diff --git a/modules/hostmetrics-process/conf/00-heartbeat.yaml b/modules/hostmetrics-process/conf/00-heartbeat.yaml new file mode 100644 index 000000000..a716564fd --- /dev/null +++ b/modules/hostmetrics-process/conf/00-heartbeat.yaml @@ -0,0 +1,13 @@ +--- +module: process +name: heartbeat + +transformation: false +aggregation: true +exclude_not_running_vm: true + +signals: + signal: + metric: process.cpu.time +rules: + critical: diff --git a/modules/hostmetrics-process/conf/readme.yaml b/modules/hostmetrics-process/conf/readme.yaml new file mode 100644 index 000000000..28ddf46a9 --- /dev/null +++ b/modules/hostmetrics-process/conf/readme.yaml @@ -0,0 +1,14 @@ +--- +documentations: + - name: Host metrics receiver + url: 'https://docs.splunk.com/observability/en/gdi/opentelemetry/components/host-metrics-receiver.html#process' + - name: Splunk Observability integration + url: 'https://docs.splunk.com/Observability/gdi/processes/processes.html' + +notes: | + By default, only `critical` rule is enabled. This allows the detector to check if the service has, at least, + one process running. + + Optionally, this is possible to enable `warning` rule to check if the service has a minimal amount of process + running (i.e. I need 5 "foo" processes for my api to run correctly, so I will update + `processes_threshold_warning` to `5` and `processes_disabled_warning` to `null`). diff --git a/modules/hostmetrics-process/detectors-gen.tf b/modules/hostmetrics-process/detectors-gen.tf new file mode 100644 index 000000000..af01fe16d --- /dev/null +++ b/modules/hostmetrics-process/detectors-gen.tf @@ -0,0 +1,28 @@ +resource "signalfx_detector" "heartbeat" { + name = format("%s %s", local.detector_name_prefix, "Process heartbeat") + + authorized_writer_teams = var.authorized_writer_teams + teams = try(coalescelist(var.teams, var.authorized_writer_teams), null) + tags = compact(concat(local.common_tags, local.tags, var.extra_tags)) + + program_text = <<-EOF + from signalfx.detectors.not_reporting import not_reporting + signal = data('process.cpu.time', filter=${local.not_running_vm_filters} and ${module.filtering.signalflow})${var.heartbeat_aggregation_function}.publish('signal') + not_reporting.detector(stream=signal, resource_identifier=None, duration='${var.heartbeat_timeframe}', auto_resolve_after='${local.heartbeat_auto_resolve_after}').publish('CRIT') +EOF + + rule { + description = "has not reported in ${var.heartbeat_timeframe}" + severity = "Critical" + detect_label = "CRIT" + disabled = coalesce(var.heartbeat_disabled, var.detectors_disabled) + notifications = try(coalescelist(lookup(var.heartbeat_notifications, "critical", []), var.notifications.critical), null) + runbook_url = try(coalesce(var.heartbeat_runbook_url, var.runbook_url), "") + tip = var.heartbeat_tip + parameterized_subject = var.message_subject == "" ? local.rule_subject_novalue : var.message_subject + parameterized_body = var.message_body == "" ? local.rule_body : var.message_body + } + + max_delay = var.heartbeat_max_delay +} + diff --git a/modules/hostmetrics-process/outputs.tf b/modules/hostmetrics-process/outputs.tf new file mode 100644 index 000000000..606361b57 --- /dev/null +++ b/modules/hostmetrics-process/outputs.tf @@ -0,0 +1,5 @@ +output "heartbeat" { + description = "Detector resource for heartbeat" + value = signalfx_detector.heartbeat +} + diff --git a/modules/hostmetrics-process/tags.tf b/modules/hostmetrics-process/tags.tf new file mode 100644 index 000000000..9a8206e37 --- /dev/null +++ b/modules/hostmetrics-process/tags.tf @@ -0,0 +1,3 @@ +locals { + tags = ["smart-agent", "processes"] +} diff --git a/modules/hostmetrics-process/variables-gen.tf b/modules/hostmetrics-process/variables-gen.tf new file mode 100644 index 000000000..34952ffb6 --- /dev/null +++ b/modules/hostmetrics-process/variables-gen.tf @@ -0,0 +1,44 @@ +# heartbeat detector + +variable "heartbeat_notifications" { + description = "Notification recipients list per severity overridden for heartbeat detector" + type = map(list(string)) + default = {} +} + +variable "heartbeat_aggregation_function" { + description = "Aggregation function and group by for heartbeat detector (i.e. \".mean(by=['host'])\")" + type = string + default = "" +} + +variable "heartbeat_max_delay" { + description = "Enforce max delay for heartbeat detector (use \"0\" or \"null\" for \"Auto\")" + type = number + default = 900 +} + +variable "heartbeat_tip" { + description = "Suggested first course of action or any note useful for incident handling" + type = string + default = "" +} + +variable "heartbeat_runbook_url" { + description = "URL like SignalFx dashboard or wiki page which can help to troubleshoot the incident cause" + type = string + default = "" +} + +variable "heartbeat_disabled" { + description = "Disable all alerting rules for heartbeat detector" + type = bool + default = null +} + +variable "heartbeat_timeframe" { + description = "Timeframe for heartbeat detector (i.e. \"10m\")" + type = string + default = "10m" +} +