metrics
API
metrics
packageAPI reference for the metrics
package.
I
interface
Gauge
Gauge tracks a float64 value that can go up and down.
pkg/metrics/metrics.go:17-24
type Gauge interface
I
interface
Histogram
Histogram records observed float64 values in buckets.
pkg/metrics/metrics.go:27-29
type Histogram interface
Methods
I
interface
Timer
Timer measures elapsed time for an operation.
pkg/metrics/metrics.go:32-35
type Timer interface
Methods
ObserveDuration
Method
func ObserveDuration(...)
S
struct
SimpleCounter
SimpleCounter is a mutex-protected Counter implementation.
pkg/metrics/metrics.go:47-50
type SimpleCounter struct
Methods
Fields
| Name | Type | Description |
|---|---|---|
| mu | sync.Mutex | |
| v | int64 |
F
function
NewCounter
NewCounter creates a new SimpleCounter.
Returns
pkg/metrics/metrics.go:53-53
func NewCounter() *SimpleCounter
{ return &SimpleCounter{} }
S
struct
SimpleGauge
SimpleGauge is a mutex-protected Gauge implementation.
pkg/metrics/metrics.go:67-70
type SimpleGauge struct
Methods
Set
Method
Parameters
v
float64
func (*SimpleGauge) Set(v float64)
{
g.mu.Lock()
defer g.mu.Unlock()
g.v = v
}
Inc
Method
func (*SimpleGauge) Inc()
{ g.Add(1) }
Dec
Method
func (*SimpleGauge) Dec()
{ g.Sub(1) }
Add
Method
Parameters
v
float64
func (*SimpleGauge) Add(v float64)
{
g.mu.Lock()
defer g.mu.Unlock()
g.v += v
}
Sub
Method
Parameters
v
float64
func (*SimpleGauge) Sub(v float64)
{
g.mu.Lock()
defer g.mu.Unlock()
g.v -= v
}
Value
Method
Returns
float64
func (*SimpleGauge) Value() float64
{
g.mu.Lock()
defer g.mu.Unlock()
return g.v
}
Fields
| Name | Type | Description |
|---|---|---|
| mu | sync.Mutex | |
| v | float64 |
F
function
NewGauge
NewGauge creates a new SimpleGauge.
Returns
pkg/metrics/metrics.go:73-73
func NewGauge() *SimpleGauge
{ return &SimpleGauge{} }
S
struct
SimpleHistogram
SimpleHistogram is a mutex-protected Histogram implementation.
pkg/metrics/metrics.go:98-104
type SimpleHistogram struct
Methods
Observe
Method
Parameters
v
float64
func (*SimpleHistogram) Observe(v float64)
{
h.mu.Lock()
defer h.mu.Unlock()
h.total++
h.sum += v
for i, b := range h.buckets {
if v <= b {
h.counts[i]++
return
}
}
h.counts[len(h.counts)-1]++
}
Fields
| Name | Type | Description |
|---|---|---|
| mu | sync.Mutex | |
| buckets | []float64 | |
| counts | []int64 | |
| total | int64 | |
| sum | float64 |
F
function
NewHistogram
NewHistogram creates a new SimpleHistogram with the given bucket boundaries.
Parameters
buckets
[]float64
Returns
pkg/metrics/metrics.go:107-114
func NewHistogram(buckets []float64) *SimpleHistogram
{
sorted := append([]float64(nil), buckets...)
sort.Float64s(sorted)
return &SimpleHistogram{
buckets: sorted,
counts: make([]int64, len(sorted)+1),
}
}
S
SimpleTimer
SimpleTimer is a basic Timer implementation.
pkg/metrics/metrics.go:131-131
type SimpleTimer struct
Methods
ObserveDuration
Method
func (*SimpleTimer) ObserveDuration()
{}
F
function
NewTimer
NewTimer creates a new SimpleTimer.
Returns
pkg/metrics/metrics.go:134-134
func NewTimer() *SimpleTimer
{ return &SimpleTimer{} }