get_stats.py
Go to the documentation of this file.
1 # Copyright 2019 The gRPC 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 """Poll statistics from the server."""
15 
16 from __future__ import absolute_import
17 from __future__ import division
18 from __future__ import print_function
19 
20 import argparse
21 import logging
22 
23 import grpc
24 from grpc_channelz.v1 import channelz_pb2
25 from grpc_channelz.v1 import channelz_pb2_grpc
26 
27 
28 def run(addr):
29  with grpc.insecure_channel(addr) as channel:
30  channelz_stub = channelz_pb2_grpc.ChannelzStub(channel)
31  # This RPC pulls server-level metrics, like sent/received messages,
32  # succeeded/failed RPCs. For more info see:
33  # https://github.com/grpc/grpc/blob/master/src/proto/grpc/channelz/channelz.proto
34  response = channelz_stub.GetServers(channelz_pb2.GetServersRequest())
35  print(f'Info for all servers: {response}')
36 
37 
38 def main():
39  parser = argparse.ArgumentParser()
40  parser.add_argument('--addr',
41  nargs=1,
42  type=str,
43  default='[::]:50051',
44  help='the address to request')
45  args = parser.parse_args()
46  run(addr=args.addr)
47 
48 
49 if __name__ == '__main__':
50  logging.basicConfig()
51  main()
grpc.insecure_channel
def insecure_channel(target, options=None, compression=None)
Definition: src/python/grpcio/grpc/__init__.py:1962
get_stats.main
def main()
Definition: get_stats.py:38
get_stats.run
def run(addr)
Definition: get_stats.py:28
grpc_channelz.v1
Definition: src/python/grpcio_channelz/grpc_channelz/v1/__init__.py:1
main
Definition: main.py:1


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:26