forked from moira-alert/notifier
/
metrics.go
35 lines (31 loc) · 949 Bytes
/
metrics.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
package notifier
import (
"fmt"
"net"
"os"
"strings"
"time"
"github.com/cyberdelia/go-metrics-graphite"
"github.com/gosexy/to"
"github.com/rcrowley/go-metrics"
)
// InitMetrics inits graphite metrics and starts graphite flush cycle
func InitMetrics() {
graphiteURI := config.Get("graphite", "uri")
graphitePrefix := config.Get("graphite", "prefix")
graphiteInterval := to.Int64(config.Get("graphite", "interval"))
if graphiteURI != "" {
graphiteAddr, err := net.ResolveTCPAddr("tcp", graphiteURI)
if err != nil {
log.Errorf("Can not resolve graphiteURI %s: %s", graphiteURI, err)
return
}
hostname, err := os.Hostname()
if err != nil {
log.Errorf("Can not get OS hostname: %s", err)
return
}
shortname := strings.Split(hostname, ".")[0]
go graphite.Graphite(metrics.DefaultRegistry, time.Duration(graphiteInterval)*time.Second, fmt.Sprintf("%s.notifier.%s", graphitePrefix, shortname), graphiteAddr)
}
}