Skip to content

Commit

Permalink
implement fine granular scrape times
Browse files Browse the repository at this point in the history
collectors can be disabled now #19

Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Aug 6, 2022
1 parent 8d484fb commit d4e3538
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
11 changes: 8 additions & 3 deletions config/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ type (
ServerBind string `long:"bind" env:"SERVER_BIND" description:"Server address" default:":8080"`

ScrapeTime struct {
General time.Duration `long:"scrape.time" env:"SCRAPE_TIME" description:"Scrape time (time.duration)" default:"5m"`
Summary time.Duration `long:"scrape.time.summary" env:"SCRAPE_TIME_SUMMARY" description:"Scrape time for general summary metrics (time.duration)" default:"15m"`
Live time.Duration `long:"scrape.time.live" env:"SCRAPE_TIME_LIVE" description:"Scrape time incidents and oncalls (time.duration)" default:"1m"`
General time.Duration `long:"scrape.time" env:"SCRAPE_TIME" description:"Scrape time (time.duration)" default:"5m"`
MaintenanceWindow *time.Duration `long:"scrape.time.maintenancewindow" env:"SCRAPE_TIME_MAINTENANCEWINDOW" description:"Scrape time for maintenance window metrics (time.duration; default is SCRAPE_TIME)"`
Schedule *time.Duration `long:"scrape.time.schedule" env:"SCRAPE_TIME_SCHEDULE" description:"Scrape time for schedule metrics (time.duration; default is SCRAPE_TIME)"`
Service *time.Duration `long:"scrape.time.service" env:"SCRAPE_TIME_SERVICE" description:"Scrape time for service metrics (time.duration; default is SCRAPE_TIME)"`
Team *time.Duration `long:"scrape.time.team" env:"SCRAPE_TIME_TEAM" description:"Scrape time for team metrics (time.duration; default is SCRAPE_TIME)"`
User *time.Duration `long:"scrape.time.user" env:"SCRAPE_TIME_USER" description:"Scrape time for user metrics (time.duration; default is SCRAPE_TIME)"`
Summary time.Duration `long:"scrape.time.summary" env:"SCRAPE_TIME_SUMMARY" description:"Scrape time for general summary metrics (time.duration)" default:"15m"`
Live time.Duration `long:"scrape.time.live" env:"SCRAPE_TIME_LIVE" description:"Scrape time incidents and oncalls (time.duration)" default:"1m"`
}
}
)
Expand Down
39 changes: 29 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ func initArgparser() {
}
}
}

if opts.ScrapeTime.MaintenanceWindow == nil {
opts.ScrapeTime.MaintenanceWindow = &opts.ScrapeTime.General
}

if opts.ScrapeTime.Schedule == nil {
opts.ScrapeTime.Schedule = &opts.ScrapeTime.General
}

if opts.ScrapeTime.Service == nil {
opts.ScrapeTime.Service = &opts.ScrapeTime.General
}
if opts.ScrapeTime.Team == nil {
opts.ScrapeTime.Team = &opts.ScrapeTime.General
}

if opts.ScrapeTime.User == nil {
opts.ScrapeTime.User = &opts.ScrapeTime.General
}
}

func initLogger() {
Expand Down Expand Up @@ -157,9 +176,9 @@ func initMetricCollector() {

if !opts.PagerDuty.Teams.Disable {
collectorName = "Team"
if opts.ScrapeTime.General.Seconds() > 0 {
if opts.ScrapeTime.Team.Seconds() > 0 {
c := collector.New(collectorName, &MetricsCollectorTeam{}, log.StandardLogger())
c.SetScapeTime(opts.ScrapeTime.General)
c.SetScapeTime(*opts.ScrapeTime.Team)
if err := c.Start(); err != nil {
log.Panic(err.Error())
}
Expand All @@ -169,9 +188,9 @@ func initMetricCollector() {
}

collectorName = "User"
if opts.ScrapeTime.General.Seconds() > 0 {
if opts.ScrapeTime.User.Seconds() > 0 {
c := collector.New(collectorName, &MetricsCollectorUser{teamListOpt: opts.PagerDuty.Teams.Filter}, log.StandardLogger())
c.SetScapeTime(opts.ScrapeTime.General)
c.SetScapeTime(*opts.ScrapeTime.User)
if err := c.Start(); err != nil {
log.Panic(err.Error())
}
Expand All @@ -180,9 +199,9 @@ func initMetricCollector() {
}

collectorName = "Service"
if opts.ScrapeTime.General.Seconds() > 0 {
if opts.ScrapeTime.Service.Seconds() > 0 {
c := collector.New(collectorName, &MetricsCollectorService{teamListOpt: opts.PagerDuty.Teams.Filter}, log.StandardLogger())
c.SetScapeTime(opts.ScrapeTime.General)
c.SetScapeTime(*opts.ScrapeTime.Service)
if err := c.Start(); err != nil {
log.Panic(err.Error())
}
Expand All @@ -192,9 +211,9 @@ func initMetricCollector() {
}

collectorName = "Schedule"
if opts.ScrapeTime.General.Seconds() > 0 {
if opts.ScrapeTime.Schedule.Seconds() > 0 {
c := collector.New(collectorName, &MetricsCollectorSchedule{}, log.StandardLogger())
c.SetScapeTime(opts.ScrapeTime.General)
c.SetScapeTime(*opts.ScrapeTime.Schedule)
if err := c.Start(); err != nil {
log.Panic(err.Error())
}
Expand All @@ -203,9 +222,9 @@ func initMetricCollector() {
}

collectorName = "MaintenanceWindow"
if opts.ScrapeTime.General.Seconds() > 0 {
if opts.ScrapeTime.MaintenanceWindow.Seconds() > 0 {
c := collector.New(collectorName, &MetricsCollectorMaintenanceWindow{teamListOpt: opts.PagerDuty.Teams.Filter}, log.StandardLogger())
c.SetScapeTime(opts.ScrapeTime.General)
c.SetScapeTime(*opts.ScrapeTime.MaintenanceWindow)
if err := c.Start(); err != nil {
log.Panic(err.Error())
}
Expand Down

0 comments on commit d4e3538

Please sign in to comment.