Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add service cmd flag and custom labels, add process metric (process_gorup_count) add process custom labels #1194

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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