Skip to content

Timer

See Timer for the concept.

Call record() with a value:

import (
    "github.com/Netflix/spectator-go/v2/spectator"
    "time"
)

func main() {
    config, _ := spectator.NewConfig("udp", nil, nil)
    registry, _ := spectator.NewRegistry(config)

    registry.Timer("server.requestLatency", nil).Record(500 * time.Millisecond)

    requestLatency := registry.NewId("server.requestLatency", nil)
    registry.TimerWithId(requestLatency).Record(500 * time.Millisecond)
}

Units

Go Timers always report values to backends in seconds (see Use Base Units). The API accepts a time.Duration value, which is converted to seconds when reporting.

Percentile Timer

Call Record() with a value:

import (
    "github.com/Netflix/spectator-go/v2/spectator"
    "time"
)

func main() {
    config, _ := spectator.NewConfig("udp", nil, nil)
    registry, _ := spectator.NewRegistry(config)

    registry.PercentileTimer("server.requestLatency", nil).Record(500 * time.Millisecond)

    requestLatency := registry.NewId("server.requestLatency", nil)
    registry.PercentileTimerWithId(requestLatency).Record(500 * time.Millisecond)
}