@@ -42,13 +42,15 @@ var (
4242 totalBytesFromClient int64
4343 totalBytesToClient int64
4444 activeConns int32
45+ activeV2Conns int32
46+ activeLegacyConns int32
4547 totalConns int64
4648 rejectedConns int64
4749 natType string = "Инициализация..."
4850 serverStartTime time.Time
4951)
5052
51- func statsLoop (ctx context.Context , configDir string ) {
53+ func statsLoop (ctx context.Context , configDir string , lifecycleRegistry * relayLifecycleRegistry ) {
5254 serverStartTime = time .Now ()
5355 statsFile := filepath .Join (configDir , "server.log" )
5456
@@ -64,8 +66,11 @@ func statsLoop(ctx context.Context, configDir string) {
6466 fromC := atomic .LoadInt64 (& totalBytesFromClient )
6567 toC := atomic .LoadInt64 (& totalBytesToClient )
6668 active := atomic .LoadInt32 (& activeConns )
69+ activeV2 := atomic .LoadInt32 (& activeV2Conns )
70+ activeLegacy := atomic .LoadInt32 (& activeLegacyConns )
6771 total := atomic .LoadInt64 (& totalConns )
6872 rejected := atomic .LoadInt64 (& rejectedConns )
73+ lifecycle := lifecycleRegistry .Stats ()
6974 uptime := time .Since (serverStartTime )
7075
7176 dbMutex .Lock ()
@@ -77,20 +82,27 @@ func statsLoop(ctx context.Context, configDir string) {
7782 downGB := float64 (toC ) / (1024 * 1024 * 1024 )
7883 upGB := float64 (fromC ) / (1024 * 1024 * 1024 )
7984
80- log .Printf ("[СТАТ] Активных: %d | Всего соединений: %d | Отклонено лимитом: %d | Uptime: %s | Получено: %.2f GB | Отправлено: %.2f GB | Паролей: %d | Устройств: %d" ,
81- active , total , rejected , uptimeStr , downGB , upGB , numPasswords , numDevices )
85+ log .Printf ("[СТАТ] Активных: %d (v2: %d, legacy: %d) | Принято за uptime: %d | Отклонено лимитом: %d | Заменено v2: %d | Отклонено stale v2: %d | Вытеснено legacy: %d | Uptime: %s | Получено: %.2f GB | Отправлено: %.2f GB | Паролей: %d | Устройств: %d" ,
86+ active , activeV2 , activeLegacy , total , rejected , lifecycle .V2Replaced , lifecycle .V2StaleDenied ,
87+ lifecycle .LegacyEvicted , uptimeStr , downGB , upGB , numPasswords , numDevices )
8288
8389 statsJSON , _ := json .Marshal (map [string ]interface {}{
84- "active" : active ,
85- "total" : total ,
86- "rejected" : rejected ,
87- "nat" : natType ,
88- "uptime" : uptimeStr ,
89- "down_gb" : fmt .Sprintf ("%.2f" , downGB ),
90- "up_gb" : fmt .Sprintf ("%.2f" , upGB ),
91- "passwords" : numPasswords ,
92- "devices" : numDevices ,
93- "timestamp" : time .Now ().Unix (),
90+ "active" : active ,
91+ "active_v2" : activeV2 ,
92+ "active_legacy" : activeLegacy ,
93+ "total" : total ,
94+ "accepted_since_start" : total ,
95+ "rejected" : rejected ,
96+ "v2_replaced" : lifecycle .V2Replaced ,
97+ "v2_stale_denied" : lifecycle .V2StaleDenied ,
98+ "legacy_evicted" : lifecycle .LegacyEvicted ,
99+ "nat" : natType ,
100+ "uptime" : uptimeStr ,
101+ "down_gb" : fmt .Sprintf ("%.2f" , downGB ),
102+ "up_gb" : fmt .Sprintf ("%.2f" , upGB ),
103+ "passwords" : numPasswords ,
104+ "devices" : numDevices ,
105+ "timestamp" : time .Now ().Unix (),
94106 })
95107 os .WriteFile (statsFile , statsJSON , 0644 )
96108 }
@@ -832,6 +844,30 @@ func handleConn(
832844 }
833845 atomic .AddInt32 (& activeConns , 1 )
834846 defer atomic .AddInt32 (& activeConns , - 1 )
847+ var relayModeTracked bool
848+ var relayModeV2 bool
849+ trackRelayMode := func (v2 bool ) {
850+ if relayModeTracked {
851+ return
852+ }
853+ relayModeTracked = true
854+ relayModeV2 = v2
855+ if v2 {
856+ atomic .AddInt32 (& activeV2Conns , 1 )
857+ } else {
858+ atomic .AddInt32 (& activeLegacyConns , 1 )
859+ }
860+ }
861+ defer func () {
862+ if ! relayModeTracked {
863+ return
864+ }
865+ if relayModeV2 {
866+ atomic .AddInt32 (& activeV2Conns , - 1 )
867+ } else {
868+ atomic .AddInt32 (& activeLegacyConns , - 1 )
869+ }
870+ }()
835871
836872 buf := make ([]byte , 1600 )
837873 firstPacket , err := readRelayPacket (clientConn , buf , 30 * time .Second )
@@ -884,6 +920,7 @@ func handleConn(
884920 if lifecycleRegistration != nil {
885921 defer lifecycleRegistration .Release ()
886922 }
923+ trackRelayMode (getConf .IsLifecycleV2 ())
887924 if _ , err := clientConn .Write ([]byte (config )); err != nil {
888925 return
889926 }
@@ -894,6 +931,9 @@ func handleConn(
894931 }
895932 firstStr = string (firstPacket )
896933 }
934+ if ! isGetConf {
935+ trackRelayMode (false )
936+ }
897937
898938 for firstStr == "READY" {
899939 if _ , err := clientConn .Write ([]byte ("READY_OK" )); err != nil {
0 commit comments