forked from Bo0mer/mozzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpmetrics.go
44 lines (37 loc) · 1.05 KB
/
httpmetrics.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
package mozzle
import (
"strconv"
cfevent "github.com/cloudfoundry/sonde-go/events"
)
type httpMetrics struct {
*cfevent.HttpStartStop
App application
}
func (r httpMetrics) EmitTo(e Emitter) {
attributes := attributes(r.App)
attributes["instance"] = strconv.Itoa(int(r.GetInstanceIndex()))
attributes["method"] = r.GetMethod().String()
attributes["request_id"] = r.GetRequestId().String()
attributes["status_code"] = strconv.Itoa(int(r.GetStatusCode()))
switch r.GetPeerType() {
case cfevent.PeerType_Client:
attributes["peer"] = "client"
case cfevent.PeerType_Server:
attributes["peer"] = "server"
default:
attributes["peer"] = "unknown"
}
durationMillis := (r.GetStopTimestamp() - r.GetStartTimestamp()) / 1000000
e.Emit(forApp(r.App, Metric{
Service: "http response time_ms",
Metric: int(durationMillis),
State: "ok",
Attributes: attributes,
}))
e.Emit(forApp(r.App, Metric{
Service: "http response content_length_bytes",
Metric: int(r.GetContentLength()),
State: "ok",
Attributes: attributes,
}))
}