-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.go
67 lines (52 loc) · 1.79 KB
/
stats.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
64
65
66
67
// Copyright (c) 2014 The SkyDNS Authors. All rights reserved.
// Use of this source code is governed by The MIT License (MIT) that can be
// found in the LICENSE file.
package main
import (
"github.com/rcrowley/go-metrics"
"github.com/rcrowley/go-metrics/stathat"
"net"
"os"
)
var (
StatsForwardCount metrics.Counter
StatsLookupCount metrics.Counter
StatsRequestCount metrics.Counter
StatsDnssecOkCount metrics.Counter
StatsDnssecCacheMiss metrics.Counter
StatsNameErrorCount metrics.Counter
StatsNoDataCount metrics.Counter
graphiteServer = os.Getenv("GRAPHITE_SERVER")
graphitePrefix = os.Getenv("GRAPHITE_PREFIX")
stathatUser = os.Getenv("STATHAT_USER")
)
func init() {
if graphitePrefix == "" {
graphitePrefix = "skydns"
}
StatsForwardCount = metrics.NewCounter()
metrics.Register("skydns-forward-requests", StatsForwardCount)
StatsDnssecOkCount = metrics.NewCounter()
metrics.Register("skydns-dnssecok-requests", StatsDnssecOkCount)
StatsDnssecCacheMiss = metrics.NewCounter()
metrics.Register("skydns-dnssec-cache-miss", StatsDnssecCacheMiss)
StatsLookupCount = metrics.NewCounter()
metrics.Register("skydns-internal-lookups", StatsLookupCount)
StatsRequestCount = metrics.NewCounter()
metrics.Register("skydns-requests", StatsRequestCount)
StatsNameErrorCount = metrics.NewCounter()
metrics.Register("skydns-nameerror-responses", StatsNameErrorCount)
StatsNoDataCount = metrics.NewCounter()
metrics.Register("skydns-nodata-responses", StatsNoDataCount)
}
func statsCollect() {
if graphiteServer != "" {
addr, err := net.ResolveTCPAddr("tcp", graphiteServer)
if err == nil {
go metrics.Graphite(metrics.DefaultRegistry, 10e9, graphitePrefix, addr)
}
}
if stathatUser != "" {
go stathat.Stathat(metrics.DefaultRegistry, 10e9, stathatUser)
}
}