Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collecting metrics #9

Open
igorvpcleao opened this issue May 8, 2017 · 5 comments
Open

Collecting metrics #9

igorvpcleao opened this issue May 8, 2017 · 5 comments

Comments

@igorvpcleao
Copy link

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();
  }
}
@racevedoo
Copy link

I'm having similar issues. It would be great to know if there's anything wrong with this approach.

@shanghai-Jerry
Copy link

i got this problems: io.netty.handler.codec.http2.Http2Exception: HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: 16030100850100008103031a44d4a944f84807b840c9d654

@dinowernli
Copy link
Member

@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?

@wingoku
Copy link

wingoku commented Nov 8, 2017

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?

@wandermonk
Copy link

Did someone able to figure this out. I wanted to capture metrics for my own service.Any help is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants