|
|
|
|
@ -66,6 +66,9 @@ var (
|
|
|
|
|
Buckets: prometheus.ExponentialBuckets(1, 2, 20), // 初始值为1,指数为2增长,20个取值
|
|
|
|
|
}, []string{"request_time"})
|
|
|
|
|
// 不同的桶根据具体情况而定
|
|
|
|
|
|
|
|
|
|
metricsPath = flag.String("web.telemetry-path", "/metrics",
|
|
|
|
|
"Path under which to expose metrics")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
@ -80,7 +83,7 @@ func init() {
|
|
|
|
|
func main() {
|
|
|
|
|
flag.Parse()
|
|
|
|
|
r := mux.NewRouter()
|
|
|
|
|
r.HandleFunc("/", handler)
|
|
|
|
|
r.HandleFunc("/", handlerIndex)
|
|
|
|
|
r.Use(metricsMiddleware)
|
|
|
|
|
|
|
|
|
|
r.Handle("/metrics", promhttp.HandlerFor(
|
|
|
|
|
@ -107,10 +110,18 @@ func metricsMiddleware(next http.Handler) http.Handler {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
func handlerIndex(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
x := rand.Intn(3)
|
|
|
|
|
time.Sleep(time.Duration(x) * time.Second)
|
|
|
|
|
_, _ = w.Write([]byte("handler response"))
|
|
|
|
|
//_, _ = w.Write([]byte("handler response"))
|
|
|
|
|
_, _ = w.Write([]byte(`<html>
|
|
|
|
|
<head><title>SRE Promethus Exporter</title></head>
|
|
|
|
|
<body>
|
|
|
|
|
<h1>SRE Promethus Exporter</h1>
|
|
|
|
|
<p><a href='` + *metricsPath + `'>Metrics</a></p>
|
|
|
|
|
</body>
|
|
|
|
|
</html>`))
|
|
|
|
|
|
|
|
|
|
fmt.Println("print handler")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|