forked from TencentBlueKing/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (39 loc) · 1.05 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cpu
import (
"strings"
"github.com/pkg/errors"
"github.com/elastic/beats/libbeat/common/cfgwarn"
)
// CPU metric types.
const (
percentages = "percentages"
normalizedPercentages = "normalized_percentages"
ticks = "ticks"
)
// Config for the system cpu metricset.
type Config struct {
Metrics []string `config:"cpu.metrics"`
CPUTicks *bool `config:"cpu_ticks"` // Deprecated.
}
// Validate validates the cpu config.
func (c Config) Validate() error {
if c.CPUTicks != nil {
cfgwarn.Deprecate("6.1", "cpu_ticks is deprecated. Add 'ticks' to the cpu.metrics list.")
}
if len(c.Metrics) == 0 {
return errors.New("cpu.metrics cannot be empty")
}
for _, metric := range c.Metrics {
switch strings.ToLower(metric) {
case percentages, normalizedPercentages, ticks:
default:
return errors.Errorf("invalid cpu.metrics value '%v' (valid "+
"options are %v, %v, and %v)", metric, percentages,
normalizedPercentages, ticks)
}
}
return nil
}
var defaultConfig = Config{
Metrics: []string{percentages},
}