123456789101112131415161718192021222324252627282930313233 |
- # coding:utf-8
- from a2s.proto import service_pb2
- from a2s.proto import service_pb2_grpc
- import grpc
- def watch_monitor(a2s_ip, topic):
- """
- 监控
- :return:
- """
- try:
- with grpc.insecure_channel(a2s_ip) as channel:
- # 客户端实例
- stub = service_pb2_grpc.CallerStub(channel)
- # 调用服务端方法
- response = stub.ViewState(service_pb2.StateReq(topic=topic))
- # 反序列化
- count = response.currentRequest
- return count
- except:
- return None
- if __name__ == '__main__':
- import time
- for i in range(1000):
- ner_count = watch_monitor('192.168.3.240:9090', 'goods_ner')
- field_count = watch_monitor('192.168.3.240:9090', 'goods_field')
- service_count = watch_monitor('192.168.3.240:9090', 'goods_service')
- print("service_count:", service_count, "ner_count:", ner_count, "field_count:", field_count)
- time.sleep(0.5)
|