Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus exporter couchdb #539

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/severity.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
- [organization_usage](#organization_usage)
- [otel-collector_kubernetes-common](#otel-collector_kubernetes-common)
- [prometheus-exporter_active-directory](#prometheus-exporter_active-directory)
- [prometheus-exporter_couchdb](#prometheus-exporter_couchdb)
- [prometheus-exporter_docker-state](#prometheus-exporter_docker-state)
- [prometheus-exporter_kong](#prometheus-exporter_kong)
- [prometheus-exporter_oracledb](#prometheus-exporter_oracledb)
Expand Down
157 changes: 157 additions & 0 deletions modules/prometheus-exporter_couchdb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# COUCHDB SignalFx detectors

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
: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)
- [Examples](#examples)
- [Metrics](#metrics)
- [Related documentation](#related-documentation)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## 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-prometheus-exporter-couchdb" {
source = "github.com/hlepesant/terraform-signalfx-detectors.git//modules/prometheus-exporter_couchdb?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 alongs 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 detailled 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|
|---|---|---|---|---|---|
|Couchdb heartbeat|X|-|-|-|-|
|Couchdb couchdb_httpd_status_code_4xx|X|X|-|-|-|
|Couchdb couchdb_auth_cache|X|X|-|-|-|
|Couchdb couchdb_couch_replicator_jobs|X|X|-|-|-|
|Couchdb couchdb_erlang_processes|X|X|-|-|-|
|Couchdb cluster_is_stable|X|-|-|-|-|

## How to collect required metrics?

This module deploys detectors using metrics reported by the
scraping of a server following the [OpenMetrics convention](https://openmetrics.io/) based on and compatible with [the Prometheus
exposition format](https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md#openmetrics-text-format).

They are generally called `Prometheus Exporters` which can be fetched by both the [SignalFx Smart Agent](https://github.com/signalfx/signalfx-agent)
thanks to its [prometheus exporter monitor](https://github.com/signalfx/signalfx-agent/blob/main/docs/monitors/prometheus-exporter.md) and the
[OpenTelemetry Collector](https://github.com/signalfx/splunk-otel-collector) using its [prometheus
receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/prometheusreceiver) or its derivates.

These exporters could be embedded directly in the tool you want to monitor (e.g. nginx ingress) or must be installed next to it as
a separate program configured to connect, create metrics and expose them as server.


Check the [Related documentation](#related-documentation) section for more detailed and specific information about this module dependencies.

The detectors of this module uses metrics from the [embedded Couchdb exporter](https://docs.couchdb.org/en/stable/config/misc.html#configuration-of-prometheus-endpoint) for Prometheus.

### Examples

Sample OTEL Agent configuration.

```yaml
---
receivers:
prometheus:
config:
scrape_configs:
- job_name: "couchdb-prometheus"
scrape_interval: 60s
metrics_path: "/_node/_local/_prometheus"
basic_auth:
username: "{{ couchdb_admin_username }}"
password: "{{ couchdb_admin_password }}"
static_configs:
- targets: ["{{ inventory_hostname }}:5984"]
labels:
environment: "{{ splunk_otel_collector_env }}"
service:
pipelines:
metrics:
receivers:
- prometheus
...
```


### Metrics


Here is the list of required metrics for detectors in this module.

* `couchdb_auth_cache_misses_total`
* `couchdb_auth_cache_requests_total`
* `couchdb_couch_replicator_cluster_is_stable`
* `couchdb_couch_replicator_jobs_crashed`
* `couchdb_couch_replicator_jobs_total`
* `couchdb_erlang_processes`
* `couchdb_erlang_process_limit`
* `couchdb_httpd_status_codes`
* `couchdb_uptime_seconds`




## 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)
* [Configuration of Prometheus Endpoint in CouchDB](https://docs.couchdb.org/en/stable/config/misc.html#configuration-of-prometheus-endpoint)
4 changes: 4 additions & 0 deletions modules/prometheus-exporter_couchdb/common-filters.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
locals {
filters = "filter('env', '${var.environment}') and filter('sfx_monitored', 'true')"
}

44 changes: 44 additions & 0 deletions modules/prometheus-exporter_couchdb/common-locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
locals {
heartbeat_auto_resolve_after = "1s"
not_running_vm_filters_gcp = "(not filter('gcp_status', '{Code=3, Name=STOPPING}', '{Code=4, Name=TERMINATED}'))"
not_running_vm_filters_aws = "(not filter('aws_state', '{Code: 32,Name: shutting-down}', '{Code: 48,Name: terminated}', '{Code: 64,Name: stopping}', '{Code: 80,Name: stopped}'))"
not_running_vm_filters_azure = "(not filter('azure_power_state', 'PowerState/stopping', 'PowerState/stopped', 'PowerState/deallocating', 'PowerState/deallocated'))"
not_running_vm_filters = format(
"%s and %s and %s",
local.not_running_vm_filters_aws,
local.not_running_vm_filters_gcp,
local.not_running_vm_filters_azure
)
detector_name_prefix = "${join("", formatlist("[%s]", var.prefixes))}[${var.environment}]"
common_tags = concat(["terraform", var.environment], var.teams)
rule_subject_prefix = "[{{ruleSeverity}}]{{{detectorName}}} {{{readableRule}}}"
rule_subject_suffix = "on {{{dimensions}}}"
rule_subject = format("%s ({{inputs.signal.value}}) %s", local.rule_subject_prefix, local.rule_subject_suffix)
rule_subject_novalue = format("%s %s", local.rule_subject_prefix, local.rule_subject_suffix)
rule_body = <<-EOF
**Alert**:
*[{{ruleSeverity}}]{{{detectorName}}} {{{readableRule}}} ({{inputs.signal.value}})*
{{#if anomalous}}
**Triggered at**:
*{{timestamp}}*
{{else}}
**Cleared at**:
*{{timestamp}}*
{{/if}}

{{#notEmpty dimensions}}
**Dimensions**:
*{{{dimensions}}}*
{{/notEmpty}}

{{#if anomalous}}
{{#if runbookUrl}}**Runbook**:
Go to [this page]({{{runbookUrl}}}) for help and analysis.
{{/if}}

{{#if tip}}**Tip**:
{{{tip}}}
{{/if}}
{{/if}}
EOF
}
8 changes: 8 additions & 0 deletions modules/prometheus-exporter_couchdb/common-modules.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "filtering" {
source = "github.com/claranet/terraform-signalfx-detectors.git//modules/internal_filtering?ref=v1.26.0"

filtering_default = local.filters
filtering_custom = var.filtering_custom
append_mode = var.filtering_append
}

78 changes: 78 additions & 0 deletions modules/prometheus-exporter_couchdb/common-variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Global

variable "environment" {
description = "Infrastructure environment"
type = string
}

variable "notifications" {
description = "Default notification recipients list per severity"
type = object({
critical = list(string)
major = list(string)
minor = list(string)
warning = list(string)
info = list(string)
})
}

variable "prefixes" {
description = "Prefixes list to prepend between brackets on every monitors names before environment"
type = list(string)
default = []
}

variable "filtering_custom" {
description = "Filters as SignalFlow string to either replace or append to default filtering convention which is the only one used if not defined"
type = string
default = null
}

variable "filtering_append" {
description = "If true, the `filtering_custom` string will be appended to the default filtering convention instead of fully replace it"
type = bool
default = false
}

variable "detectors_disabled" {
description = "Disable all detectors in this module"
type = bool
default = false
}

variable "runbook_url" {
description = "Default runbook URL to apply to all detectors (if not overridden at detector level)"
type = string
default = ""
}

variable "authorized_writer_teams" {
description = "List of teams IDs authorized (with admins) to edit the detector. If defined, it requires an user token to work"
type = list(string)
default = null
}

variable "teams" {
description = "List of teams IDs to associate the detector to"
type = list(string)
default = []
}

variable "message_subject" {
description = "The subject to use in alerting rules messages which overrides the default template"
type = string
default = ""
}

variable "message_body" {
description = "The body to use in alerting rules messages which overrides the default template"
type = string
default = ""
}

variable "extra_tags" {
description = "List of tags to add to the detectors resources, useful to find detectors "
type = list(string)
default = []
}

9 changes: 9 additions & 0 deletions modules/prometheus-exporter_couchdb/common-versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
signalfx = {
source = "splunk-terraform/signalfx"
version = ">= 7.0.0"
}
}
required_version = ">= 0.12.26"
}
13 changes: 13 additions & 0 deletions modules/prometheus-exporter_couchdb/conf/00-heartbeat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Example
module: couchdb
name: heartbeat

transformation: false
aggregation: true
exclude_not_running_vm: true

signals:
signal:
metric: "couchdb_uptime_seconds"
rules:
critical:
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module: couchdb
name: couchdb_httpd_status_code_4xx

transformation: ".mean(over='10m')"
aggregation: ".sum(by=['sf_metric'])"

signals:
A:
metric: couchdb_httpd_status_codes
filter: "(filter('code', '400', '401', '403', '404', '405', '406', '409', '412', '413', '414', '415', '416', '417'))"
rollup: sum
B:
metric: couchdb_httpd_status_codes
rollup: sum
signal:
formula: ((A/B).scale(100))
rules:
critical:
threshold: 30
comparator: '>'
major:
threshold: 20
comparator: '>'
dependency: critical
21 changes: 21 additions & 0 deletions modules/prometheus-exporter_couchdb/conf/02-auth_cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module: couchdb
name: couchdb_auth_cache

transformation: ".mean(over='10m')"
aggregation: ".sum(by=['sf_metric'])"

signals:
misses_total:
metric: couchdb_auth_cache_misses_total
request_total:
metric: couchdb_auth_cache_requests_total
signal:
formula: ((misses_total/request_total).scale(100))
rules:
critical:
threshold: 10
comparator: '>'
major:
threshold: 5
comparator: '>'
dependency: critical
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module: couchdb
name: couchdb_couch_replicator_jobs

transformation: ".mean(over='10m')"
aggregation: ".sum(by=['sf_metric'])"

signals:
jobs_crashed:
metric: couchdb_couch_replicator_jobs_crashed
jobs_total:
metric: couchdb_couch_replicator_jobs_total
signal:
formula: ((jobs_crashed/jobs_total).scale(100))
rules:
critical:
threshold: 10
comparator: '>'
major:
threshold: 5
comparator: '>'
dependency: critical
Loading
Loading