Skip to content

Commit a040ea9

Browse files
authored
Merge pull request #150 from pagbrl/improve-reliability
Make querying interval configurable and improve error handling
2 parents 72c201e + 7945f13 commit a040ea9

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The exporter can be configured using env variables or command flags.
5454
| `LISTEN` | listen on addr:port (default `:8080`), omit addr to listen on all interfaces |
5555
| `METRICS_PATH` | path for metrics, default `/metrics` |
5656
| `SCRAPE_DELAY` | scrape delay in seconds, default `300` |
57+
| `SCRAPE_INTERVAL` | scrape interval in seconds (will query cloudflare every SCRAPE_INTERVAL seconds), default `60` |
5758
| `CF_BATCH_SIZE` | cloudflare request zones batch size (1 - 10), default `10` |
5859
| `METRICS_DENYLIST` | (Optional) cloudflare-exporter metrics to not export, comma delimited list of cloudflare-exporter metrics. If not set, all metrics are exported |
5960
| `ENABLE_PPROF` | (Optional) enable pprof profiling endpoints at `/debug/pprof/`. Accepts `true` or `false`, default `false`. **Warning**: Only enable in development/debugging environments |
@@ -70,6 +71,7 @@ Corresponding flags:
7071
-listen=":8080": listen on addr:port ( default :8080), omit addr to listen on all interfaces
7172
-metrics_path="/metrics": path for metrics, default /metrics
7273
-scrape_delay=300: scrape delay in seconds, defaults to 300
74+
-scrape_interval=60: scrape interval in seconds, defaults to 60
7375
-cf_batch_size=10: cloudflare zones batch size (1-10)
7476
-metrics_denylist="": cloudflare-exporter metrics to not export, comma delimited list
7577
-enable_pprof=false: enable pprof profiling endpoints at /debug/pprof/

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ func runExporter() {
187187
log.Debugf("Metrics set: %v", metricsSet)
188188
mustRegisterMetrics(metricsSet)
189189

190+
scrapeInterval := time.Duration(viper.GetInt("scrape_interval")) * time.Second
191+
log.Info("Scrape interval set to ", scrapeInterval)
192+
190193
go func() {
191-
for ; true; <-time.NewTicker(60 * time.Second).C {
194+
for ; true; <-time.NewTicker(scrapeInterval).C {
192195
go fetchMetrics()
193196
}
194197
}()
@@ -255,6 +258,10 @@ func main() {
255258
viper.BindEnv("scrape_delay")
256259
viper.SetDefault("scrape_delay", 300)
257260

261+
flags.Int("scrape_interval", 60, "scrape interval in seconds, defaults to 60")
262+
viper.BindEnv("scrape_interval")
263+
viper.SetDefault("scrape_interval", 60)
264+
258265
flags.Int("cf_batch_size", 10, "cloudflare zones batch size (1-10)")
259266
viper.BindEnv("cf_batch_size")
260267
viper.SetDefault("cf_batch_size", 10)

prometheus.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/biter777/countries"
1010
cloudflare "github.com/cloudflare/cloudflare-go"
1111
"github.com/prometheus/client_golang/prometheus"
12+
log "github.com/sirupsen/logrus"
1213
"github.com/spf13/viper"
1314
)
1415

@@ -448,6 +449,7 @@ func fetchWorkerAnalytics(account cloudflare.Account, wg *sync.WaitGroup) {
448449

449450
r, err := fetchWorkerTotals(account.ID)
450451
if err != nil {
452+
log.Error("failed to fetch worker analytics for account ", account.ID, ": ", err)
451453
return
452454
}
453455

@@ -481,6 +483,7 @@ func fetchLogpushAnalyticsForAccount(account cloudflare.Account, wg *sync.WaitGr
481483
r, err := fetchLogpushAccount(account.ID)
482484

483485
if err != nil {
486+
log.Error("failed to fetch logpush analytics for account ", account.ID, ": ", err)
484487
return
485488
}
486489

@@ -532,6 +535,7 @@ func fetchLogpushAnalyticsForZone(zones []cloudflare.Zone, wg *sync.WaitGroup) {
532535
r, err := fetchLogpushZone(zoneIDs)
533536

534537
if err != nil {
538+
log.Error("failed to fetch logpush analytics for zones: ", err)
535539
return
536540
}
537541

@@ -560,6 +564,7 @@ func fetchZoneColocationAnalytics(zones []cloudflare.Zone, wg *sync.WaitGroup) {
560564

561565
r, err := fetchColoTotals(zoneIDs)
562566
if err != nil {
567+
log.Error("failed to fetch colocation analytics for zones: ", err)
563568
return
564569
}
565570
for _, z := range r.Viewer.Zones {
@@ -589,6 +594,7 @@ func fetchZoneAnalytics(zones []cloudflare.Zone, wg *sync.WaitGroup) {
589594

590595
r, err := fetchZoneTotals(zoneIDs)
591596
if err != nil {
597+
log.Error("failed to fetch zone analytics: ", err)
592598
return
593599
}
594600

@@ -740,6 +746,7 @@ func fetchLoadBalancerAnalytics(zones []cloudflare.Zone, wg *sync.WaitGroup) {
740746

741747
l, err := fetchLoadBalancerTotals(zoneIDs)
742748
if err != nil {
749+
log.Error("failed to fetch load balancer analytics: ", err)
743750
return
744751
}
745752
for _, lb := range l.Viewer.Zones {

0 commit comments

Comments
 (0)