Skip to content

Commit

Permalink
add service cmd flag and custom labels
Browse files Browse the repository at this point in the history
Signed-off-by: Peekjef72 <[email protected]>
  • Loading branch information
peekjef72 committed Apr 22, 2023
1 parent 76c435d commit 11543a9
Show file tree
Hide file tree
Showing 10 changed files with 585 additions and 57 deletions.
12 changes: 10 additions & 2 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/alecthomas/kingpin/v2"
"github.com/leoluk/perflib_exporter/perflib"
"github.com/prometheus-community/windows_exporter/config"
"github.com/prometheus-community/windows_exporter/log"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/windows/registry"
Expand Down Expand Up @@ -58,11 +59,15 @@ type perfCounterNamesBuilder func() []string
var (
builders = make(map[string]collectorBuilder)
perfCounterDependencies = make(map[string]string)
config_hooks = make(map[string]config.CfgHook)
)

func registerCollector(name string, builder collectorBuilder, perfCounterNames ...string) {
func registerCollector(name string, builder collectorBuilder, hooks map[string]config.CfgHook, perfCounterNames ...string) {
builders[name] = builder
addPerfCounterDependencies(name, perfCounterNames)
for k, v := range hooks {
config_hooks[k] = v
}
}

func addPerfCounterDependencies(name string, perfCounterNames []string) {
Expand All @@ -80,10 +85,13 @@ func Available() []string {
}
return cs
}
func CfgHooks() map[string]config.CfgHook {
return config_hooks
}
func Build(collector string) (Collector, error) {
builder, exists := builders[collector]
if !exists {
return nil, fmt.Errorf("Unknown collector %q", collector)
return nil, fmt.Errorf("unknown collector %q", collector)
}
return builder()
}
Expand Down
10 changes: 8 additions & 2 deletions collector/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package collector

import "github.com/alecthomas/kingpin/v2"
import (
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus-community/windows_exporter/config"
)

// collectorInit represents the required initialisation config for a collector.
type collectorInit struct {
Expand All @@ -13,6 +16,8 @@ type collectorInit struct {
// Perflib counter names for the collector.
// These will be included in the Perflib scrape scope by the exporter.
perfCounterFunc perfCounterNamesBuilder
// builder function to intercept parameters for a collector
config_hooks map[string]config.CfgHook
}

func getDFSRCollectorDeps() []string {
Expand Down Expand Up @@ -307,6 +312,7 @@ var collectors = []collectorInit{
flags: newServiceCollectorFlags,
builder: newserviceCollector,
perfCounterFunc: nil,
config_hooks: ServiceBuildHook(),
},
{
name: "smtp",
Expand Down Expand Up @@ -402,6 +408,6 @@ func RegisterCollectors() {
perfCounterNames = v.perfCounterFunc()
}

registerCollector(v.name, v.builder, perfCounterNames...)
registerCollector(v.name, v.builder, v.config_hooks, perfCounterNames...)
}
}
Loading

0 comments on commit 11543a9

Please sign in to comment.