Skip to content

Commit e7cdf44

Browse files
committed
feat: update config for prometheus
1 parent 9f02c43 commit e7cdf44

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

api/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"fmt"
5+
"net/http"
56
"time"
67

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

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

57+
// Ping pong tutorial prometheus
58+
http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
59+
fmt.Print(w, "pong")
60+
})
61+
5662
router.POST("/users", server.createUser)
5763
router.POST("/users/login", server.loginUser)
5864
// Question

pkg/tutorial.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package metric
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
7+
"github.com/prometheus/client_golang/prometheus"
8+
)
9+
10+
func ping(w http.ResponseWriter, req *http.Request) {
11+
pingCounter.Inc()
12+
fmt.Fprintf(w, "pong")
13+
}
14+
15+
var pingCounter = prometheus.NewCounter(
16+
prometheus.CounterOpts{
17+
Name: "ping_request_count",
18+
Help: "No of request handled by Ping handler",
19+
},
20+
)

0 commit comments

Comments
 (0)