Skip to content

Commit 80355c9

Browse files
authored
PMM-4474 Add extra labels. (#32)
1 parent 7956cc9 commit 80355c9

File tree

543 files changed

+141780
-53473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

543 files changed

+141780
-53473
lines changed

Gopkg.lock

+51-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ instances:
2626
region: us-east-1
2727
aws_access_key: AKIAIOSFODNN7EXAMPLE
2828
aws_secret_key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
29+
labels:
30+
foo: bar
31+
baz: qux
2932
```
3033
3134
If `aws_access_key` and `aws_secret_key` are present, they are used for that instance.
3235
Otherwise, [default credential provider chain](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials)
3336
is used, which includes `AWS_ACCESS_KEY_ID`/`AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY`/`AWS_SECRET_KEY` environment variables, `~/.aws/credentials` file,
3437
and IAM role for EC2.
3538

39+
Returned metrics contain `instance` and `region` labels set. They also contain extra labels specified in the configuration file.
3640

3741
Start exporter by running:
3842
```

basic/basic.go basic/collector.go

+20-21
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,46 @@ var (
2323
)
2424

2525
type Metric struct {
26-
Name string
27-
Desc *prometheus.Desc
26+
cwName string
27+
prometheusName string
28+
prometheusHelp string
2829
}
2930

30-
type Exporter struct {
31+
type Collector struct {
3132
config *config.Config
3233
sessions *sessions.Sessions
3334
metrics []Metric
3435
l log.Logger
3536
}
3637

37-
// New creates a new instance of a Exporter.
38-
func New(config *config.Config, sessions *sessions.Sessions) *Exporter {
39-
return &Exporter{
38+
// New creates a new instance of a Collector.
39+
func New(config *config.Config, sessions *sessions.Sessions) *Collector {
40+
return &Collector{
4041
config: config,
4142
sessions: sessions,
4243
metrics: Metrics,
4344
l: log.With("component", "basic"),
4445
}
4546
}
4647

47-
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
48+
func (e *Collector) Describe(ch chan<- *prometheus.Desc) {
49+
// unchecked collector
50+
}
51+
52+
func (e *Collector) Collect(ch chan<- prometheus.Metric) {
4853
now := time.Now()
4954
e.collect(ch)
5055

5156
// Collect scrape time
5257
ch <- prometheus.MustNewConstMetric(scrapeTimeDesc, prometheus.GaugeValue, time.Since(now).Seconds())
5358
}
5459

55-
func (e *Exporter) collect(ch chan<- prometheus.Metric) {
56-
wg := &sync.WaitGroup{}
60+
func (e *Collector) collect(ch chan<- prometheus.Metric) {
61+
var wg sync.WaitGroup
5762
defer wg.Wait()
5863

59-
instances := e.config.Instances
60-
wg.Add(len(instances))
61-
for _, instance := range instances {
64+
wg.Add(len(e.config.Instances))
65+
for _, instance := range e.config.Instances {
6266
instance := instance
6367
go func() {
6468
defer wg.Done()
@@ -73,12 +77,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) {
7377
}
7478
}
7579

76-
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
77-
// RDS metrics
78-
for _, m := range e.metrics {
79-
ch <- m.Desc
80-
}
81-
82-
// Scrape time
83-
ch <- scrapeTimeDesc
84-
}
80+
// check interfaces
81+
var (
82+
_ prometheus.Collector = (*Collector)(nil)
83+
)

basic/basic_test.go basic/collector_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/percona/rds_exporter/sessions"
1414
)
1515

16-
func getExporter(t *testing.T) *Exporter {
16+
func getCollector(t *testing.T) *Collector {
1717
t.Helper()
1818

1919
cfg, err := config.Load("../config.yml")
@@ -25,7 +25,7 @@ func getExporter(t *testing.T) *Exporter {
2525
}
2626

2727
func TestCollector_Describe(t *testing.T) {
28-
c := getExporter(t)
28+
c := getCollector(t)
2929
ch := make(chan *prometheus.Desc)
3030
go func() {
3131
c.Describe(ch)
@@ -42,7 +42,7 @@ func TestCollector_Describe(t *testing.T) {
4242
}
4343

4444
func TestCollector_Collect(t *testing.T) {
45-
c := getExporter(t)
45+
c := getCollector(t)
4646
ch := make(chan prometheus.Metric)
4747
go func() {
4848
c.Collect(ch)

0 commit comments

Comments
 (0)