Skip to content

Commit

Permalink
add service and process custom labels
Browse files Browse the repository at this point in the history
Signed-off-by: Peekjef72 <[email protected]>
  • Loading branch information
peekjef72 committed Oct 23, 2023
1 parent 9c0be5f commit 7abc192
Show file tree
Hide file tree
Showing 9 changed files with 912 additions and 200 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ The prometheus metrics will be exposed on [localhost:9182](http://localhost:9182

### Enable only service collector and specify a custom query

.\windows_exporter.exe --collectors.enabled "service" --collector.service.services-where "Name='windows_exporter'"
```shell
.\windows_exporter.exe --collectors.enabled "service" --collector.service.services-where "Name='windows_exporter'"
```

or

```shell
.\windows_exporter.exe --collectors.enabled "service" --collector.service.services-list "windows_exporter"
```

### Enable only process collector and specify a custom query

Expand Down
13 changes: 11 additions & 2 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"strings"

"github.com/prometheus-community/windows_exporter/config"
"github.com/prometheus-community/windows_exporter/perflib"

"github.com/alecthomas/kingpin/v2"
Expand Down Expand Up @@ -60,11 +61,15 @@ type perfCounterNamesBuilder func(log.Logger) []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 @@ -82,10 +87,14 @@ func Available() []string {
}
return cs
}
func CfgHooks() map[string]config.CfgHook {
return config_hooks
}

func Build(collector string, logger log.Logger) (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(logger)
}
Expand Down
8 changes: 7 additions & 1 deletion collector/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package collector

import (
"github.com/prometheus-community/windows_exporter/config"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
)
Expand All @@ -16,6 +18,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(_ log.Logger) []string {
Expand Down Expand Up @@ -303,6 +307,7 @@ var collectors = []collectorInit{
perfCounterFunc: func(_ log.Logger) []string {
return []string{"Process"}
},
config_hooks: ProcessBuildHook(),
},
{
name: "remote_fx",
Expand All @@ -323,6 +328,7 @@ var collectors = []collectorInit{
flags: newServiceCollectorFlags,
builder: newserviceCollector,
perfCounterFunc: nil,
config_hooks: ServiceBuildHook(),
},
{
name: "smtp",
Expand Down Expand Up @@ -418,6 +424,6 @@ func RegisterCollectors(logger log.Logger) {
perfCounterNames = v.perfCounterFunc(logger)
}

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

0 comments on commit 7abc192

Please sign in to comment.