lchenn / py-grpc-prometheus

Python gRPC Prometheus
Apache License 2.0
48 stars 25 forks source link

multiprocess not work #8

Open eic-aibee opened 5 years ago

eic-aibee commented 5 years ago
   MAX_MESSAGE_LENGTH = 41943040
    # prometheus related 参考自: https://github.com/lchenn/py-grpc-prometheus#server-side-1
    server = grpc.server(thread_pool=futures.ThreadPoolExecutor(max_workers=_THREAD_CONCURRENCY, ),
                         options=[('grpc.max_send_message_length', MAX_MESSAGE_LENGTH), (
                             'grpc.max_receive_message_length', MAX_MESSAGE_LENGTH), ('grpc.so_reuseport', 1)],
                         interceptors=(PromServerInterceptor(),))
    port = 50051
    bind_address = '0.0.0.0:{}'.format(port)
    _LOGGER.info("Binding to '%s'", bind_address)
    sys.stdout.flush()
    workers = []
    for _ in range(_PROCESS_COUNT):
        # NOTE: It is imperative that the worker subprocesses be forked before
        # any gRPC servers start up. See
        # https://github.com/grpc/grpc/issues/16001 for more details.
        worker = multiprocessing.Process(
            target=_run_server, args=(bind_address,))
        worker.start()
        workers.append(worker)
    for worker in workers:
        worker.join()
root@4c633109246e:~# curl http://localhost:50061
# HELP grpc_server_msg_received_total Histogram of response latency (seconds) of gRPC that had been application-level handled by the server.
# TYPE grpc_server_msg_received_total counter
# HELP grpc_server_started_total Total number of RPCs started on the server.
# TYPE grpc_server_started_total counter
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 2423529472.0
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 144318464.0
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1565093071.54
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 4.57
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 8.0
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 1048576.0
# HELP grpc_server_msg_sent_total Total number of stream messages sent by the server.
# TYPE grpc_server_msg_sent_total counter
# HELP grpc_server_handled_latency_seconds Histogram of response latency (seconds) of gRPC that had been application-level handled by the server
# TYPE grpc_server_handled_latency_seconds histogram
# HELP grpc_server_handled_total Total number of RPCs completed on the server, regardless of success or failure.
# TYPE grpc_server_handled_total counter
# HELP python_info Python platform information
# TYPE python_info gauge
python_info{implementation="CPython",major="2",minor="7",patchlevel="16",version="2.7.16"} 1.0

metrics without value!