forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
look.go
45 lines (37 loc) · 1003 Bytes
/
look.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
// Package look defines common formatters for fields/types to be used when
// generating heartbeat events.
package look
import (
"time"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/heartbeat/reason"
)
// RTT formats a round-trip-time given as time.Duration into an
// event field. The duration is stored in `{"us": rtt}`.
func RTT(rtt time.Duration) common.MapStr {
if rtt < 0 {
rtt = 0
}
return common.MapStr{
"us": rtt / (time.Microsecond / time.Nanosecond),
}
}
// Reason formats an error into an error event field.
func Reason(err error) common.MapStr {
if r, ok := err.(reason.Reason); ok {
return reason.Fail(r)
}
return reason.FailIO(err)
}
// Timestamp converts an event timestamp into an compatible event timestamp for
// reporting.
func Timestamp(t time.Time) common.Time {
return common.Time(t)
}
// Status creates a service status message from an error value.
func Status(err error) string {
if err == nil {
return "up"
}
return "down"
}