mirror of
https://github.com/prometheus-community/windows_exporter
synced 2024-12-28 01:12:06 +00:00
0711268d3c
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
37 lines
939 B
Go
37 lines
939 B
Go
//go:build windows
|
|
|
|
package utils
|
|
|
|
import (
|
|
"slices"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
|
)
|
|
|
|
// ExpandEnabledChildCollectors used by more complex Collectors where user input specifies enabled child Collectors.
|
|
// Splits provided child Collectors and deduplicate.
|
|
func ExpandEnabledChildCollectors(enabled string) []string {
|
|
result := slices.Compact(strings.Split(enabled, ","))
|
|
// Ensure result is ordered, to prevent test failure
|
|
sort.Strings(result)
|
|
return result
|
|
}
|
|
|
|
func ExpandEnabledCollectors(enabled string) []string {
|
|
expanded := strings.Replace(enabled, types.DefaultCollectorsPlaceholder, types.DefaultCollectors, -1)
|
|
separated := strings.Split(expanded, ",")
|
|
unique := map[string]bool{}
|
|
for _, s := range separated {
|
|
if s != "" {
|
|
unique[s] = true
|
|
}
|
|
}
|
|
result := make([]string, 0, len(unique))
|
|
for s := range unique {
|
|
result = append(result, s)
|
|
}
|
|
return result
|
|
}
|