(reg prometheus.Registerer, normMean, normDomain float64)
| 36 | } |
| 37 | |
| 38 | func NewMetrics(reg prometheus.Registerer, normMean, normDomain float64) *metrics { |
| 39 | m := &metrics{ |
| 40 | // Create a summary to track fictional inter service RPC latencies for three |
| 41 | // distinct services with different latency distributions. These services are |
| 42 | // differentiated via a "service" label. |
| 43 | rpcDurations: prometheus.NewSummaryVec( |
| 44 | prometheus.SummaryOpts{ |
| 45 | Name: "rpc_durations_seconds", |
| 46 | Help: "RPC latency distributions.", |
| 47 | Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, |
| 48 | }, |
| 49 | []string{"service"}, |
| 50 | ), |
| 51 | // The same as above, but now as a histogram, and only for the |
| 52 | // normal distribution. The histogram features both conventional |
| 53 | // buckets as well as sparse buckets, the latter needed for the |
| 54 | // experimental native histograms (ingested by a Prometheus |
| 55 | // server v2.40 with the corresponding feature flag |
| 56 | // enabled). The conventional buckets are targeted to the |
| 57 | // parameters of the normal distribution, with 20 buckets |
| 58 | // centered on the mean, each half-sigma wide. The sparse |
| 59 | // buckets are always centered on zero, with a growth factor of |
| 60 | // one bucket to the next of (at most) 1.1. (The precise factor |
| 61 | // is 2^2^-3 = 1.0905077...) |
| 62 | rpcDurationsHistogram: prometheus.NewHistogram(prometheus.HistogramOpts{ |
| 63 | Name: "rpc_durations_histogram_seconds", |
| 64 | Help: "RPC latency distributions.", |
| 65 | Buckets: prometheus.LinearBuckets(normMean-5*normDomain, .5*normDomain, 20), |
| 66 | NativeHistogramBucketFactor: 1.1, |
| 67 | }), |
| 68 | } |
| 69 | reg.MustRegister(m.rpcDurations) |
| 70 | reg.MustRegister(m.rpcDurationsHistogram) |
| 71 | return m |
| 72 | } |
| 73 | |
| 74 | func main() { |
| 75 | var ( |
no test coverage detected