java-grpc-prometheus
java-grpc-prometheus copied to clipboard
Collecting metrics
Hey everyone,
I'm having difficulties to get the library working.
Right below I set a register and bind it to a pushgateway. In addition, I define a gauge and set it to the previous defined register, as well as pass this register as a parameter to MonitoringServerInterceptor . Whenever e check the metrics on pushgateway I only see the gauge I defined. No Grpc metrics are found there.
Am I doing anything wrong?
Thanks in advance!
public class UserApiServer {
private static final int APP_DEFAULT_PORT = 50020;
private static final Logger logger = Logger.getLogger(UserApiServer.class.getName());
private Server server;
static final CollectorRegistry pushRegistry = new CollectorRegistry();
static final Gauge g = (Gauge) Gauge.build().name("userapi").help("blah").register(pushRegistry);
void start(final int port) throws IOException {
final MonitoringServerInterceptor monitoringInterceptor =
MonitoringServerInterceptor.create(Configuration.cheapMetricsOnly().withCollectorRegistry(pushRegistry));
server = ServerBuilder.forPort(port)
.addService(ServerInterceptors.intercept(new UserApiService().bindService(), monitoringInterceptor))
.build()
.start();
logger.info("Server started, listening on " + port);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
logger.warning("*** shutting down gRPC server since JVM is shutting down");
try {
UserApiServer.this.stop();
} catch (IOException ignore) {}
logger.warning("*** server shut down");
}));
}
...
public static void main(String[] args) throws IOException, InterruptedException {
Thread.setDefaultUncaughtExceptionHandler(RaygunExceptionHandler.getInstance());
PushGateway pg = new PushGateway("localhost:9091" );
g.set(42);
pg.push(pushRegistry, "grpc");
final UserApiServer server = new UserApiServer();
server.start(APP_DEFAULT_PORT);
server.blockUntilShutdown();
}
}
I'm having similar issues. It would be great to know if there's anything wrong with this approach.
i got this problems: io.netty.handler.codec.http2.Http2Exception: HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: 16030100850100008103031a44d4a944f84807b840c9d654
@igorvpcleao your code snippet looks sane to me. One thing worth noting is that you will only get metrics once the first rpc is intercepted. Could it be that you just haven't triggered any rpcs yet?
Where does it shows the logs of the intercepted requests from the client on server? Is there a method we need to call to print out the logs?
Did someone able to figure this out. I wanted to capture metrics for my own service.Any help is appreciated.