| 1 |
# Copyright 2020 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 |
import argparse |
| 17 |
import asyncio |
| 18 |
import logging |
| 19 |
|
| 20 |
import grpc |
| 21 |
from grpc_channelz.v1 import channelz_pb2 |
| 22 |
from grpc_channelz.v1 import channelz_pb2_grpc |
| 23 |
|
| 24 |
|
| 25 |
async def run(addr: str) -> None: |
| 26 |
async with grpc.aio.insecure_channel(addr) as channel: |
| 27 |
channelz_stub = channelz_pb2_grpc.ChannelzStub(channel) |
| 28 |
response = await channelz_stub.GetServers( |
| 29 |
channelz_pb2.GetServersRequest(start_server_id=0)) |
| 30 |
print('Info for all servers: %s' % response) |
| 31 |
|
| 32 |
|
| 33 |
async def main() -> None: |
| 34 |
parser = argparse.ArgumentParser() |
| 35 |
parser.add_argument('--addr', |
| 36 |
nargs=1, |
| 37 |
type=str, |
| 38 |
default='[::]:50051', |
| 39 |
help='the address to request') |
| 40 |
args = parser.parse_args() |
| 41 |
run(addr=args.addr) |
| 42 |
|
| 43 |
|
| 44 |
if __name__ == '__main__': |
| 45 |
logging.basicConfig() |
| 46 |
asyncio.get_event_loop().run_until_complete(main()) |