mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-20 08:49:01 +08:00
feat: add openim images config path
Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package prom_metrics
|
||||
|
||||
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||
|
||||
/*
|
||||
labels := prometheus.Labels{"label_one": "any", "label_two": "value"}
|
||||
ApiCustomCnt.MetricCollector.(*prometheus.CounterVec).With(labels).Inc()
|
||||
*/
|
||||
var (
|
||||
ApiCustomCnt = &ginProm.Metric{
|
||||
Name: "custom_total",
|
||||
Description: "Custom counter events.",
|
||||
Type: "counter_vec",
|
||||
Args: []string{"label_one", "label_two"},
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
package prom_metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
UserLoginCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "user_login_total",
|
||||
Help: "The number of user login",
|
||||
})
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
package prom_metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
SingleChatMsgProcessSuccessCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "single_chat_msg_process_success_total",
|
||||
Help: "The number of single chat msg successful processed",
|
||||
})
|
||||
SingleChatMsgProcessFailedCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "single_chat_msg_process_failed_total",
|
||||
Help: "The number of single chat msg failed processed",
|
||||
})
|
||||
GroupChatMsgProcessSuccessCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "group_chat_msg_process_success_total",
|
||||
Help: "The number of group chat msg successful processed",
|
||||
})
|
||||
GroupChatMsgProcessFailedCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "group_chat_msg_process_failed_total",
|
||||
Help: "The number of group chat msg failed processed",
|
||||
})
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
package prom_metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
OnlineUserGauge = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "online_user_num",
|
||||
Help: "The number of online user num",
|
||||
})
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
package prom_metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
MsgOfflinePushFailedCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "msg_offline_push_failed_total",
|
||||
Help: "The number of msg failed offline pushed",
|
||||
})
|
||||
)
|
||||
@@ -0,0 +1,45 @@
|
||||
package prom_metrics
|
||||
|
||||
import (
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
)
|
||||
|
||||
func NewGrpcPromObj(cusMetrics []prometheus.Collector) (*prometheus.Registry, *grpc_prometheus.ServerMetrics, error) {
|
||||
////////////////////////////////////////////////////////
|
||||
reg := prometheus.NewRegistry()
|
||||
grpcMetrics := grpc_prometheus.NewServerMetrics()
|
||||
grpcMetrics.EnableHandlingTimeHistogram()
|
||||
cusMetrics = append(cusMetrics, grpcMetrics, collectors.NewGoCollector())
|
||||
reg.MustRegister(cusMetrics...)
|
||||
return reg, grpcMetrics, nil
|
||||
}
|
||||
|
||||
func GetGrpcCusMetrics(registerName string) []prometheus.Collector {
|
||||
switch registerName {
|
||||
case config2.Config.RpcRegisterName.OpenImMessageGatewayName:
|
||||
return []prometheus.Collector{OnlineUserGauge}
|
||||
case config2.Config.RpcRegisterName.OpenImMsgName:
|
||||
return []prometheus.Collector{SingleChatMsgProcessSuccessCounter, SingleChatMsgProcessFailedCounter, GroupChatMsgProcessSuccessCounter, GroupChatMsgProcessFailedCounter}
|
||||
case "Transfer":
|
||||
return []prometheus.Collector{MsgInsertRedisSuccessCounter, MsgInsertRedisFailedCounter, MsgInsertMongoSuccessCounter, MsgInsertMongoFailedCounter, SeqSetFailedCounter}
|
||||
case config2.Config.RpcRegisterName.OpenImPushName:
|
||||
return []prometheus.Collector{MsgOfflinePushFailedCounter}
|
||||
case config2.Config.RpcRegisterName.OpenImAuthName:
|
||||
return []prometheus.Collector{UserLoginCounter}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetGinCusMetrics(name string) []*ginprom.Metric {
|
||||
switch name {
|
||||
case "Api":
|
||||
return []*ginprom.Metric{ApiCustomCnt}
|
||||
default:
|
||||
return []*ginprom.Metric{ApiCustomCnt}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package prom_metrics
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func TestNewGrpcPromObj(t *testing.T) {
|
||||
type args struct {
|
||||
cusMetrics []prometheus.Collector
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *prometheus.Registry
|
||||
want1 *grpc_prometheus.ServerMetrics
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, got1, err := NewGrpcPromObj(tt.args.cusMetrics)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("NewGrpcPromObj() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewGrpcPromObj() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
if !reflect.DeepEqual(got1, tt.want1) {
|
||||
t.Errorf("NewGrpcPromObj() got1 = %v, want %v", got1, tt.want1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetGrpcCusMetrics(t *testing.T) {
|
||||
type args struct {
|
||||
registerName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []prometheus.Collector
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetGrpcCusMetrics(tt.args.registerName); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetGrpcCusMetrics() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetGinCusMetrics(t *testing.T) {
|
||||
type args struct {
|
||||
name string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []*ginprom.Metric
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetGinCusMetrics(tt.args.name); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetGinCusMetrics() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package prom_metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
MsgInsertRedisSuccessCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "msg_insert_redis_success_total",
|
||||
Help: "The number of successful insert msg to redis",
|
||||
})
|
||||
MsgInsertRedisFailedCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "msg_insert_redis_failed_total",
|
||||
Help: "The number of failed insert msg to redis",
|
||||
})
|
||||
MsgInsertMongoSuccessCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "msg_insert_mongo_success_total",
|
||||
Help: "The number of successful insert msg to mongo",
|
||||
})
|
||||
MsgInsertMongoFailedCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "msg_insert_mongo_failed_total",
|
||||
Help: "The number of failed insert msg to mongo",
|
||||
})
|
||||
SeqSetFailedCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "seq_set_failed_total",
|
||||
Help: "The number of failed set seq",
|
||||
})
|
||||
)
|
||||
Reference in New Issue
Block a user