@@ -87,16 +87,6 @@ func (v *apiV1) serve() {
8787 mr .GET ("/configs" , v .monitorConfigs )
8888 mr .GET ("/:id" , v .monitorHistoriesById )
8989
90- sr := v .r .Group ("service" )
91- sr .Use (mygin .Authorize (mygin.AuthorizeOption {
92- MemberOnly : false ,
93- IsPage : false ,
94- }))
95- sr .Use (mygin .ValidateViewPassword (mygin.ValidateViewPasswordOption {
96- IsPage : false ,
97- AbortWhenFail : true ,
98- }))
99- sr .GET ("" , v .serviceStatus )
10090
10191 // Frontend Profile API (提供原先由 CommonEnvironment 注入的全局配置)
10292 cr := v .r .Group ("profile" )
@@ -834,80 +824,3 @@ func monitoredServerIDs(monitors []*model.Monitor) []uint64 {
834824 return result
835825}
836826
837- func (v * apiV1 ) serviceStatus (c * gin.Context ) {
838- type serviceItem struct {
839- ID uint64 `json:"ID"`
840- Monitor * model.Monitor `json:"Monitor"`
841- CurrentUp uint64 `json:"CurrentUp"`
842- CurrentDown uint64 `json:"CurrentDown"`
843- TotalUp uint64 `json:"TotalUp"`
844- TotalDown uint64 `json:"TotalDown"`
845- Uptime float32 `json:"Uptime"`
846- Delay []float32 `json:"Delay"`
847- Up []int `json:"Up"`
848- Down []int `json:"Down"`
849- }
850-
851- items := make ([]serviceItem , 0 )
852- if singleton .ServiceSentinelShared != nil {
853- singleton .AlertsLock .RLock ()
854- stats := singleton .ServiceSentinelShared .LoadStats ()
855- for id , item := range stats {
856- if item == nil || item .Monitor == nil || ! item .Monitor .EnableShowInService {
857- continue
858- }
859- total := item .TotalUp + item .TotalDown
860- uptime := float32 (0 )
861- if total > 0 {
862- uptime = float32 (item .TotalUp ) / float32 (total ) * 100
863- }
864- items = append (items , serviceItem {
865- ID : id ,
866- Monitor : item .Monitor ,
867- CurrentUp : item .CurrentUp ,
868- CurrentDown : item .CurrentDown ,
869- TotalUp : item .TotalUp ,
870- TotalDown : item .TotalDown ,
871- Uptime : uptime ,
872- Delay : float32Array (item .Delay ),
873- Up : intArray (item .Up ),
874- Down : intArray (item .Down ),
875- })
876- }
877- singleton .AlertsLock .RUnlock ()
878- }
879-
880- sort .Slice (items , func (i , j int ) bool {
881- if items [i ].Monitor == nil || items [j ].Monitor == nil {
882- return items [i ].ID < items [j ].ID
883- }
884- if items [i ].Monitor .Name == items [j ].Monitor .Name {
885- return items [i ].ID < items [j ].ID
886- }
887- return items [i ].Monitor .Name < items [j ].Monitor .Name
888- })
889-
890- WriteJSON (c , 200 , gin.H {"Services" : items })
891- }
892-
893- func float32Array (input * [30 ]float32 ) []float32 {
894- if input == nil {
895- return []float32 {}
896- }
897- output := make ([]float32 , 0 , len (input ))
898- for _ , value := range input {
899- output = append (output , value )
900- }
901- return output
902- }
903-
904- func intArray (input * [30 ]int ) []int {
905- if input == nil {
906- return []int {}
907- }
908- output := make ([]int , 0 , len (input ))
909- for _ , value := range input {
910- output = append (output , value )
911- }
912- return output
913- }
0 commit comments