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

PMM-1901 metrics endpoint and collectors filtering. #23

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,46 @@ scrape_configs:
- job_name: rds-basic
scrape_interval: 60s
scrape_timeout: 55s
metrics_path: /basic
honor_labels: true
static_configs:
- targets:
- 127.0.0.1:9042
params:
collect[]:
- basic

- job_name: rds-enhanced
scrape_interval: 10s
scrape_timeout: 9s
metrics_path: /enhanced
honor_labels: true
static_configs:
- targets:
- 127.0.0.1:9042
params:
collect[]:
- enhanced
```

`honor_labels: true` is important because exporter returns metrics with `instance` label set.

## Collectors

### Enabled by default

Name | Description
---------|-------------
basic | Basic metrics from https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MonitoringOverview.html#monitoring-cloudwatch.
enhanced | Enhanced metrics from https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.OS.html.

### Filtering enabled collectors

The `rds_exporter` will expose all metrics from enabled collectors by default.

For advanced use the `rds_exporter` can be passed an optional list of collectors to filter metrics. The `collect[]` parameter may be used multiple times. In Prometheus configuration you can use this syntax under the [scrape config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<scrape_config>).

```
params:
collect[]:
- basic
- enhanced
```
23 changes: 21 additions & 2 deletions basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/percona/rds_exporter/sessions"
)

//go:generate go run generate/main.go generate/utils.go

var (
scrapeTimeDesc = prometheus.NewDesc(
"rds_exporter_scrape_duration_seconds",
Expand Down Expand Up @@ -44,6 +42,27 @@ func New(config *config.Config, sessions *sessions.Sessions) *Exporter {
}
}

// ExcludeMetrics exclude some metrics from collector.
// This need for resolve metric names conflicts when registering basic and enhanced collectors.
func (e *Exporter) ExcludeMetrics(metrics ...string) {
idexter marked this conversation as resolved.
Show resolved Hide resolved
var filtered []Metric
for _, v := range e.metrics {
if !contains(v.Name, metrics) {
filtered = append(filtered, v)
}
}
e.metrics = filtered
}

func contains(metricName string, metrics []string) bool {
idexter marked this conversation as resolved.
Show resolved Hide resolved
for _, v := range metrics {
if v == metricName {
return true
}
}
return false
}

func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
now := time.Now()
e.collect(ch)
Expand Down
179 changes: 0 additions & 179 deletions basic/generate/main.go

This file was deleted.

34 changes: 0 additions & 34 deletions basic/generate/utils.go

This file was deleted.

1 change: 0 additions & 1 deletion basic/metrics.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Code generated by go generate; DO NOT EDIT.
package basic

import (
Expand Down
Loading