mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-28 07:36:37 +00:00
update: export properties so that they can be read from yaml file (#2053)
This commit is contained in:
@@ -39,14 +39,14 @@ import (
|
|||||||
const Name = "update"
|
const Name = "update"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
online bool `yaml:"online"`
|
Online bool `yaml:"online"`
|
||||||
scrapeInterval time.Duration `yaml:"scrape_interval"`
|
ScrapeInterval time.Duration `yaml:"scrape_interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gochecknoglobals
|
//nolint:gochecknoglobals
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
online: false,
|
Online: false,
|
||||||
scrapeInterval: 6 * time.Hour,
|
ScrapeInterval: 6 * time.Hour,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -92,29 +92,29 @@ func NewWithFlags(app *kingpin.Application) *Collector {
|
|||||||
app.Flag(
|
app.Flag(
|
||||||
"collector.updates.online",
|
"collector.updates.online",
|
||||||
"Deprecated: Please use collector.update.online instead",
|
"Deprecated: Please use collector.update.online instead",
|
||||||
).Default(strconv.FormatBool(ConfigDefaults.online)).BoolVar(&online)
|
).Default(strconv.FormatBool(ConfigDefaults.Online)).BoolVar(&online)
|
||||||
|
|
||||||
app.Flag(
|
app.Flag(
|
||||||
"collector.updates.scrape-interval",
|
"collector.updates.scrape-interval",
|
||||||
"Deprecated: Please use collector.update.scrape-interval instead",
|
"Deprecated: Please use collector.update.scrape-interval instead",
|
||||||
).Default(ConfigDefaults.scrapeInterval.String()).DurationVar(&scrapeInterval)
|
).Default(ConfigDefaults.ScrapeInterval.String()).DurationVar(&scrapeInterval)
|
||||||
|
|
||||||
app.Flag(
|
app.Flag(
|
||||||
"collector.update.online",
|
"collector.update.online",
|
||||||
"Whether to search for updates online.",
|
"Whether to search for updates online.",
|
||||||
).Default(strconv.FormatBool(ConfigDefaults.online)).BoolVar(&c.config.online)
|
).Default(strconv.FormatBool(ConfigDefaults.Online)).BoolVar(&c.config.Online)
|
||||||
|
|
||||||
app.Flag(
|
app.Flag(
|
||||||
"collector.update.scrape-interval",
|
"collector.update.scrape-interval",
|
||||||
"Define the interval of scraping Windows Update information.",
|
"Define the interval of scraping Windows Update information.",
|
||||||
).Default(ConfigDefaults.scrapeInterval.String()).DurationVar(&c.config.scrapeInterval)
|
).Default(ConfigDefaults.ScrapeInterval.String()).DurationVar(&c.config.ScrapeInterval)
|
||||||
|
|
||||||
app.Action(func(*kingpin.ParseContext) error {
|
app.Action(func(*kingpin.ParseContext) error {
|
||||||
// Use deprecated flags only if new ones weren't explicitly set
|
// Use deprecated flags only if new ones weren't explicitly set
|
||||||
if online {
|
if online {
|
||||||
// If the new flag is set, ignore the old one
|
// If the new flag is set, ignore the old one
|
||||||
if !c.config.online {
|
if !c.config.Online {
|
||||||
c.config.online = online
|
c.config.Online = online
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Warn("Warning: --collector.updates.online is deprecated, use --collector.update.online instead.",
|
slog.Warn("Warning: --collector.updates.online is deprecated, use --collector.update.online instead.",
|
||||||
@@ -122,10 +122,10 @@ func NewWithFlags(app *kingpin.Application) *Collector {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if scrapeInterval != ConfigDefaults.scrapeInterval {
|
if scrapeInterval != ConfigDefaults.ScrapeInterval {
|
||||||
// If the new flag is set, ignore the old one
|
// If the new flag is set, ignore the old one
|
||||||
if c.config.scrapeInterval != scrapeInterval {
|
if c.config.ScrapeInterval != scrapeInterval {
|
||||||
c.config.scrapeInterval = scrapeInterval
|
c.config.ScrapeInterval = scrapeInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Warn("Warning: --collector.updates.scrape-interval is deprecated, use --collector.update.scrape-interval instead.",
|
slog.Warn("Warning: --collector.updates.scrape-interval is deprecated, use --collector.update.scrape-interval instead.",
|
||||||
@@ -153,7 +153,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
initErrCh := make(chan error, 1)
|
initErrCh := make(chan error, 1)
|
||||||
go c.scheduleUpdateStatus(ctx, logger, initErrCh, c.config.online)
|
go c.scheduleUpdateStatus(ctx, logger, initErrCh, c.config.Online)
|
||||||
|
|
||||||
c.ctxCancelFn = cancel
|
c.ctxCancelFn = cancel
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ func (c *Collector) scheduleUpdateStatus(ctx context.Context, logger *slog.Logge
|
|||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(c.config.scrapeInterval):
|
case <-time.After(c.config.ScrapeInterval):
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user