Move flags and metrics into main()

Fixes #933.

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2021-11-10 16:20:10 +01:00
parent 679eb0d315
commit f78dc19a65
1 changed files with 32 additions and 34 deletions

View File

@ -29,15 +29,18 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
var ( func main() {
var (
addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.") addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
uniformDomain = flag.Float64("uniform.domain", 0.0002, "The domain for the uniform distribution.") uniformDomain = flag.Float64("uniform.domain", 0.0002, "The domain for the uniform distribution.")
normDomain = flag.Float64("normal.domain", 0.0002, "The domain for the normal distribution.") normDomain = flag.Float64("normal.domain", 0.0002, "The domain for the normal distribution.")
normMean = flag.Float64("normal.mean", 0.00001, "The mean for the normal distribution.") normMean = flag.Float64("normal.mean", 0.00001, "The mean for the normal distribution.")
oscillationPeriod = flag.Duration("oscillation-period", 10*time.Minute, "The duration of the rate oscillation period.") oscillationPeriod = flag.Duration("oscillation-period", 10*time.Minute, "The duration of the rate oscillation period.")
) )
var ( flag.Parse()
var (
// Create a summary to track fictional interservice RPC latencies for three // Create a summary to track fictional interservice RPC latencies for three
// distinct services with different latency distributions. These services are // distinct services with different latency distributions. These services are
// differentiated via a "service" label. // differentiated via a "service" label.
@ -58,18 +61,13 @@ var (
Help: "RPC latency distributions.", Help: "RPC latency distributions.",
Buckets: prometheus.LinearBuckets(*normMean-5**normDomain, .5**normDomain, 20), Buckets: prometheus.LinearBuckets(*normMean-5**normDomain, .5**normDomain, 20),
}) })
) )
func init() {
// Register the summary and the histogram with Prometheus's default registry. // Register the summary and the histogram with Prometheus's default registry.
prometheus.MustRegister(rpcDurations) prometheus.MustRegister(rpcDurations)
prometheus.MustRegister(rpcDurationsHistogram) prometheus.MustRegister(rpcDurationsHistogram)
// Add Go module build info. // Add Go module build info.
prometheus.MustRegister(prometheus.NewBuildInfoCollector()) prometheus.MustRegister(prometheus.NewBuildInfoCollector())
}
func main() {
flag.Parse()
start := time.Now() start := time.Now()