Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
108 changes: 51 additions & 57 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ instances:
region: us-east-1
aws_access_key: AKIAIOSFODNN7EXAMPLE
aws_secret_key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
labels:
foo: bar
baz: qux
```

If `aws_access_key` and `aws_secret_key` are present, they are used for that instance.
Otherwise, [default credential provider chain](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials)
is used, which includes `AWS_ACCESS_KEY_ID`/`AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY`/`AWS_SECRET_KEY` environment variables, `~/.aws/credentials` file,
and IAM role for EC2.

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

Start exporter by running:
```
Expand Down
41 changes: 20 additions & 21 deletions basic/basic.go → basic/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,46 @@ var (
)

type Metric struct {
Name string
Desc *prometheus.Desc
cwName string
prometheusName string
prometheusHelp string
}

type Exporter struct {
type Collector struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported type Collector should have comment or be unexported (from golint)

config *config.Config
sessions *sessions.Sessions
metrics []Metric
l log.Logger
}

// New creates a new instance of a Exporter.
func New(config *config.Config, sessions *sessions.Sessions) *Exporter {
return &Exporter{
// New creates a new instance of a Collector.
func New(config *config.Config, sessions *sessions.Sessions) *Collector {
return &Collector{
config: config,
sessions: sessions,
metrics: Metrics,
l: log.With("component", "basic"),
}
}

func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
func (e *Collector) Describe(ch chan<- *prometheus.Desc) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method Collector.Describe should have comment or be unexported (from golint)

// unchecked collector
}

func (e *Collector) Collect(ch chan<- prometheus.Metric) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method Collector.Collect should have comment or be unexported (from golint)

now := time.Now()
e.collect(ch)

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

func (e *Exporter) collect(ch chan<- prometheus.Metric) {
wg := &sync.WaitGroup{}
func (e *Collector) collect(ch chan<- prometheus.Metric) {
var wg sync.WaitGroup
defer wg.Wait()

instances := e.config.Instances
wg.Add(len(instances))
for _, instance := range instances {
wg.Add(len(e.config.Instances))
for _, instance := range e.config.Instances {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ranges should only be cuddled with assignments used in the iteration (from wsl)

instance := instance
go func() {
defer wg.Done()
Expand All @@ -73,12 +77,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) {
}
}

func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
// RDS metrics
for _, m := range e.metrics {
ch <- m.Desc
}

// Scrape time
ch <- scrapeTimeDesc
}
// check interfaces
var (
_ prometheus.Collector = (*Collector)(nil)
)
6 changes: 3 additions & 3 deletions basic/basic_test.go → basic/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/percona/rds_exporter/sessions"
)

func getExporter(t *testing.T) *Exporter {
func getCollector(t *testing.T) *Collector {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func getCollector is unused (from unused)

t.Helper()

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

func TestCollector_Describe(t *testing.T) {
c := getExporter(t)
c := getCollector(t)
ch := make(chan *prometheus.Desc)
go func() {
c.Describe(ch)
Expand All @@ -42,7 +42,7 @@ func TestCollector_Describe(t *testing.T) {
}

func TestCollector_Collect(t *testing.T) {
c := getExporter(t)
c := getCollector(t)
ch := make(chan prometheus.Metric)
go func() {
c.Collect(ch)
Expand Down
Loading