Ver código fonte

snap: export durations of marshalling cost during snapshot save

Currently, total duration of snapshot saving is exported for
prometheus. For more detailed analysis, this commit let etcd export
durations of marshalling for prometheus.
Hitoshi Mitake 10 anos atrás
pai
commit
7a6d33620f
2 arquivos alterados com 11 adições e 1 exclusões
  1. 8 1
      snap/metrics.go
  2. 3 0
      snap/snapshotter.go

+ 8 - 1
snap/metrics.go

@@ -18,15 +18,22 @@ import "github.com/coreos/etcd/Godeps/_workspace/src/github.com/prometheus/clien
 
 
 var (
 var (
 	// TODO: save_fsync latency?
 	// TODO: save_fsync latency?
-	// TODO: save_encoding latency?
 	saveDurations = prometheus.NewSummary(prometheus.SummaryOpts{
 	saveDurations = prometheus.NewSummary(prometheus.SummaryOpts{
 		Namespace: "etcd",
 		Namespace: "etcd",
 		Subsystem: "snapshot",
 		Subsystem: "snapshot",
 		Name:      "save_total_durations_microseconds",
 		Name:      "save_total_durations_microseconds",
 		Help:      "The total latency distributions of save called by snapshot.",
 		Help:      "The total latency distributions of save called by snapshot.",
 	})
 	})
+
+	marshallingDurations = prometheus.NewSummary(prometheus.SummaryOpts{
+		Namespace: "etcd",
+		Subsystem: "snapshot",
+		Name:      "save_marshalling_durations_microseconds",
+		Help:      "The marshalling cost distributions of save called by snapshot.",
+	})
 )
 )
 
 
 func init() {
 func init() {
 	prometheus.MustRegister(saveDurations)
 	prometheus.MustRegister(saveDurations)
+	prometheus.MustRegister(marshallingDurations)
 }
 }

+ 3 - 0
snap/snapshotter.go

@@ -73,7 +73,10 @@ func (s *Snapshotter) save(snapshot *raftpb.Snapshot) error {
 	d, err := snap.Marshal()
 	d, err := snap.Marshal()
 	if err != nil {
 	if err != nil {
 		return err
 		return err
+	} else {
+		marshallingDurations.Observe(float64(time.Since(start).Nanoseconds() / int64(time.Microsecond)))
 	}
 	}
+
 	err = ioutil.WriteFile(path.Join(s.dir, fname), d, 0666)
 	err = ioutil.WriteFile(path.Join(s.dir, fname), d, 0666)
 	if err == nil {
 	if err == nil {
 		saveDurations.Observe(float64(time.Since(start).Nanoseconds() / int64(time.Microsecond)))
 		saveDurations.Observe(float64(time.Since(start).Nanoseconds() / int64(time.Microsecond)))