mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-30 07:06:38 +08:00
33 lines
806 B
Go
33 lines
806 B
Go
package monitor
|
|
|
|
import "github.com/songquanpeng/one-api/relay/model"
|
|
|
|
type MonitorInstance interface {
|
|
Emit(ChannelId int, success bool)
|
|
ShouldDisableChannel(err *model.Error, statusCode int) bool
|
|
DisableChannel(channelId int, channelName string, reason string)
|
|
}
|
|
|
|
type defaultMonitor struct {
|
|
}
|
|
|
|
func NewMonitorInstance() MonitorInstance {
|
|
return &defaultMonitor{}
|
|
}
|
|
|
|
func (m *defaultMonitor) Emit(channelId int, success bool) {
|
|
if success {
|
|
metricSuccessChan <- channelId
|
|
} else {
|
|
metricFailChan <- channelId
|
|
}
|
|
}
|
|
|
|
func (m *defaultMonitor) ShouldDisableChannel(err *model.Error, statusCode int) bool {
|
|
return ShouldDisableChannel(err, statusCode)
|
|
}
|
|
|
|
func (m *defaultMonitor) DisableChannel(channelId int, channelName string, reason string) {
|
|
DisableChannel(channelId, channelName, reason)
|
|
}
|