Skip to content

Commit

Permalink
add prom metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Sep 6, 2020
1 parent cd6e6f9 commit 2e47342
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package apis
import (
"net/http"

"github.com/axiaoxin-com/logging"
"github.com/axiaoxin-com/pink-lady/apis/docs"
"github.com/axiaoxin-com/pink-lady/webserver"
"github.com/gin-contrib/pprof"
Expand Down Expand Up @@ -55,6 +56,9 @@ func Register(httpHandler http.Handler) {
if viper.GetBool("server.pprof") {
pprof.RouteRegister(x, "/pprof")
}
if viper.GetBool("server.metrics") {
x.GET("/metrics", logging.PromMetricsGinHandler())
}
// ginSwagger 生成的在线 API 文档路由
x.GET("/apidocs/*any", ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, DisableGinSwaggerEnvkey))
// 默认的 ping 方法,返回 server 相关信息
Expand Down
2 changes: 2 additions & 0 deletions src/config.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ mode = "debug"
pprof = true
# 请求处理超时时间(秒)
handler_timeout = 5
# 开启 prometheus metrics
metrics = true

########## 日志相关配置
[logging]
Expand Down
6 changes: 3 additions & 3 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/axiaoxin-com/goutils v0.0.0-20200903141426-4f3b85da9884
github.com/axiaoxin-com/logging v1.2.3-0.20200904093302-60998122f327
github.com/axiaoxin-com/logging v1.2.3-0.20200906133312-c412ba56842d
github.com/denisenkom/go-mssqldb v0.0.0-20200831201914-36b6ff1bbc10 // indirect
github.com/fsnotify/fsnotify v1.4.9
github.com/getsentry/sentry-go v0.7.0 // indirect
Expand All @@ -15,12 +15,12 @@ require (
github.com/go-openapi/swag v0.19.9 // indirect
github.com/go-playground/validator/v10 v10.3.0 // indirect
github.com/jinzhu/gorm v1.9.16 // indirect
github.com/json-iterator/go v1.1.10 // indirect
github.com/lib/pq v1.8.0 // indirect
github.com/magiconair/properties v1.8.2 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/prometheus/common v0.13.0 // indirect
github.com/spf13/afero v1.3.5 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand All @@ -33,7 +33,7 @@ require (
go.uber.org/zap v1.16.0 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc // indirect
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a // indirect
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f // indirect
golang.org/x/tools v0.0.0-20200821200730-1e23e48ab93b // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/ini.v1 v1.60.2 // indirect
Expand Down
Loading

0 comments on commit 2e47342

Please sign in to comment.