Skip to content

Commit

Permalink
add option to add extra collectors
Browse files Browse the repository at this point in the history
options like os collector reduces time executing perflib queries
  • Loading branch information
abhishuraina committed Nov 26, 2024
1 parent fd88b22 commit 5fe323d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Exporter struct {
}

// New create a configured Exporter struct ready to be run
func New(verbose bool, bindAddress string, bindPort string) (*Exporter, error) {
func New(verbose bool, bindAddress string, bindPort string, extraCollectors string) (*Exporter, error) {
integrationDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return nil, fmt.Errorf("failed to create exporter:%v", err)
Expand All @@ -48,12 +48,17 @@ func New(verbose bool, bindAddress string, bindPort string) (*Exporter, error) {

ctx, cancel := context.WithCancel(context.Background())

path, err := os.Getwd()
exporterPath = filepath.Join(path, "target/bin/windows_amd64/windows_exporter.exe")
fmt.Printf("%s, %v", integrationDir, filepath.Join(path, "target/bin/windows_amd64/windows_exporter.exe"))
exporterLogLevel := "info"
if verbose {
exporterLogLevel = "debug"
}
exporterURL := bindAddress + ":" + bindPort

enabledCollectors := enabledCollectors + "," + extraCollectors
log.Debug("enabledCollectors", enabledCollectors)
cmd := exec.CommandContext(ctx,
exporterPath,
"--collectors.enabled", enabledCollectors,
Expand Down
3 changes: 3 additions & 0 deletions src/nri/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ type Config struct {
ExporterBindPort string
ScrapeInterval time.Duration
HeartBeatPeriod time.Duration
ExtraCollectors string
}

type configYml struct {
FilterEntity map[string][]string `yaml:"include_matching_entities"`
ExporterBindAddress string `yaml:"exporter_bind_address"`
ExporterBindPort string `yaml:"exporter_bind_port"`
ScrapeInterval string `yaml:"scrape_interval"`
ExtraCollectors string `yaml:"exporter_extra_collectors"`
}

// NewConfig reads the configuration from yml file
Expand Down Expand Up @@ -79,6 +81,7 @@ func NewConfig(filename string) (*Config, error) {
ExporterBindPort: c.ExporterBindPort,
ScrapeInterval: interval,
HeartBeatPeriod: heartBeatPeriod,
ExtraCollectors: c.ExtraCollectors,
}
return config, nil
}
2 changes: 1 addition & 1 deletion src/winservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {
config, err := nri.NewConfig(args.ConfigPath)
fatalOnErr(err)

e, err := exporter.New(args.Verbose, config.ExporterBindAddress, config.ExporterBindPort)
e, err := exporter.New(args.Verbose, config.ExporterBindAddress, config.ExporterBindPort, config.ExtraCollectors)
fatalOnErr(err)

log.Debug("Running exporter")
Expand Down
2 changes: 1 addition & 1 deletion win_build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $exporterBinaryName = "windows_exporter.exe"
# Commit used by v0.16.0 of windows_exporter
$exporterVersion = "1c199e6c0eed881fb09dfcc84eee191262215e5e"
# Collector used by the Windows Service integration
$collectors = "collector.go","wmi.go","perflib.go","service.go","cs.go"
$collectors = "collector.go","wmi.go","perflib.go","service.go","cs.go","os.go"

$env:GOPATH = go env GOPATH
$env:GOBIN = "$env:GOPATH\bin"
Expand Down
3 changes: 3 additions & 0 deletions winservices-config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ integrations:
# exporter_bind_address: 127.0.0.1
# exporter_bind_port: 9182

# add more collectors
# exporter_extra_collectors: "os"

# To include services, create a list of filters to be applied to the service names.
# Services that find a match with any of the matching lists are included. By default,
# no service is included.
Expand Down

0 comments on commit 5fe323d

Please sign in to comment.