a2s_monitor.py 979 B

123456789101112131415161718192021222324252627282930313233
  1. # coding:utf-8
  2. from a2s.proto import service_pb2
  3. from a2s.proto import service_pb2_grpc
  4. import grpc
  5. def watch_monitor(a2s_ip, topic):
  6. """
  7. 监控
  8. :return:
  9. """
  10. try:
  11. with grpc.insecure_channel(a2s_ip) as channel:
  12. # 客户端实例
  13. stub = service_pb2_grpc.CallerStub(channel)
  14. # 调用服务端方法
  15. response = stub.ViewState(service_pb2.StateReq(topic=topic))
  16. # 反序列化
  17. count = response.currentRequest
  18. return count
  19. except:
  20. return None
  21. if __name__ == '__main__':
  22. import time
  23. for i in range(1000):
  24. ner_count = watch_monitor('192.168.3.240:9090', 'goods_ner')
  25. field_count = watch_monitor('192.168.3.240:9090', 'goods_field')
  26. service_count = watch_monitor('192.168.3.240:9090', 'goods_service')
  27. print("service_count:", service_count, "ner_count:", ner_count, "field_count:", field_count)
  28. time.sleep(0.5)