...

Source file src/go.opencensus.io/plugin/ocgrpc/server_metrics.go

Documentation: go.opencensus.io/plugin/ocgrpc

     1  // Copyright 2017, OpenCensus Authors
     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  
    16  package ocgrpc
    17  
    18  import (
    19  	"go.opencensus.io/stats"
    20  	"go.opencensus.io/stats/view"
    21  	"go.opencensus.io/tag"
    22  )
    23  
    24  // The following variables are measures are recorded by ServerHandler:
    25  var (
    26  	ServerReceivedMessagesPerRPC = stats.Int64("grpc.io/server/received_messages_per_rpc", "Number of messages received in each RPC. Has value 1 for non-streaming RPCs.", stats.UnitDimensionless)
    27  	ServerReceivedBytesPerRPC    = stats.Int64("grpc.io/server/received_bytes_per_rpc", "Total bytes received across all messages per RPC.", stats.UnitBytes)
    28  	ServerSentMessagesPerRPC     = stats.Int64("grpc.io/server/sent_messages_per_rpc", "Number of messages sent in each RPC. Has value 1 for non-streaming RPCs.", stats.UnitDimensionless)
    29  	ServerSentBytesPerRPC        = stats.Int64("grpc.io/server/sent_bytes_per_rpc", "Total bytes sent in across all response messages per RPC.", stats.UnitBytes)
    30  	ServerStartedRPCs            = stats.Int64("grpc.io/server/started_rpcs", "Number of started server RPCs.", stats.UnitDimensionless)
    31  	ServerLatency                = stats.Float64("grpc.io/server/server_latency", "Time between first byte of request received to last byte of response sent, or terminal error.", stats.UnitMilliseconds)
    32  )
    33  
    34  // TODO(acetechnologist): This is temporary and will need to be replaced by a
    35  // mechanism to load these defaults from a common repository/config shared by
    36  // all supported languages. Likely a serialized protobuf of these defaults.
    37  
    38  // Predefined views may be registered to collect data for the above measures.
    39  // As always, you may also define your own custom views over measures collected by this
    40  // package. These are declared as a convenience only; none are registered by
    41  // default.
    42  var (
    43  	ServerReceivedBytesPerRPCView = &view.View{
    44  		Name:        "grpc.io/server/received_bytes_per_rpc",
    45  		Description: "Distribution of received bytes per RPC, by method.",
    46  		Measure:     ServerReceivedBytesPerRPC,
    47  		TagKeys:     []tag.Key{KeyServerMethod},
    48  		Aggregation: DefaultBytesDistribution,
    49  	}
    50  
    51  	ServerSentBytesPerRPCView = &view.View{
    52  		Name:        "grpc.io/server/sent_bytes_per_rpc",
    53  		Description: "Distribution of total sent bytes per RPC, by method.",
    54  		Measure:     ServerSentBytesPerRPC,
    55  		TagKeys:     []tag.Key{KeyServerMethod},
    56  		Aggregation: DefaultBytesDistribution,
    57  	}
    58  
    59  	ServerLatencyView = &view.View{
    60  		Name:        "grpc.io/server/server_latency",
    61  		Description: "Distribution of server latency in milliseconds, by method.",
    62  		TagKeys:     []tag.Key{KeyServerMethod},
    63  		Measure:     ServerLatency,
    64  		Aggregation: DefaultMillisecondsDistribution,
    65  	}
    66  
    67  	// Purposely reuses the count from `ServerLatency`, tagging
    68  	// with method and status to result in ServerCompletedRpcs.
    69  	ServerCompletedRPCsView = &view.View{
    70  		Name:        "grpc.io/server/completed_rpcs",
    71  		Description: "Count of RPCs by method and status.",
    72  		TagKeys:     []tag.Key{KeyServerMethod, KeyServerStatus},
    73  		Measure:     ServerLatency,
    74  		Aggregation: view.Count(),
    75  	}
    76  
    77  	ServerStartedRPCsView = &view.View{
    78  		Measure:     ServerStartedRPCs,
    79  		Name:        "grpc.io/server/started_rpcs",
    80  		Description: "Number of started server RPCs.",
    81  		TagKeys:     []tag.Key{KeyServerMethod},
    82  		Aggregation: view.Count(),
    83  	}
    84  
    85  	ServerReceivedMessagesPerRPCView = &view.View{
    86  		Name:        "grpc.io/server/received_messages_per_rpc",
    87  		Description: "Distribution of messages received count per RPC, by method.",
    88  		TagKeys:     []tag.Key{KeyServerMethod},
    89  		Measure:     ServerReceivedMessagesPerRPC,
    90  		Aggregation: DefaultMessageCountDistribution,
    91  	}
    92  
    93  	ServerSentMessagesPerRPCView = &view.View{
    94  		Name:        "grpc.io/server/sent_messages_per_rpc",
    95  		Description: "Distribution of messages sent count per RPC, by method.",
    96  		TagKeys:     []tag.Key{KeyServerMethod},
    97  		Measure:     ServerSentMessagesPerRPC,
    98  		Aggregation: DefaultMessageCountDistribution,
    99  	}
   100  )
   101  
   102  // DefaultServerViews are the default server views provided by this package.
   103  var DefaultServerViews = []*view.View{
   104  	ServerReceivedBytesPerRPCView,
   105  	ServerSentBytesPerRPCView,
   106  	ServerLatencyView,
   107  	ServerCompletedRPCsView,
   108  }
   109  

View as plain text