Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

A complete example to expose /metrics #4

Closed
huichen opened this issue May 16, 2016 · 6 comments
Closed

A complete example to expose /metrics #4

huichen opened this issue May 16, 2016 · 6 comments

Comments

@huichen
Copy link

huichen commented May 16, 2016

Can you provide a complete example to expose /metrics in grpc server? Can't find any in the codebase.

@mwitkow
Copy link
Member

mwitkow commented May 16, 2016

For a more comprehensive guide on how to use golang Prometheus library, see:
https://github.com/prometheus/client_golang

@prestonvanloon
Copy link

Can you provide a better example? How does gRPC and http /metrics get served? The example doesn't make sense when you are serving like this:

	s := grpc.NewServer(
		grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
		grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor),
	)
        myservice.RegisterMyServiceServer(s, &myServiceImpl{})
	grpc_prometheus.Register(s)
	http.Handle("/metrics", prometheus.Handler())

	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}

@HTChang
Copy link

HTChang commented Jan 23, 2017

I have exactly the same question here. Any good practice to serve on both gRPC and http? @mwitkow

@mwitkow
Copy link
Member

mwitkow commented Jan 23, 2017

@prestonvanloon, I think the thing you're lacking here is a separate goroutine with http.ListenAndServe. Unfortunately, the grpc.Server.Serve is not an HTTP server by itself, so you need to start a gRPC server and an HTTP server separately.

@HTChang in terms of best practices of serving both gRPC and HTTP.. that's a little bit beyond the scope of this repo in particular. Maybe worthwhile bringing it up in upstream? https://github.com/grpc/grpc-go

@prestonvanloon
Copy link

@mwitkow It looks like they have a method to serveHTTP but it has very poor performance and is mostly undocumented.
grpc/grpc-go#549

One approach is to have the http on a separate goroutine and port, like you suggested, but I'm not sure how that would impact discovery or reporting.

@FX-HAO
Copy link

FX-HAO commented Jan 24, 2018

@prestonvanloon Can you share the code? How to use serveHTTP?

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

No branches or pull requests

5 participants