Add two complementary features to reduce remote revision cache staleness: 1. Smart local cache: When current system revision matches cached remote revision, force an immediate cache refresh to check for newer revisions. 2. NATS integration: Share cache updates across hosts via NATS pub/sub. Hosts publish revision updates when they fetch new data, and subscribe to receive updates from other hosts. Features include: - Auto-reconnect with infinite retries - Graceful fallback when NATS unavailable - Filtering by flake URL and hostname New CLI flags: --flake.nats.enable --flake.nats.url --flake.nats.subject --flake.nats.credentials-file New NixOS module options under services.prometheus.exporters.nixos.flake.nats Bumps version to 0.3.0. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
ListenAddr string
|
|
FlakeCollector bool
|
|
FlakeURL string
|
|
FlakeCheckInterval time.Duration
|
|
|
|
// NATS configuration
|
|
FlakeNATSEnable bool
|
|
FlakeNATSURL string
|
|
FlakeNATSSubject string
|
|
FlakeNATSCredentialsFile string
|
|
}
|
|
|
|
func Parse() (*Config, error) {
|
|
cfg := &Config{}
|
|
|
|
flag.StringVar(&cfg.ListenAddr, "listen", ":9971", "Address to listen on")
|
|
flag.BoolVar(&cfg.FlakeCollector, "collector.flake", false, "Enable flake collector")
|
|
flag.StringVar(&cfg.FlakeURL, "flake.url", "", "Flake URL for revision comparison (required if flake collector enabled)")
|
|
flag.DurationVar(&cfg.FlakeCheckInterval, "flake.check-interval", time.Hour, "Interval between remote flake checks")
|
|
|
|
// NATS flags
|
|
flag.BoolVar(&cfg.FlakeNATSEnable, "flake.nats.enable", false, "Enable NATS cache sharing")
|
|
flag.StringVar(&cfg.FlakeNATSURL, "flake.nats.url", "nats://localhost:4222", "NATS server URL")
|
|
flag.StringVar(&cfg.FlakeNATSSubject, "flake.nats.subject", "nixos-exporter.remote-rev", "NATS subject for revision updates")
|
|
flag.StringVar(&cfg.FlakeNATSCredentialsFile, "flake.nats.credentials-file", "", "NATS credentials file (optional)")
|
|
|
|
flag.Parse()
|
|
|
|
if cfg.FlakeCollector && cfg.FlakeURL == "" {
|
|
return nil, fmt.Errorf("--flake.url is required when --collector.flake is enabled")
|
|
}
|
|
|
|
if cfg.FlakeNATSEnable && !cfg.FlakeCollector {
|
|
return nil, fmt.Errorf("--flake.nats.enable requires --collector.flake to be enabled")
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|