• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hamba / statter / 24285139690

11 Apr 2026 03:03PM UTC coverage: 94.606% (-0.4%) from 94.987%
24285139690

push

github

web-flow
fix: minor issues (#185)

11 of 16 new or added lines in 3 files covered. (68.75%)

1 existing line in 1 file now uncovered.

1140 of 1205 relevant lines covered (94.61%)

476.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.06
/runtime/runtime.go
1
// Package runtime implements runtime stats collection convenience functions.
2
package runtime
3

4
import (
5
        "context"
6
        "runtime"
7
        "time"
8

9
        "github.com/hamba/statter/v2"
10
)
11

12
// DefaultRuntimeInterval is the default runtime collection interval.
13
var DefaultRuntimeInterval = 10 * time.Second
14

15
// Collect collects runtime metrics periodically sending them to s.
16
//
17
// Collect blocks until the process exits. To stop collection, use
18
// CollectWithContext instead.
19
func Collect(s *statter.Statter) {
2✔
20
        CollectWithContext(context.Background(), s, DefaultRuntimeInterval)
2✔
21
}
2✔
22

23
// CollectEvery collects runtime metrics at interval d sending them to s.
24
//
25
// CollectEvery blocks until the process exits. To stop collection, use
26
// CollectWithContext instead.
UNCOV
27
func CollectEvery(s *statter.Statter, d time.Duration) {
×
NEW
28
        CollectWithContext(context.Background(), s, d)
×
NEW
29
}
×
30

31
// CollectWithContext collects runtime metrics at interval d sending them to s,
32
// stopping when ctx is done.
33
func CollectWithContext(ctx context.Context, s *statter.Statter, d time.Duration) {
2✔
34
        tick := time.NewTicker(d)
2✔
35
        defer tick.Stop()
2✔
36

2✔
37
        for {
2,158✔
38
                select {
2,156✔
NEW
39
                case <-ctx.Done():
×
NEW
40
                        return
×
41
                case <-tick.C:
2,156✔
42
                        r := newRuntimeStats()
2,156✔
43
                        r.send(s)
2,156✔
44
                }
45
        }
46
}
47

48
type runtimeStats struct {
49
        *runtime.MemStats
50

51
        goroutines int
52
}
53

54
func newRuntimeStats() *runtimeStats {
2,156✔
55
        r := &runtimeStats{MemStats: &runtime.MemStats{}}
2,156✔
56
        runtime.ReadMemStats(r.MemStats)
2,156✔
57
        r.goroutines = runtime.NumGoroutine()
2,156✔
58

2,156✔
59
        return r
2,156✔
60
}
2,156✔
61

62
func (r *runtimeStats) send(s *statter.Statter) {
2,155✔
63
        ms := r.MemStats
2,155✔
64

2,155✔
65
        // CPU
2,155✔
66
        s.Gauge("runtime.cpu.goroutines").Set(float64(r.goroutines))
2,155✔
67

2,155✔
68
        // Memory
2,155✔
69
        // General
2,155✔
70
        s.Gauge("runtime.memory.alloc").Set(float64(ms.Alloc))
2,155✔
71
        s.Gauge("runtime.memory.total").Set(float64(ms.TotalAlloc))
2,155✔
72
        s.Gauge("runtime.memory.sys").Set(float64(ms.Sys))
2,155✔
73
        s.Gauge("runtime.memory.lookups").Set(float64(ms.Lookups))
2,155✔
74
        s.Gauge("runtime.memory.mallocs").Set(float64(ms.Mallocs))
2,155✔
75
        s.Gauge("runtime.memory.frees").Set(float64(ms.Frees))
2,155✔
76

2,155✔
77
        // Heap
2,155✔
78
        s.Gauge("runtime.memory.heap.alloc").Set(float64(ms.HeapAlloc))
2,155✔
79
        s.Gauge("runtime.memory.heap.sys").Set(float64(ms.HeapSys))
2,155✔
80
        s.Gauge("runtime.memory.heap.idle").Set(float64(ms.HeapIdle))
2,155✔
81
        s.Gauge("runtime.memory.heap.inuse").Set(float64(ms.HeapInuse))
2,155✔
82
        s.Gauge("runtime.memory.heap.objects").Set(float64(ms.HeapObjects))
2,155✔
83
        s.Gauge("runtime.memory.heap.released").Set(float64(ms.HeapReleased))
2,155✔
84

2,155✔
85
        // Stack
2,155✔
86
        s.Gauge("runtime.memory.stack.inuse").Set(float64(ms.StackInuse))
2,155✔
87
        s.Gauge("runtime.memory.stack.sys").Set(float64(ms.StackSys))
2,155✔
88
        s.Gauge("runtime.memory.stack.mcache_inuse").Set(float64(ms.MCacheInuse))
2,155✔
89
        s.Gauge("runtime.memory.stack.mcache_sys").Set(float64(ms.MCacheSys))
2,155✔
90
        s.Gauge("runtime.memory.stack.mspan_inuse").Set(float64(ms.MSpanInuse))
2,155✔
91
        s.Gauge("runtime.memory.stack.mspan_sys").Set(float64(ms.MSpanSys))
2,155✔
92

2,155✔
93
        // GC
2,155✔
94
        s.Gauge("runtime.memory.gc.last").Set(float64(ms.LastGC))
2,155✔
95
        s.Gauge("runtime.memory.gc.next").Set(float64(ms.NextGC))
2,155✔
96
        s.Gauge("runtime.memory.gc.count").Set(float64(ms.NumGC))
2,155✔
97
        s.Gauge("runtime.memory.gc.pause_total").Set(float64(ms.PauseTotalNs))
2,155✔
98
        pauseNs := ms.PauseNs[(ms.NumGC+255)%256]
2,155✔
99
        s.Timing("runtime.memory.gc.pause").Observe(time.Duration(pauseNs))
2,155✔
100
}
2,155✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc