-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmetric.go
More file actions
30 lines (25 loc) · 753 Bytes
/
metric.go
File metadata and controls
30 lines (25 loc) · 753 Bytes
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
package ecsmetrics
import (
"time"
"github.com/AliceO2Group/Control/common/monitoring"
)
func NewMetric(name string) monitoring.Metric {
timestamp := time.Now()
metric := monitoring.Metric{Name: name, Timestamp: timestamp.UnixMilli()}
metric.AddTag("subsystem", "ECS")
return metric
}
// Timer* functions are meant to be used with defer statement to measure runtime of given function:
// defer TimerNS(&metric)()
func TimerMS(metric *monitoring.Metric) func() {
start := time.Now()
return func() {
metric.AddValue("execution_time_ms", time.Since(start).Milliseconds())
}
}
func TimerNS(metric *monitoring.Metric) func() {
start := time.Now()
return func() {
metric.AddValue("execution_time_ns", time.Since(start).Nanoseconds())
}
}