Просмотр исходного кода

Use Sample to get Histogram stats in reporters.

Richard Crowley 12 лет назад
Родитель
Сommit
acb13c899b
7 измененных файлов с 49 добавлено и 42 удалено
  1. 7 6
      graphite.go
  2. 7 6
      json.go
  3. 7 6
      librato/librato.go
  4. 7 6
      log.go
  5. 7 6
      stathat/stathat.go
  6. 7 6
      syslog.go
  7. 7 6
      writer.go

+ 7 - 6
graphite.go

@@ -32,12 +32,13 @@ func graphite(r Registry, prefix string, addr *net.TCPAddr) error {
 		case Gauge:
 			fmt.Fprintf(w, "%s.%s.value %d %d\n", prefix, name, m.Value(), now)
 		case Histogram:
-			ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
-			fmt.Fprintf(w, "%s.%s.count %d %d\n", prefix, name, m.Count(), now)
-			fmt.Fprintf(w, "%s.%s.min %d %d\n", prefix, name, m.Min(), now)
-			fmt.Fprintf(w, "%s.%s.max %d %d\n", prefix, name, m.Max(), now)
-			fmt.Fprintf(w, "%s.%s.mean %.2f %d\n", prefix, name, m.Mean(), now)
-			fmt.Fprintf(w, "%s.%s.std-dev %.2f %d\n", prefix, name, m.StdDev(), now)
+			s := m.Sample()
+			ps := s.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
+			fmt.Fprintf(w, "%s.%s.count %d %d\n", prefix, name, s.Count(), now)
+			fmt.Fprintf(w, "%s.%s.min %d %d\n", prefix, name, s.Min(), now)
+			fmt.Fprintf(w, "%s.%s.max %d %d\n", prefix, name, s.Max(), now)
+			fmt.Fprintf(w, "%s.%s.mean %.2f %d\n", prefix, name, s.Mean(), now)
+			fmt.Fprintf(w, "%s.%s.std-dev %.2f %d\n", prefix, name, s.StdDev(), now)
 			fmt.Fprintf(w, "%s.%s.50-percentile %.2f %d\n", prefix, name, ps[0], now)
 			fmt.Fprintf(w, "%s.%s.75-percentile %.2f %d\n", prefix, name, ps[1], now)
 			fmt.Fprintf(w, "%s.%s.95-percentile %.2f %d\n", prefix, name, ps[2], now)

+ 7 - 6
json.go

@@ -19,12 +19,13 @@ func (r StandardRegistry) MarshalJSON() ([]byte, error) {
 			m.Check()
 			values["error"] = m.Error()
 		case Histogram:
-			ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
-			values["count"] = m.Count()
-			values["min"] = m.Min()
-			values["max"] = m.Max()
-			values["mean"] = m.Mean()
-			values["stddev"] = m.StdDev()
+			s := m.Sample()
+			ps := s.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
+			values["count"] = s.Count()
+			values["min"] = s.Min()
+			values["max"] = s.Max()
+			values["mean"] = s.Mean()
+			values["stddev"] = s.StdDev()
 			values["median"] = ps[0]
 			values["75%%"] = ps[1]
 			values["95%%"] = ps[2]

+ 7 - 6
librato/librato.go

@@ -99,17 +99,18 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
 		case metrics.Histogram:
 			if m.Count() > 0 {
 				gauges := make([]Measurement, histogramGaugeCount, histogramGaugeCount)
+				s := m.Sample()
 				measurement[Name] = fmt.Sprintf("%s.%s", name, "hist")
-				measurement[Count] = uint64(m.Count())
-				measurement[Sum] = m.Mean() * float64(m.Count())
-				measurement[Max] = float64(m.Max())
-				measurement[Min] = float64(m.Min())
-				measurement[SumSquares] = sumSquares(m)
+				measurement[Count] = uint64(s.Count())
+				measurement[Sum] = s.Mean() * float64(s.Count())
+				measurement[Max] = float64(s.Max())
+				measurement[Min] = float64(s.Min())
+				measurement[SumSquares] = sumSquares(s)
 				gauges[0] = measurement
 				for i, p := range self.Percentiles {
 					gauges[i+1] = Measurement{
 						Name:   fmt.Sprintf("%s.%.2f", measurement[Name], p),
-						Value:  m.Percentile(p),
+						Value:  s.Percentile(p),
 						Period: measurement[Period],
 					}
 				}

+ 7 - 6
log.go

@@ -22,13 +22,14 @@ func Log(r Registry, d time.Duration, l *log.Logger) {
 				l.Printf("healthcheck %s\n", name)
 				l.Printf("  error:       %v\n", m.Error())
 			case Histogram:
-				ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
+				s := m.Sample()
+				ps := s.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
 				l.Printf("histogram %s\n", name)
-				l.Printf("  count:       %9d\n", m.Count())
-				l.Printf("  min:         %9d\n", m.Min())
-				l.Printf("  max:         %9d\n", m.Max())
-				l.Printf("  mean:        %12.2f\n", m.Mean())
-				l.Printf("  stddev:      %12.2f\n", m.StdDev())
+				l.Printf("  count:       %9d\n", s.Count())
+				l.Printf("  min:         %9d\n", s.Min())
+				l.Printf("  max:         %9d\n", s.Max())
+				l.Printf("  mean:        %12.2f\n", s.Mean())
+				l.Printf("  stddev:      %12.2f\n", s.StdDev())
 				l.Printf("  median:      %12.2f\n", ps[0])
 				l.Printf("  75%%:         %12.2f\n", ps[1])
 				l.Printf("  95%%:         %12.2f\n", ps[2])

+ 7 - 6
stathat/stathat.go

@@ -25,12 +25,13 @@ func sh(r metrics.Registry, userkey string) error {
 		case metrics.Gauge:
 			stathat.PostEZValue(name, userkey, float64(m.Value()))
 		case metrics.Histogram:
-			ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
-			stathat.PostEZCount(name+".count", userkey, int(m.Count()))
-			stathat.PostEZValue(name+".min", userkey, float64(m.Min()))
-			stathat.PostEZValue(name+".max", userkey, float64(m.Max()))
-			stathat.PostEZValue(name+".mean", userkey, float64(m.Mean()))
-			stathat.PostEZValue(name+".std-dev", userkey, float64(m.StdDev()))
+			s := m.Sample()
+			ps := s.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
+			stathat.PostEZCount(name+".count", userkey, int(s.Count()))
+			stathat.PostEZValue(name+".min", userkey, float64(s.Min()))
+			stathat.PostEZValue(name+".max", userkey, float64(s.Max()))
+			stathat.PostEZValue(name+".mean", userkey, float64(s.Mean()))
+			stathat.PostEZValue(name+".std-dev", userkey, float64(s.StdDev()))
 			stathat.PostEZValue(name+".50-percentile", userkey, float64(ps[0]))
 			stathat.PostEZValue(name+".75-percentile", userkey, float64(ps[1]))
 			stathat.PostEZValue(name+".95-percentile", userkey, float64(ps[2]))

+ 7 - 6
syslog.go

@@ -22,15 +22,16 @@ func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
 				m.Check()
 				w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, m.Error()))
 			case Histogram:
-				ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
+				s := m.Sample()
+				ps := s.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
 				w.Info(fmt.Sprintf(
 					"histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f",
 					name,
-					m.Count(),
-					m.Min(),
-					m.Max(),
-					m.Mean(),
-					m.StdDev(),
+					s.Count(),
+					s.Min(),
+					s.Max(),
+					s.Mean(),
+					s.StdDev(),
 					ps[0],
 					ps[1],
 					ps[2],

+ 7 - 6
writer.go

@@ -29,13 +29,14 @@ func WriteOnce(r Registry, w io.Writer) {
 			fmt.Fprintf(w, "healthcheck %s\n", name)
 			fmt.Fprintf(w, "  error:       %v\n", m.Error())
 		case Histogram:
-			ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
+			s := m.Sample()
+			ps := s.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
 			fmt.Fprintf(w, "histogram %s\n", name)
-			fmt.Fprintf(w, "  count:       %9d\n", m.Count())
-			fmt.Fprintf(w, "  min:         %9d\n", m.Min())
-			fmt.Fprintf(w, "  max:         %9d\n", m.Max())
-			fmt.Fprintf(w, "  mean:        %12.2f\n", m.Mean())
-			fmt.Fprintf(w, "  stddev:      %12.2f\n", m.StdDev())
+			fmt.Fprintf(w, "  count:       %9d\n", s.Count())
+			fmt.Fprintf(w, "  min:         %9d\n", s.Min())
+			fmt.Fprintf(w, "  max:         %9d\n", s.Max())
+			fmt.Fprintf(w, "  mean:        %12.2f\n", s.Mean())
+			fmt.Fprintf(w, "  stddev:      %12.2f\n", s.StdDev())
 			fmt.Fprintf(w, "  median:      %12.2f\n", ps[0])
 			fmt.Fprintf(w, "  75%%:         %12.2f\n", ps[1])
 			fmt.Fprintf(w, "  95%%:         %12.2f\n", ps[2])