forked from tanitall/memo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.22 KB
/
main.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
package metric
import (
"fmt"
"github.com/DataDog/datadog-go/statsd"
"github.com/jchavannes/jgo/jerr"
"github.com/memocash/memo/app/config"
)
const (
NameHttpRequest = "http_request"
NameHttpRequestTime = "http_request_time"
NameMemoBroadcast = "memo_broadcast"
NameMemoSave = "memo_save"
NameTransactionSaveTime = "transaction_save_time"
NamePostSearch = "post_search"
)
const (
TagUrl = "url"
TagPattern = "pattern"
TagResponseCode = "response_code"
TagOutputType = "type"
TagSearchTerm = "search_term"
TagCmd = "cmd"
TagCode = "code"
TagReason = "reason"
)
var statsdClient *statsd.Client
var statsdDisabled bool
func getStatsd() (*statsd.Client, error) {
if statsdDisabled {
return nil, nil
} else if statsdClient == nil {
statsdConfig := config.GetStatsdConfig()
if statsdConfig.Port == 0 || statsdConfig.Host == "" {
statsdDisabled = true
return nil, nil
}
var err error
statsdClient, err = statsd.New(fmt.Sprintf("%s:%d", statsdConfig.Host, statsdConfig.Port))
if err != nil {
return nil, jerr.Get("error getting statsd client", err)
}
statsdClient.Namespace = fmt.Sprintf("%s.", statsdConfig.Namespace)
}
return statsdClient, nil
}