-
Notifications
You must be signed in to change notification settings - Fork 2
/
stats.go
64 lines (52 loc) · 1.44 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
package kafkasync
import (
"bytes"
"fmt"
"log"
"time"
)
type Stats struct {
// Diff statistics
Created uint64
Modified uint64
Deleted uint64
Unchanged uint64
// Producer statistics
SendCount uint64
SuccessCount int64
ErrorCount int64
// The count of defined key values.
Count uint64
// Performance statistics
MessagesInTopic uint64
ReadTopicDuration time.Duration
SyncDuration time.Duration
TotalDuration time.Duration
startTime time.Time
}
func NewStats() *Stats {
return &Stats{startTime: time.Now()}
}
func (stats *Stats) Elapsed() time.Duration {
return time.Since(stats.startTime)
}
func (stats *Stats) LogString() string {
buf := &bytes.Buffer{}
fmt.Fprintf(buf, "- %d creations, %d modifications, %d deletions, %d unchanged\n",
stats.Created, stats.Modified, stats.Deleted, stats.Unchanged)
fmt.Fprintf(buf, "- %d active values\n", stats.Count)
fmt.Fprintf(buf, "- %d messages sent\n", stats.SendCount)
if stats.SuccessCount >= 0 {
fmt.Fprintf(buf, "- %d send successes\n", stats.SuccessCount)
}
if stats.ErrorCount >= 0 {
fmt.Fprintf(buf, "- %d send errors\n", stats.ErrorCount)
}
fmt.Fprintf(buf, "- read: %s (%d messages)\n", stats.ReadTopicDuration, stats.MessagesInTopic)
fmt.Fprintf(buf, "- sync: %s\n", stats.SyncDuration)
fmt.Fprintf(buf, "- total: %s", stats.TotalDuration)
return buf.String()
}
func (stats *Stats) Log() {
log.Print("synchronization status:\n", stats.LogString())
}