add Metric
This commit is contained in:
13
internal/services/api/handler_metrics.go
Normal file
13
internal/services/api/handler_metrics.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"thuanle.me/ip-info/internal/services/db_updater"
|
||||
)
|
||||
|
||||
func HandleMetrics(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"updated_at": db_updater.DbUpdatedAt.UnixMilli(),
|
||||
})
|
||||
}
|
||||
@@ -24,6 +24,7 @@ func StartApiService() {
|
||||
|
||||
engine.GET("/", HandleIp)
|
||||
engine.GET("/json", HandleJson)
|
||||
engine.GET("/metrics", HandleMetrics)
|
||||
|
||||
port := os.Getenv(key.EnvApiPort)
|
||||
if len(port) == 0 {
|
||||
|
||||
@@ -5,8 +5,11 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"thuanle.me/ip-info/configs"
|
||||
"thuanle.me/ip-info/internal/data"
|
||||
"time"
|
||||
)
|
||||
|
||||
var DbUpdatedAt time.Time
|
||||
|
||||
func StartUpdateDbService() {
|
||||
c := cron.New()
|
||||
_, _ = c.AddFunc("@daily", fetchDbs)
|
||||
@@ -29,5 +32,7 @@ func fetchDbs() {
|
||||
log.Err(err).Msg("Failed to reload mmdb")
|
||||
return
|
||||
}
|
||||
|
||||
DbUpdatedAt = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user