@@ -29,8 +29,8 @@ import (
29
29
var (
30
30
addr = flag .String ("listen-address" , ":8080" , "The address to listen on for HTTP requests." )
31
31
uniformDomain = flag .Float64 ("uniform.domain" , 200 , "The domain for the uniform distribution." )
32
- normDomain = flag .Float64 ("exponential .domain" , 200 , "The domain for the normal distribution." )
33
- normMean = flag .Float64 ("exponential .mean" , 10 , "The mean for the normal distribution." )
32
+ normDomain = flag .Float64 ("normal .domain" , 200 , "The domain for the normal distribution." )
33
+ normMean = flag .Float64 ("normal .mean" , 10 , "The mean for the normal distribution." )
34
34
oscillationPeriod = flag .Duration ("oscillation-period" , 10 * time .Minute , "The duration of the rate oscillation period." )
35
35
)
36
36
@@ -45,11 +45,21 @@ var (
45
45
},
46
46
[]string {"service" },
47
47
)
48
+ // The same as above, but now as a histogram, and only for the normal
49
+ // distribution. The buckets are targeted to the parameters of the
50
+ // normal distribution, with 20 buckets centered on the mean, each
51
+ // half-sigma wide.
52
+ rpcDurationsHistogram = prometheus .NewHistogram (prometheus.HistogramOpts {
53
+ Name : "rpc_durations_histogram_microseconds" ,
54
+ Help : "RPC latency distributions." ,
55
+ Buckets : prometheus .LinearBuckets (* normMean - 5 * * normDomain , .5 * * normDomain , 20 ),
56
+ })
48
57
)
49
58
50
59
func init () {
51
- // Register the summary with Prometheus's default registry.
60
+ // Register the summary and the histogram with Prometheus's default registry.
52
61
prometheus .MustRegister (rpcDurations )
62
+ prometheus .MustRegister (rpcDurationsHistogram )
53
63
}
54
64
55
65
func main () {
@@ -64,21 +74,25 @@ func main() {
64
74
// Periodically record some sample latencies for the three services.
65
75
go func () {
66
76
for {
67
- rpcDurations .WithLabelValues ("uniform" ).Observe (rand .Float64 () * * uniformDomain )
77
+ v := rand .Float64 () * * uniformDomain
78
+ rpcDurations .WithLabelValues ("uniform" ).Observe (v )
68
79
time .Sleep (time .Duration (100 * oscillationFactor ()) * time .Millisecond )
69
80
}
70
81
}()
71
82
72
83
go func () {
73
84
for {
74
- rpcDurations .WithLabelValues ("normal" ).Observe ((rand .NormFloat64 () * * normDomain ) + * normMean )
85
+ v := (rand .NormFloat64 () * * normDomain ) + * normMean
86
+ rpcDurations .WithLabelValues ("normal" ).Observe (v )
87
+ rpcDurationsHistogram .Observe (v )
75
88
time .Sleep (time .Duration (75 * oscillationFactor ()) * time .Millisecond )
76
89
}
77
90
}()
78
91
79
92
go func () {
80
93
for {
81
- rpcDurations .WithLabelValues ("exponential" ).Observe (rand .ExpFloat64 ())
94
+ v := rand .ExpFloat64 ()
95
+ rpcDurations .WithLabelValues ("exponential" ).Observe (v )
82
96
time .Sleep (time .Duration (50 * oscillationFactor ()) * time .Millisecond )
83
97
}
84
98
}()
0 commit comments