Question on how to use the library
Hi, Our service is a GRPC service, and I am trying to use this library with prometheus to manage the metrics, I have tried to setup my code following the usage example, though it doesn't work, could you give me some suggestions on this? My grpc server looks like:
var server: Server = null var httpServer: HTTPServer = null val pushRegistry = new CollectorRegistry()
def start(): Unit = { val serverBuilder = if (config.auth.enableTls) { val certPath = Paths.get(config.auth.serverCertFolder, config.auth.serverCertFilename).toString val keyPath = Paths.get(config.auth.serverCertFolder, config.auth.serverCertKeyFilename).toString if (config.auth.enableClientAuth) getSecureServerWithClientAuthBuilder(MuFnServer.port, certPath, keyPath, config.auth.trustStorePath) else getSecureServerBuilder(MuFnServer.port, certPath, keyPath, config.auth.trustStorePath) } else getInsecureServerBuilder(MuFnServer.port)
httpServer = new HTTPServer(9090)
server = serverBuilder
.addService(MuFnServiceGrpc.bindService(new MuFnImpl(config, openTelemetry), executionContext))
.addService(ProtoReflectionService.newInstance())
.intercept(MonitoringServerInterceptor.create(Configuration.cheapMetricsOnly()
.withCollectorRegistry(pushRegistry)))
.build
.start
sys.addShutdownHook {
logger.error("*** shutting down gRPC server since JVM is shutting down")
self.stop()
logger.error("*** server shut down")
}
And my prometheus setup in pod-spec is as below:
template: metadata: annotations: "prometheus.io/scrape": "true" "prometheus.io/port": "8888" "prometheus.io/path": "/metrics" labels: app.kubernetes.io/name: mufn-service ginku.opentelemetry.onboard: "true"
Hi @NancyXie2022 , I'm having trouble following what you mean by "doesn't work". Could you clarify what behavior you're expecting to see, and what you're seeing instead?
hmm, I don't see metric get emitted, that what I mean it doesn't work. I create a httpServer using port 9090, I try to do this: curl -v http://localhost:9090/metrics there is no result though
curl -v http://localhost:9090/metrics
- About to connect() to localhost port 9090 (#0)
- Trying ::1...
- Connected to localhost (::1) port 9090 (#0)
GET /metrics HTTP/1.1 User-Agent: curl/7.29.0 Host: localhost:9090 Accept: /
< HTTP/1.1 200 OK < Date: Thu, 08 Dec 2022 21:54:13 GMT < Transfer-encoding: chunked < Content-type: text/plain; version=0.0.4; charset=utf-8 <
- Connection #0 to host localhost left intact
@dinowernli thanks for your quick response
And also do you think my code is right or do you see anything wrong with it?
Looking at your code, I would expect the RPC server to correctly emit metrics into your pushRegistry object. I don't see you using it anywhere for serving via your metrics endpoint though. So I'm guessing you've got a missing step there to wire that up.
Hmm, do you mind how to make it serving via your metrics endpoint? Any example on that?
Assuming your HTTPServer is the one described here [1], then I think the missing piece might be to actually pass in your pushRegistry by calling .withRegistry(pushRegistry), see [2].
[1] https://github.com/prometheus/client_java/tree/7cf0cc9dc58981198be106a27333653bed7bf688#http [2] https://github.com/prometheus/client_java/blob/7cf0cc9dc58981198be106a27333653bed7bf688/simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java#L309