Quellcode durchsuchen

coerce timestamps so graphs from disparate sources line up

mihasya vor 11 Jahren
Ursprung
Commit
a924b1eb25
1 geänderte Dateien mit 4 neuen und 3 gelöschten Zeilen
  1. 4 3
      librato/librato.go

+ 4 - 3
librato/librato.go

@@ -28,10 +28,11 @@ type Reporter struct {
 	Registry        metrics.Registry
 	Percentiles     []float64              // percentiles to report on histogram metrics
 	TimerAttributes map[string]interface{} // units in which timers will be displayed
+	intervalSec     int64
 }
 
 func NewReporter(r metrics.Registry, d time.Duration, e string, t string, s string, p []float64, u time.Duration) *Reporter {
-	return &Reporter{e, t, s, d, r, p, translateTimerAttributes(u)}
+	return &Reporter{e, t, s, d, r, p, translateTimerAttributes(u), int64(d / time.Second)}
 }
 
 func Librato(r metrics.Registry, d time.Duration, e string, t string, s string, p []float64, u time.Duration) {
@@ -78,10 +79,10 @@ func sumSquaresTimer(t metrics.Timer) float64 {
 
 func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot Batch, err error) {
 	snapshot = Batch{
-		MeasureTime: now.Unix(),
+		// coerce timestamps to a stepping fn so that they line up in Librato graphs
+		MeasureTime: (now.Unix() / self.intervalSec) * self.intervalSec,
 		Source:      self.Source,
 	}
-	snapshot.MeasureTime = now.Unix()
 	snapshot.Gauges = make([]Measurement, 0)
 	snapshot.Counters = make([]Measurement, 0)
 	histogramGaugeCount := 1 + len(self.Percentiles)