/
stats.go
66 lines (54 loc) · 1.36 KB
/
stats.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package historyarchive
import "sync/atomic"
// golang will auto wrap them back to 0 if they overflow after addition.
type archiveStats struct {
requests atomic.Uint32
fileDownloads atomic.Uint32
fileUploads atomic.Uint32
cacheHits atomic.Uint32
cacheBw atomic.Uint64
backendName string
}
type ArchiveStats interface {
GetRequests() uint32
GetDownloads() uint32
GetUploads() uint32
GetCacheHits() uint32
GetCacheBandwidth() uint64
GetBackendName() string
}
func (as *archiveStats) incrementDownloads() {
as.fileDownloads.Add(1)
as.incrementRequests()
}
func (as *archiveStats) incrementUploads() {
as.fileUploads.Add(1)
as.incrementRequests()
}
func (as *archiveStats) incrementRequests() {
as.requests.Add(1)
}
func (as *archiveStats) incrementCacheHits() {
as.cacheHits.Add(1)
}
func (as *archiveStats) incrementCacheBandwidth(bytes int64) {
as.cacheBw.Add(uint64(bytes))
}
func (as *archiveStats) GetRequests() uint32 {
return as.requests.Load()
}
func (as *archiveStats) GetDownloads() uint32 {
return as.fileDownloads.Load()
}
func (as *archiveStats) GetUploads() uint32 {
return as.fileUploads.Load()
}
func (as *archiveStats) GetBackendName() string {
return as.backendName
}
func (as *archiveStats) GetCacheHits() uint32 {
return as.cacheHits.Load()
}
func (as *archiveStats) GetCacheBandwidth() uint64 {
return as.cacheBw.Load()
}