github.com/matrixorigin/matrixone@v1.2.0/pkg/util/status/logtail_server.go (about) 1 // Copyright 2021 -2023 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package status 16 17 import ( 18 "time" 19 20 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logtail/service" 21 ) 22 23 type SessionStatus struct { 24 ClientAddress string `json:"client_address"` 25 LastBeforeSend time.Time `json:"last_before_send"` 26 LastAfterSend time.Time `json:"last_after_send"` 27 Active int `json:"active"` 28 TableStatusCount int `json:"table_status_count"` 29 } 30 31 type DeletedSession struct { 32 Address string `json:"address"` 33 DeletedAt time.Time `json:"deleted_at"` 34 } 35 36 type LogtailServerStatus struct { 37 Sessions []SessionStatus `json:"session_status"` 38 DeletedSessions []DeletedSession `json:"deleted_sessions"` 39 } 40 41 func (s *LogtailServerStatus) fill(logtailServer *service.LogtailServer) { 42 if logtailServer == nil { 43 return 44 } 45 sessions := logtailServer.SessionMgr().ListSession() 46 s.Sessions = make([]SessionStatus, 0, len(sessions)) 47 for _, session := range sessions { 48 s.Sessions = append(s.Sessions, SessionStatus{ 49 ClientAddress: session.RemoteAddress(), 50 LastBeforeSend: session.LastBeforeSend(), 51 LastAfterSend: session.LastAfterSend(), 52 Active: session.Active(), 53 TableStatusCount: len(session.Tables()), 54 }) 55 } 56 57 deleted := logtailServer.SessionMgr().DeletedSessions() 58 s.DeletedSessions = make([]DeletedSession, 0, len(deleted)) 59 for _, session := range deleted { 60 s.DeletedSessions = append(s.DeletedSessions, DeletedSession{ 61 Address: session.RemoteAddress(), 62 DeletedAt: session.DeletedAt(), 63 }) 64 } 65 }