Skip to main content

Python gRPC Prometheus Interceptors

Project description


Instrument library to provide prometheus metrics similar to:


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'),
# Start an end point to expose metrics.

Server side:

Server metrics are exposed by adding the interceptor when the gRPC server is started. Take a look at tests/integration/hello_world/ 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/ for the complete example.

server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
# Start an end point to expose metrics.

How to run and test

  1. Run the testing server
python -m tests.integration.hello_world.hello_world_sever
  1. Run the testing client
python -m tests.integration.hello_world.hello_world_client
  1. Open http://localhost:50052 for the server side metrics
  2. Open http://localhost:50053 for the client side metrics



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for py-grpc-prometheus, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size py_grpc_prometheus-0.2.0-py3-none-any.whl (10.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size py_grpc_prometheus-0.2.0.tar.gz (4.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page