github.com/true-sqn/fabric@v2.1.1+incompatible/internal/pkg/comm/serverstatshandler.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package comm
     8  
     9  import (
    10  	"context"
    11  
    12  	"github.com/hyperledger/fabric/common/metrics"
    13  	"google.golang.org/grpc/stats"
    14  )
    15  
    16  type ServerStatsHandler struct {
    17  	OpenConnCounter   metrics.Counter
    18  	ClosedConnCounter metrics.Counter
    19  }
    20  
    21  func (h *ServerStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context {
    22  	return ctx
    23  }
    24  
    25  func (h *ServerStatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats) {}
    26  
    27  func (h *ServerStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context {
    28  	return ctx
    29  }
    30  
    31  func (h *ServerStatsHandler) HandleConn(ctx context.Context, s stats.ConnStats) {
    32  	switch s.(type) {
    33  	case *stats.ConnBegin:
    34  		h.OpenConnCounter.Add(1)
    35  	case *stats.ConnEnd:
    36  		h.ClosedConnCounter.Add(1)
    37  	}
    38  }