forked from cnosdb/cnosdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
63 lines (53 loc) · 1.74 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package monitor
import (
"errors"
"github.com/cnosdb/cnosdb/vend/common/monitor/diagnostics"
"time"
"github.com/cnosdb/cnosdb/vend/common/pkg/toml"
)
const (
// DefaultStoreEnabled is whether the system writes gathered information in
// an CnosDB system for historical analysis.
DefaultStoreEnabled = true
// DefaultStoreDatabase is the name of the database where gathered information is written.
DefaultStoreDatabase = "_internal"
// DefaultStoreInterval is the period between storing gathered information.
DefaultStoreInterval = 10 * time.Second
)
// Config represents the configuration for the monitor service.
type Config struct {
StoreEnabled bool `toml:"store-enabled"`
StoreDatabase string `toml:"store-database"`
StoreInterval toml.Duration `toml:"store-interval"`
}
// NewConfig returns an instance of Config with defaults.
func NewConfig() Config {
return Config{
StoreEnabled: DefaultStoreEnabled,
StoreDatabase: DefaultStoreDatabase,
StoreInterval: toml.Duration(DefaultStoreInterval),
}
}
// Validate validates that the configuration is acceptable.
func (c Config) Validate() error {
if c.StoreInterval <= 0 {
return errors.New("monitor store interval must be positive")
}
if c.StoreDatabase == "" {
return errors.New("monitor store database name must not be empty")
}
return nil
}
// Diagnostics returns a diagnostics representation of a subset of the Config.
func (c Config) Diagnostics() (*diagnostics.Diagnostics, error) {
if !c.StoreEnabled {
return diagnostics.RowFromMap(map[string]interface{}{
"store-enabled": false,
}), nil
}
return diagnostics.RowFromMap(map[string]interface{}{
"store-enabled": true,
"store-database": c.StoreDatabase,
"store-interval": c.StoreInterval,
}), nil
}