forked from moira-alert/notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
34 lines (30 loc) · 885 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
package notifier
import (
"fmt"
"net"
"os"
"strings"
"time"
"github.com/cyberdelia/go-metrics-graphite"
"github.com/rcrowley/go-metrics"
)
// InitMetrics inits graphite metrics and starts graphite flush cycle
func InitMetrics() {
graphiteURI := config.Graphite.URI
graphitePrefix := config.Graphite.Prefix
graphiteInterval := config.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)
}
}