增加缓存qps

This commit is contained in:
ayflying
2025-04-02 11:32:54 +08:00
parent 5e18d67747
commit db3a2bf405
4 changed files with 56 additions and 25 deletions

View File

@@ -1,15 +1,40 @@
package aycache
import (
v1 "github.com/ayflying/utility_go/api/system/v1"
"github.com/ayflying/utility_go/pkg/aycache/drive"
drive2 "github.com/ayflying/utility_go/pkg/aycache/drive"
"github.com/ayflying/utility_go/service"
"github.com/gogf/gf/v2/os/gcache"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"math"
)
type Mod struct {
client *gcache.Cache
}
var (
QPSCount int
QPS = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "Cache_QPS",
Help: "当前缓存QPS数量",
},
)
)
func init() {
service.SystemCron().AddCron(v1.CronType_MINUTE, func() error {
QPS.Set(math.Round(float64(QPSCount) / 60))
QPSCount = 0
return nil
})
}
func New(_name ...string) gcache.Adapter {
var cacheAdapterObj gcache.Adapter
@@ -30,5 +55,7 @@ func New(_name ...string) gcache.Adapter {
//var client = gcache.New()
//client.SetAdapter(cacheAdapterObj)
QPSCount++
return cacheAdapterObj
}