-
Couldn't load subscription status.
- Fork 87
PMM-4474 Add extra labels. #32
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
Changes from all commits
6bcf941
2df0556
da49575
2f0e384
7f90000
d357014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
| 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method |
||
| // unchecked collector | ||
| } | ||
|
|
||
| func (e *Collector) Collect(ch chan<- prometheus.Metric) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method |
||
| 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 { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ranges should only be cuddled with assignments used in the iteration (from |
||
| instance := instance | ||
| go func() { | ||
| defer wg.Done() | ||
|
|
@@ -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) | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ import ( | |
| "github.com/percona/rds_exporter/sessions" | ||
| ) | ||
|
|
||
| func getExporter(t *testing.T) *Exporter { | ||
| func getCollector(t *testing.T) *Collector { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. func |
||
| t.Helper() | ||
|
|
||
| cfg, err := config.Load("../config.yml") | ||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported type
Collectorshould have comment or be unexported (fromgolint)