promethues

This commit is contained in:
wangchuxiao
2022-09-14 17:45:38 +08:00
parent 72d0920458
commit d534f026b0
10 changed files with 73 additions and 11 deletions
+2
View File
@@ -99,6 +99,8 @@ type config struct {
DBMaxOpenConns int `yaml:"dbMaxOpenConns"`
DBMaxIdleConns int `yaml:"dbMaxIdleConns"`
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
LogLevel int `yaml:"logLevel"`
SlowThreshold int `yaml:"slowThreshold"`
}
Mongo struct {
DBUri string `yaml:"dbUri"`
+4 -4
View File
@@ -56,10 +56,10 @@ func initMysqlDB() {
newLogger := logger.New(
Writer{},
logger.Config{
SlowThreshold: 200 * time.Millisecond, // Slow SQL threshold
LogLevel: logger.Warn, // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
Colorful: true, // Disable color
SlowThreshold: time.Duration(config.Config.Mysql.SlowThreshold) * time.Millisecond, // Slow SQL threshold
LogLevel: logger.LogLevel(config.Config.Mysql.LogLevel), // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
Colorful: true, // Disable color
},
)
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
+7
View File
@@ -6,6 +6,7 @@ import (
"strconv"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
@@ -24,3 +25,9 @@ func PrometheusHandler() gin.HandlerFunc {
h.ServeHTTP(c.Writer, c.Request)
}
}
func PromeInc(counter prometheus.Counter) {
if config.Config.Prometheus.Enable {
counter.Inc()
}
}