@@ -2,28 +2,25 @@ package config
22
33import "github.com/pkg/errors"
44
5- type Config struct {
6- Version string
7- Sentinel struct {
8- App struct {
9- // Name represents the name of current running service.
10- Name string
11- // Type indicates the classification of the service (e.g. web service, API gateway).
12- Type int32
13- }
14- Log struct {
15- // Dir represents the log directory path.
16- Dir string
17- // UsePid indicates whether the filename ends with the process ID (PID).
18- UsePid bool
19- // Metric represents the configuration items of the metric log.
20- Metric struct {
21- SingleFileMaxSize uint64
22- MaxFileCount uint32
23- FlushIntervalSec uint32
24- }
25- }
5+ type Entity struct {
6+ // Version represents the format version of the entity.
7+ Version string
8+
9+ Sentinel SentinelConfig
10+ }
11+
12+ // SentinelConfig represent the general configuration of Sentinel.
13+ type SentinelConfig struct {
14+ App struct {
15+ // Name represents the name of current running service.
16+ Name string
17+ // Type indicates the classification of the service (e.g. web service, API gateway).
18+ Type int32
2619 }
20+ // Log represents configuration items related to logging.
21+ Log LogConfig
22+ // Stat represents configuration items related to statistics.
23+ Stat StatConfig
2724}
2825
2926// LogConfig represent the configuration of logging in Sentinel.
@@ -43,23 +40,15 @@ type MetricLogConfig struct {
4340 FlushIntervalSec uint32 `yaml:"flushIntervalSec"`
4441}
4542
46- // SentinelConfig represent the general configuration of Sentinel.
47- type SentinelConfig struct {
48- App struct {
49- // Name represents the name of current running service.
50- Name string
51- // Type indicates the classification of the service (e.g. web service, API gateway).
52- Type int32
53- }
54- // Log represents configuration items related to logging.
55- Log LogConfig
43+ // StatConfig represents the configuration items of statistics.
44+ type StatConfig struct {
45+ System SystemStatConfig `yaml:"system"`
5646}
5747
58- type Entity struct {
59- // Version represents the format version of the entity.
60- Version string
61-
62- Sentinel SentinelConfig
48+ // SystemStatConfig represents the configuration items of system statistics.
49+ type SystemStatConfig struct {
50+ // CollectIntervalMs represents the collecting interval of the system metrics collector.
51+ CollectIntervalMs uint32 `yaml:"collectIntervalMs"`
6352}
6453
6554func NewDefaultConfig () * Entity {
@@ -73,7 +62,11 @@ func NewDefaultConfig() *Entity {
7362 Name : UnknownProjectName ,
7463 Type : DefaultAppType ,
7564 },
76- Log : LogConfig {Metric : MetricLogConfig {SingleFileMaxSize : DefaultMetricLogSingleFileMaxSize , MaxFileCount : DefaultMetricLogMaxFileAmount , FlushIntervalSec : DefaultMetricLogFlushIntervalSec }},
65+ Log : LogConfig {Metric : MetricLogConfig {SingleFileMaxSize : DefaultMetricLogSingleFileMaxSize ,
66+ MaxFileCount : DefaultMetricLogMaxFileAmount , FlushIntervalSec : DefaultMetricLogFlushIntervalSec }},
67+ Stat : StatConfig {
68+ System : SystemStatConfig {CollectIntervalMs : DefaultSystemStatCollectIntervalMs },
69+ },
7770 },
7871 }
7972}
@@ -92,5 +85,8 @@ func checkValid(conf *SentinelConfig) error {
9285 if mc .SingleFileMaxSize <= 0 {
9386 return errors .New ("Bad metric log config: singleFileMaxSize <= 0" )
9487 }
88+ if conf .Stat .System .CollectIntervalMs == 0 {
89+ return errors .New ("Bad system stat config: collectIntervalMs = 0" )
90+ }
9591 return nil
9692}
0 commit comments