-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstatsd.go
39 lines (33 loc) · 1.07 KB
/
statsd.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
package main
//import "github.com/cactus/go-statsd-client/statsd"
import "time"
import "fmt"
type StatisticsSender interface {
Inc(string, int64, float32) error
Dec(string, int64, float32) error
Gauge(string, int64, float32) error
GaugeDelta(string, int64, float32) error
Timing(string, int64, float32) error
TimingDuration(string, time.Duration, float32) error
Set(string, string, float32) error
SetInt(string, int64, float32) error
Raw(string, string, float32) error
}
func SendStatsdMetricsFromMessage(statsd StatisticsSender, m *Message) error {
service, ok := m.Container.Path("service").Data().(string)
if !ok {
statsd.Inc("logs2kafka.unknown_service", 1, 1)
return nil
}
level, ok := m.Container.Path("level").Data().(string)
if ok {
if level == "DEBUG" {
statsd.Inc(fmt.Sprintf("app.log.messages,service=%s,level=DEBUG", service), 1, 0.1)
} else {
statsd.Inc(fmt.Sprintf("app.log.messages,service=%s,level=%s", service, level), 1, 1)
}
} else {
statsd.Inc(fmt.Sprintf("app.log.messages,service=%s,level=OTHER", service), 1, 0.4)
}
return nil
}