Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align timestamps #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion librato.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"math"
"net/http"
"sort"
"time"
)

type Measurement struct {
Counters []*Counter `json:"counters"`
Gauges []interface{} `json:"gauges"`
Source string `json:"source,omitempty"`
Time int64 `json:"measure_time"`
}

func (m *Measurement) Count() int {
Expand Down Expand Up @@ -80,7 +82,7 @@ func submitLibrato() (err error) {
return fmt.Errorf("%s: %s", resp.Status, string(raw))
}

log.Printf("%d measurements sent to librato\n", m.Count())
log.Printf("%d measurements sent to librato, timestamp: %d\n", m.Count(), m.Time)

resetTimers()

Expand All @@ -93,6 +95,13 @@ func buildMeasurement() (m *Measurement) {
m.Source = *libratoSource
}

t := time.Now().Unix()
if *snapTime {
// unix timestamp, matching our interval
t = t - (t % *interval)
}
m.Time = t

m.Counters = make([]*Counter, len(counters))
m.Gauges = make([]interface{}, len(gauges))

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
libratoToken = flag.String("token", "", "librato api token (LIBRATO_TOKEN)")
libratoSource = flag.String("source", "", "librato api source (LIBRATO_SOURCE)")
interval = flag.Int64("flush", 60, "interval at which data is sent to librato (in seconds)")
snapTime = flag.Bool("snaptime", false, "snap timestamps to interval, to align with other servers started at different offsets")
percentiles = flag.String("percentiles", "", "comma separated list of percentiles to calculate for timers (eg. \"95,99.5\")")
proxy = flag.String("proxy", "", "send metrics to a proxy rather than directly to librato")
debug = flag.Bool("debug", false, "enable logging of inputs and submissions")
Expand Down