forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
43 lines (33 loc) · 1.05 KB
/
settings.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
package metrics
import "github.com/grafana/grafana/pkg/setting"
type MetricPublisher interface {
Publish(metrics []Metric)
}
type MetricSettings struct {
Enabled bool
IntervalSeconds int64
Publishers []MetricPublisher
}
func readSettings() *MetricSettings {
var settings = &MetricSettings{
Enabled: false,
Publishers: make([]MetricPublisher, 0),
}
var section, err = setting.Cfg.GetSection("metrics")
if err != nil {
metricsLogger.Crit("Unable to find metrics config section", "error", err)
return nil
}
settings.Enabled = section.Key("enabled").MustBool(false)
settings.IntervalSeconds = section.Key("interval_seconds").MustInt64(10)
if !settings.Enabled {
return settings
}
if graphitePublisher, err := CreateGraphitePublisher(); err != nil {
metricsLogger.Error("Failed to init Graphite metric publisher", "error", err)
} else if graphitePublisher != nil {
metricsLogger.Info("Metrics publisher initialized", "type", "graphite")
settings.Publishers = append(settings.Publishers, graphitePublisher)
}
return settings
}