package rafthttp import ( "time" "github.com/coreos/etcd-starter/Godeps/_workspace/src/github.com/coreos/etcd/pkg/types" "github.com/coreos/etcd-starter/Godeps/_workspace/src/github.com/coreos/etcd/raft/raftpb" "github.com/coreos/etcd-starter/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus" ) var ( msgSentDuration = prometheus.NewSummaryVec( prometheus.SummaryOpts{ Name: "rafthttp_message_sent_latency_microseconds", Help: "message sent latency distributions.", }, []string{"channel", "remoteID", "msgType"}, ) msgSentFailed = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "rafthttp_message_sent_failed_total", Help: "The total number of failed messages sent.", }, []string{"channel", "remoteID", "msgType"}, ) ) func init() { prometheus.MustRegister(msgSentDuration) prometheus.MustRegister(msgSentFailed)
func ExampleSummaryVec() { temps := prometheus.NewSummaryVec( prometheus.SummaryOpts{ Name: "pond_temperature_celsius", Help: "The temperature of the frog pond.", // Sorry, we can't measure how badly it smells. }, []string{"species"}, ) // Simulate some observations. for i := 0; i < 1000; i++ { temps.WithLabelValues("litoria-caerulea").Observe(30 + math.Floor(120*math.Sin(float64(i)*0.1))/10) temps.WithLabelValues("lithobates-catesbeianus").Observe(32 + math.Floor(100*math.Cos(float64(i)*0.11))/10) } // Just for demonstration, let's check the state of the summary vector // by (ab)using its Collect method and the Write method of its elements // (which is usually only used by Prometheus internally - code like the // following will never appear in your own code). metricChan := make(chan prometheus.Metric) go func() { defer close(metricChan) temps.Collect(metricChan) }() metricStrings := []string{} for metric := range metricChan { dtoMetric := &dto.Metric{} metric.Write(dtoMetric) metricStrings = append(metricStrings, proto.MarshalTextString(dtoMetric)) } sort.Strings(metricStrings) // For reproducible print order. fmt.Println(metricStrings) // Output: // [label: < // name: "species" // value: "lithobates-catesbeianus" // > // summary: < // sample_count: 1000 // sample_sum: 31956.100000000017 // quantile: < // quantile: 0.5 // value: 32.4 // > // quantile: < // quantile: 0.9 // value: 41.4 // > // quantile: < // quantile: 0.99 // value: 41.9 // > // > // label: < // name: "species" // value: "litoria-caerulea" // > // summary: < // sample_count: 1000 // sample_sum: 29969.50000000001 // quantile: < // quantile: 0.5 // value: 31.1 // > // quantile: < // quantile: 0.9 // value: 41.3 // > // quantile: < // quantile: 0.99 // value: 41.9 // > // > // ] }