about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-09 19:47:53 +0200
committerEmile <hanemile@protonmail.com>2019-10-09 19:47:53 +0200
commit62f67cf2c22237b1866a202e3b7ba0fc2c1598ac (patch)
tree238fb44728560911fc297318f830e335b3364012
parentde78273f080634b57cc0e0e7c3e05e3ff03d0478 (diff)
moved the metrics handler to /metrics
-rw-r--r--src/http.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/http.go b/src/http.go
index 0add89e..a08845e 100644
--- a/src/http.go
+++ b/src/http.go
@@ -12,6 +12,7 @@ func setupHTTPServer() http.Server {
 	r := mux.NewRouter()
 
 	r.HandleFunc("/", indexHandler)
+	r.HandleFunc("/metrics", metricsHandler)
 
 	return http.Server{
 		Addr:    fmt.Sprintf("0.0.0.0:%d", *port),
@@ -21,11 +22,20 @@ func setupHTTPServer() http.Server {
 
 // indexHandler handles the "/" endpoint
 func indexHandler(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "%s", "You can find the metrics by accessing the /metrics endpoint!\n")
+}
+
+// metricsHandler handles the "/metrics" endpoint
+func metricsHandler(w http.ResponseWriter, r *http.Request) {
 	if userFlags == nil {
 		userFlags = make(map[string]int)
 	}
 
+	fmt.Fprintf(w, "%s\n", "scoreboard_up 1")
+
 	for _, user := range users {
-		fmt.Fprintf(w, "challengesSolves{name=%s} %d\n", user, userFlags[user])
+		if user != "" {
+			fmt.Fprintf(w, "challengesSolves{name=\"%s\"} %d\n", user, userFlags[user])
+		}
 	}
 }