Giter Club home page Giter Club logo

java-grpc-prometheus's Introduction

java-grpc-prometheus

Build Status

Java interceptors which can be used to monitor Grpc services using Prometheus.

Features

The features of this library include two monitoring grpc interceptors, MonitoringServerInterceptor and MonitoringClientInterceptor. These interceptors can be attached separately to grpc servers and client stubs respectively. For each RPC, the interceptors increment the following Prometheus metrics, broken down by method type, service name, method name, and response code:

  • Server
    • grpc_server_started_total: Total number of RPCs started on the server.
    • grpc_server_handled_total: Total number of RPCs completed on the server, regardless of success or failure.
    • grpc_server_handled_latency_seconds: (Optional) Histogram of response latency of rpcs handled by the server, in seconds.
    • grpc_server_msg_received_total: Total number of stream messages received from the client.
    • grpc_server_msg_sent_total: Total number of stream messages sent by the server.
  • Client
    • grpc_client_started_total: Total number of RPCs started on the client.
    • grpc_client_completed: Total number of RPCs completed on the client, regardless of success or failure.
    • grpc_client_completed_latency_seconds: (Optional) Histogram of rpc response latency for completed rpcs, in seconds.
    • grpc_client_msg_received_total: Total number of stream messages received from the server.
    • grpc_client_msg_sent_total: Total number of stream messages sent by the client.

Note that by passing a Configuration instance to the interceptors, it is possible to configure the following:

  • Whether or not a latency histogram is recorded for RPCs.
  • Which histogram buckets to use for the latency metrics.
  • Which Prometheus CollectorRegistry the metrics get registered with.

The server interceptors have an identical implementation in Golang, go-grpc-prometheus, brought to you by @MWitkow.

Usage

This library is made available on the dinowernli GitHub Maven repository. Once the repository is set up, the library can be included using the following artifact id:

me.dinowernli:java-grpc-prometheus:0.3.0

In order to attach the monitoring server interceptor to your gRPC server, you can do the following:

MonitoringServerInterceptor monitoringInterceptor = 
    MonitoringServerInterceptor.create(Configuration.cheapMetricsOnly());
grpcServer = ServerBuilder.forPort(GRPC_PORT)
    .addService(ServerInterceptors.intercept(
        HelloServiceGrpc.bindService(new HelloServiceImpl()), monitoringInterceptor))
    .build();

In order to attach the monitoring client interceptor to your gRPC client, you can do the following:

MonitoringClientInterceptor monitoringInterceptor =
    MonitoringClientInterceptor.create(Configuration.cheapMetricsOnly());
grpcStub = HelloServiceGrpc.newStub(NettyChannelBuilder.forAddress(REMOTE_HOST, GRPC_PORT)
    .intercept(monitoringInterceptor)
    .build());

If you're using Spring Boot 2 with micrometer-registry-prometheus you should inject the CollectorRegistry that is already provided in the application context:

@Autowired
private CollectorRegistry collectorRegistry;

// use the provided registry 
MonitoringServerInterceptor monitoringInterceptor =  
    MonitoringServerInterceptor.create(Configuration.cheapMetricsOnly().withCollectorRegistry(collectorRegistry));

Related reading

java-grpc-prometheus's People

Contributors

charlesmicou avatar dinowernli avatar garfieldnate avatar jameshiew avatar jorgheymans avatar kozipiotr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.