Skip to content

Commit

Permalink
feat: update config for prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtri6179 committed May 12, 2024
1 parent 9f02c43 commit e7cdf44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"fmt"
"net/http"
"time"

"github.com/gin-contrib/cors"
Expand Down Expand Up @@ -53,6 +54,11 @@ func (server *Server) setupRouter() {

router.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

// Ping pong tutorial prometheus
http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
fmt.Print(w, "pong")
})

router.POST("/users", server.createUser)
router.POST("/users/login", server.loginUser)
// Question
Expand Down
20 changes: 20 additions & 0 deletions pkg/tutorial.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package metric

import (
"fmt"
"net/http"

"github.com/prometheus/client_golang/prometheus"
)

func ping(w http.ResponseWriter, req *http.Request) {
pingCounter.Inc()
fmt.Fprintf(w, "pong")
}

var pingCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "ping_request_count",
Help: "No of request handled by Ping handler",
},
)

0 comments on commit e7cdf44

Please sign in to comment.