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

Remove fluent-style kingpin #1186

Merged
merged 1 commit into from
Apr 17, 2023
Merged
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
3 changes: 3 additions & 0 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/alecthomas/kingpin/v2"
"github.com/leoluk/perflib_exporter/perflib"
"github.com/prometheus-community/windows_exporter/log"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -51,6 +52,8 @@ func getWindowsVersion() float64 {
}

type collectorBuilder func() (Collector, error)
type flagsBuilder func(*kingpin.Application)
type perfCounterNamesBuilder func() []string

var (
builders = make(map[string]collectorBuilder)
Expand Down
11 changes: 10 additions & 1 deletion collector/dfsr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

var dfsrEnabledCollectors = kingpin.Flag("collectors.dfsr.sources-enabled", "Comma-seperated list of DFSR Perflib sources to use.").Default("connection,folder,volume").String()
const (
FlagDfsrEnabledCollectors = "collectors.dfsr.sources-enabled"
)

var dfsrEnabledCollectors *string

// DFSRCollector contains the metric and state data of the DFSR collectors.
type DFSRCollector struct {
Expand Down Expand Up @@ -82,6 +86,11 @@ func dfsrGetPerfObjectName(collector string) string {
return (prefix + suffix)
}

// newDFSRCollectorFlags is registered
func newDFSRCollectorFlags(app *kingpin.Application) {
dfsrEnabledCollectors = app.Flag(FlagDfsrEnabledCollectors, "Comma-seperated list of DFSR Perflib sources to use.").Default("connection,folder,volume").String()
}

// newDFSRCollector is registered
func newDFSRCollector() (Collector, error) {
log.Info("dfsr collector is in an experimental state! Metrics for this collector have not been tested.")
Expand Down
22 changes: 17 additions & 5 deletions collector/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

const (
FlagExchangeListAllCollectors = "collectors.exchange.list"
FlagExchangeCollectorsEnabled = "collectors.exchange.enabled"
)

type exchangeCollector struct {
LDAPReadTime *prometheus.Desc
LDAPSearchTime *prometheus.Desc
Expand Down Expand Up @@ -69,16 +74,23 @@ var (
"RpcClientAccess",
}

argExchangeListAllCollectors = kingpin.Flag(
"collectors.exchange.list",
argExchangeListAllCollectors *bool

argExchangeCollectorsEnabled *string
)

// newExchangeCollectorFlags ...
func newExchangeCollectorFlags(app *kingpin.Application) {
argExchangeListAllCollectors = app.Flag(
FlagExchangeListAllCollectors,
"List the collectors along with their perflib object name/ids",
).Bool()

argExchangeCollectorsEnabled = kingpin.Flag(
"collectors.exchange.enabled",
argExchangeCollectorsEnabled = app.Flag(
FlagExchangeCollectorsEnabled,
"Comma-separated list of collectors to use. Defaults to all, if not specified.",
).Default("").String()
)
}

// newExchangeCollector returns a new Collector
func newExchangeCollector() (Collector, error) {
Expand Down
22 changes: 18 additions & 4 deletions collector/iis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ import (
"golang.org/x/sys/windows/registry"
)

const (
FlagISSSiteBlacklist = "collector.iis.site-blacklist"
FlagISSSiteWhitelist = "collector.iis.site-whitelist"
FlagISSAppBlacklist = "collector.iis.app-blacklist"
FlagISSAppWhitelist = "collector.iis.app-whitelist"
)

var (
siteWhitelist = kingpin.Flag("collector.iis.site-whitelist", "Regexp of sites to whitelist. Site name must both match whitelist and not match blacklist to be included.").Default(".+").String()
siteBlacklist = kingpin.Flag("collector.iis.site-blacklist", "Regexp of sites to blacklist. Site name must both match whitelist and not match blacklist to be included.").String()
appWhitelist = kingpin.Flag("collector.iis.app-whitelist", "Regexp of apps to whitelist. App name must both match whitelist and not match blacklist to be included.").Default(".+").String()
appBlacklist = kingpin.Flag("collector.iis.app-blacklist", "Regexp of apps to blacklist. App name must both match whitelist and not match blacklist to be included.").String()
siteWhitelist *string
siteBlacklist *string
appWhitelist *string
appBlacklist *string
)

type simple_version struct {
Expand Down Expand Up @@ -191,6 +198,13 @@ type IISCollector struct {
iis_version simple_version
}

func newIISCollectorFlags(app *kingpin.Application) {
siteWhitelist = kingpin.Flag(FlagISSSiteWhitelist, "Regexp of sites to whitelist. Site name must both match whitelist and not match blacklist to be included.").Default(".+").String()
siteBlacklist = kingpin.Flag(FlagISSSiteBlacklist, "Regexp of sites to blacklist. Site name must both match whitelist and not match blacklist to be included.").String()
appWhitelist = kingpin.Flag(FlagISSAppWhitelist, "Regexp of apps to whitelist. App name must both match whitelist and not match blacklist to be included.").Default(".+").String()
appBlacklist = kingpin.Flag(FlagISSAppBlacklist, "Regexp of apps to blacklist. App name must both match whitelist and not match blacklist to be included.").String()
}

func newIISCollector() (Collector, error) {
const subsystem = "iis"

Expand Down
Loading