Skip to content

Scrape metrics immediately for scrape.interval #171

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

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
21 changes: 16 additions & 5 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,30 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
// rather than letting it be per Collect call
func (e *Exporter) RunScheduledScrapes(ctx context.Context, si time.Duration) {
e.scrapeInterval = &si

e.doScrape(time.Now())

ticker := time.NewTicker(si)
defer ticker.Stop()

for {
select {
case tick := <-ticker.C:

e.mu.Lock() // ensure no simultaneous scrapes
e.scheduledScrape(&tick)
e.lastTick = &tick
e.mu.Unlock()
e.doScrape(tick)
case <-ctx.Done():
return
}
}
}

func (e *Exporter) doScrape(tick time.Time) {
e.mu.Lock() // ensure no simultaneous scrapes
e.scheduledScrape(&tick)
e.lastTick = &tick
e.mu.Unlock()
}

func (e *Exporter) scheduledScrape(tick *time.Time) {
metricCh := make(chan prometheus.Metric, 5)

Expand Down Expand Up @@ -387,7 +394,11 @@ func (e *Exporter) connect() error {
e.user = ""
}
level.Info(e.logger).Log("msg", msg)
P.Username, P.Password, P.ConnectString, P.ExternalAuth = e.user, godror.NewPassword(e.password), e.connectString, e.externalAuth
externalAuth := sql.NullBool{
Bool: e.externalAuth,
Valid: true,
}
P.Username, P.Password, P.ConnectString, P.ExternalAuth = e.user, godror.NewPassword(e.password), e.connectString, externalAuth

// if TNS_ADMIN env var is set, set ConfigDir to that location
P.ConfigDir = e.configDir
Expand Down