forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
51 lines (41 loc) · 893 Bytes
/
metrics.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
package metrics
import (
"sync/atomic"
"time"
"go.pedge.io/lion/proto"
)
var metrics = &Metrics{}
var modified int64
func AddRepos(num int64) {
atomic.AddInt64(&metrics.Repos, num)
atomic.SwapInt64(&modified, 1)
}
func AddCommits(num int64) {
atomic.AddInt64(&metrics.Commits, num)
atomic.SwapInt64(&modified, 1)
}
func AddFiles(num int64) {
atomic.AddInt64(&metrics.Files, num)
atomic.SwapInt64(&modified, 1)
}
func AddBytes(num int64) {
atomic.AddInt64(&metrics.Bytes, num)
atomic.SwapInt64(&modified, 1)
}
func AddJobs(num int64) {
atomic.AddInt64(&metrics.Jobs, num)
atomic.SwapInt64(&modified, 1)
}
func AddPipelines(num int64) {
atomic.AddInt64(&metrics.Pipelines, num)
atomic.SwapInt64(&modified, 1)
}
func ReportMetrics() {
for {
write := atomic.SwapInt64(&modified, 0)
if write == 1 {
protolion.Info(metrics)
}
<-time.After(15 * time.Second)
}
}