influxdb/gather
L1Cafe 5a7ce078f5
fix: scraping failed when Content-Type header is not set (#24135)
Co-authored-by: L1Cafe <L1Cafe@donotemail.me>
2023-03-14 10:13:28 -04:00
..
README.md chore: Remove several instances of WithLogger (#15996) 2019-12-04 15:10:23 -08:00
metrics.go chore: clean up protobuf loose ends (#22823) 2021-11-05 10:30:30 -05:00
metrics_test.go chore: clean up protobuf loose ends (#22823) 2021-11-05 10:30:30 -05:00
prometheus.go fix: scraping failed when Content-Type header is not set (#24135) 2023-03-14 10:13:28 -04:00
scheduler.go fix: only the latest scraper being run (#23813) 2022-10-20 13:33:41 -04:00
scheduler_test.go fix: remove nats for scraper processing (#23107) 2022-02-10 11:23:18 -05:00
scraper.go refactor: rewrite imports to include the /v2 suffix for version 2 2020-04-03 12:39:20 -05:00
scraper_test.go fix: remove nats for scraper processing (#23107) 2022-02-10 11:23:18 -05:00

README.md

How to use this package

Make sure nats is running. Both publisher and subscriber are open

// NATS streaming server
m.natsServer = nats.NewServer(nats.Config{FilestoreDir: m.natsPath})
if err := m.natsServer.Open(); err != nil {
    m.logger.Error("Failed to start nats streaming server", zap.Error(err))
    return err
}

publisher := nats.NewAsyncPublisher("nats-publisher")
if err := publisher.Open(); err != nil {
    m.logger.Error("Failed to connect to streaming server", zap.Error(err))
    return err
}

subscriber := nats.NewQueueSubscriber("nats-subscriber")
if err := subscriber.Open(); err != nil {
    m.logger.Error("Failed to connect to streaming server", zap.Error(err))
    return err
}

Make sure the scraperTargetStorageService is accessible

scraperTargetSvc influxdb.ScraperTargetStoreService = m.boltClient

Setup recorder, Make sure subscriber subscribes use the correct recorder with the correct write service

recorder := gather.PlatformWriter{
    Timeout: time.Millisecond * 30,
    Writer: writer,
}
subscriber.Subscribe(MetricsSubject, "", &RecorderHandler{
    Logger:   logger,
    Recorder: recorder,
})

Start the scheduler

scraperScheduler, err := gather.NewScheduler(10, m.logger, scraperTargetSvc, publisher, subscriber, 0, 0)
if err != nil {
    m.logger.Error("Failed to create scraper subscriber", zap.Error(err))
    return err
}