2018-10-08 13:17:05 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2019-04-27 15:35:08 +02:00
|
|
|
"log"
|
2018-10-08 13:17:05 +02:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func metricsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(200)
|
2019-04-27 15:35:08 +02:00
|
|
|
_, err := w.Write([]byte(fmt.Sprintf(`{"queue": {"length": %d}}`, size)))
|
2022-02-01 18:13:48 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to write: %v", err)
|
|
|
|
}
|
2018-10-08 13:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
size int
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.IntVar(&size, "fake-queue-length", 10, "Fake queue length for fake metrics.")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux.HandleFunc("/metrics", metricsHandler)
|
|
|
|
|
|
|
|
server := &http.Server{
|
|
|
|
Addr: ":9090",
|
|
|
|
Handler: mux,
|
|
|
|
ReadTimeout: 5 * time.Second,
|
|
|
|
}
|
|
|
|
|
2019-04-27 15:35:08 +02:00
|
|
|
log.Fatal(server.ListenAndServe())
|
2018-10-08 13:17:05 +02:00
|
|
|
}
|