Python gRPC Prometheus Interceptors
Project description
py-grpc-prometheus
Instrument library to provide prometheus metrics similar to:
- https://github.com/grpc-ecosystem/java-grpc-prometheus
- https://github.com/grpc-ecosystem/go-grpc-prometheus
Status
Currently, the library has the parity metrics with the Java and Go library.
Server side:
- grpc_server_started_total
- grpc_server_handled_total
- grpc_server_handled_latency_seconds
- grpc_server_msg_received_total
- grpc_server_msg_sent_total
Client side:
- grpc_client_started_total
- grpc_client_completed
- grpc_client_completed_latency_seconds
- grpc_client_msg_sent_total
- grpc_client_msg_received_total
How to use
pip install py-grpc-prometheus
Client side:
Client metrics monitoring is done by intercepting the gPRC channel.
import grpc
from py_grpc_prometheus.prometheus_client_interceptor import PromClientInterceptor
channel = grpc.intercept_channel(grpc.insecure_channel('server:6565'),
PromClientInterceptor())
# Start an end point to expose metrics.
start_http_server(metrics_port)
Server side:
Server metrics are exposed by adding the interceptor when the gRPC server is started. Take a look at
tests/integration/hello_world/hello_world_client.py
for the complete example.
import grpc
from concurrent import futures
from py_grpc_prometheus.prometheus_server_interceptor import PromServerInterceptor
from prometheus_client import start_http_server
Start the gRPC server with the interceptor, take a look at
tests/integration/hello_world/hello_world_server.py
for the complete example.
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
interceptors=(PromServerInterceptor(),))
# Start an end point to expose metrics.
start_http_server(metrics_port)
How to run and test
- Run the testing server
python -m tests.integration.hello_world.hello_world_sever
- Run the testing client
python -m tests.integration.hello_world.hello_world_client
- Open http://localhost:50052 for the server side metrics
- Open http://localhost:50053 for the client side metrics
TODO:
- Unit test with https://github.com/census-instrumentation/opencensus-python/blob/master/tests/unit/trace/ext/grpc/test_server_interceptor.py
Reference
- https://grpc.io/grpc/python/grpc.html
- https://github.com/census-instrumentation/opencensus-python/blob/master/opencensus/trace/ext/grpc/utils.py
- https://github.com/opentracing-contrib/python-grpc/blob/b4bdc7ce81fa75ede00f7c6bcf5dab8fae47332a/grpc_opentracing/grpcext/grpc_interceptor/server_interceptor.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for py_grpc_prometheus-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab3f7a8495bbe2ae5de98fade38247a38341cb151e24ce9f64c6f072ac813d42 |
|
MD5 | 2900c9a60dbd69361c80fc62cf402a92 |
|
BLAKE2b-256 | 30f460114fb31f4c7710c6dce4c746d48c47e98e4853977533523c1c545ea7e4 |