{"action":"created","comment":{"url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/comments/175514784","pull_request_review_id":105052183,"id":175514784,"diff_hunk":"@@ -0,0 +1,78 @@\n+package main\n+\n+import (\n+\t\"fmt\"\n+\t\"log\"\n+\t\"net\"\n+\t\"net/http\"\n+\n+\t\"golang.org/x/net/context\"\n+\t\"google.golang.org/grpc\"\n+\n+\t\"github.com/grpc-ecosystem/go-grpc-prometheus\"\n+\tpb \"github.com/grpc-ecosystem/go-grpc-prometheus/examples/grpc-server-with-prometheus/protobuf\"\n+\t\"github.com/prometheus/client_golang/prometheus\"\n+\t\"github.com/prometheus/client_golang/prometheus/promhttp\"\n+)\n+\n+// DemoServiceServer defines a Server.\n+type DemoServiceServer struct{}\n+\n+func newDemoServer() *DemoServiceServer {\n+\treturn &DemoServiceServer{}\n+}\n+\n+// SayHello implements a interface defined by protobuf.\n+func (s *DemoServiceServer) SayHello(ctx context.Context, request *pb.HelloRequest) (*pb.HelloResponse, error) {\n+\tpushCounter.Inc()\n+\treturn &pb.HelloResponse{Message: fmt.Sprintf(\"Hello %s\", request.Name)}, nil\n+}\n+\n+// Create a counter metric\n+var (\n+\tpushCounter = prometheus.NewCounter(prometheus.CounterOpts{\n+\t\tName: \"repository_pushes\",\n+\t\tHelp: \"Number of pushes to external repository.\",\n+\t})\n+)\n+\n+func init() {\n+\t// Metrics have to be registered to be exposed:\n+\tprometheus.MustRegister(pushCounter)\n+}\n+\n+func main() {\n+\t// Listen an actual port.\n+\tlis, err := net.Listen(\"tcp\", fmt.Sprintf(\":%d\", 9093))\n+\tif err != nil {\n+\t\tlog.Fatalf(\"failed to listen: %v\", err)\n+\t}\n+\n+\t// Create a HTTP server for prometheus.\n+\thttpServer := &http.Server{Handler: promhttp.Handler(), Addr: fmt.Sprintf(\"0.0.0.0:%d\", 9092)}\n+\n+\t// Create a gRPC Server with gRPC interceptor.\n+\tgrpcServer := grpc.NewServer(\n+\t\tgrpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),\n+\t\tgrpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor),\n+\t)\n+\n+\t// Register your service.\n+\tpb.RegisterDemoServiceServer(grpcServer, newDemoServer())\n+\n+\t// Enable Histogram for gRPC-Prometheus interceptor.\n+\tgrpc_prometheus.EnableHandlingTimeHistogram()\n+\n+\t// Register your gRPC Server to gRPC-Prometheus interceptor.\n+\tgrpc_prometheus.Register(grpcServer)\n+\n+\t// Start your http server for prometheus.\n+\tgo func() {\n+\t\tif err := httpServer.ListenAndServe(); err != nil {\n+\t\t\tlog.Fatal(\"Unable to start a http server.\")","path":"examples/grpc-server-with-prometheus/server/server.go","position":72,"original_position":72,"commit_id":"d7f48af461854088571d230344f9783f78c2acb6","original_commit_id":"d7f48af461854088571d230344f9783f78c2acb6","user":{"login":"Bplotka","id":6950331,"avatar_url":"https://avatars2.githubusercontent.com/u/6950331?v=4","gravatar_id":"","url":"https://api.github.com/users/Bplotka","html_url":"https://github.com/Bplotka","followers_url":"https://api.github.com/users/Bplotka/followers","following_url":"https://api.github.com/users/Bplotka/following{/other_user}","gists_url":"https://api.github.com/users/Bplotka/gists{/gist_id}","starred_url":"https://api.github.com/users/Bplotka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bplotka/subscriptions","organizations_url":"https://api.github.com/users/Bplotka/orgs","repos_url":"https://api.github.com/users/Bplotka/repos","events_url":"https://api.github.com/users/Bplotka/events{/privacy}","received_events_url":"https://api.github.com/users/Bplotka/received_events","type":"User","site_admin":false},"body":"Still graceful shutdown would be nice to add here. What do you think? (: \r\n\r\nGraceful shutdown means the ability to complete all the requests with given timeout on e.g interrupt (Ctrl+C)\r\nCurrently, this program probably does not care about Ctrl+C (interrupt signal) or is doing something random on that.","created_at":"2018-03-19T17:14:08Z","updated_at":"2018-03-19T17:14:39Z","html_url":"https://github.com/grpc-ecosystem/go-grpc-prometheus/pull/35#discussion_r175514784","pull_request_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/35","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/comments/175514784"},"html":{"href":"https://github.com/grpc-ecosystem/go-grpc-prometheus/pull/35#discussion_r175514784"},"pull_request":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/35"}}},"pull_request":{"url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/35","id":165022894,"html_url":"https://github.com/grpc-ecosystem/go-grpc-prometheus/pull/35","diff_url":"https://github.com/grpc-ecosystem/go-grpc-prometheus/pull/35.diff","patch_url":"https://github.com/grpc-ecosystem/go-grpc-prometheus/pull/35.patch","issue_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/issues/35","number":35,"state":"open","locked":false,"title":"Add example for gRPC-Server with Prometheus","user":{"login":"fengzixu","id":9636615,"avatar_url":"https://avatars0.githubusercontent.com/u/9636615?v=4","gravatar_id":"","url":"https://api.github.com/users/fengzixu","html_url":"https://github.com/fengzixu","followers_url":"https://api.github.com/users/fengzixu/followers","following_url":"https://api.github.com/users/fengzixu/following{/other_user}","gists_url":"https://api.github.com/users/fengzixu/gists{/gist_id}","starred_url":"https://api.github.com/users/fengzixu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengzixu/subscriptions","organizations_url":"https://api.github.com/users/fengzixu/orgs","repos_url":"https://api.github.com/users/fengzixu/repos","events_url":"https://api.github.com/users/fengzixu/events{/privacy}","received_events_url":"https://api.github.com/users/fengzixu/received_events","type":"User","site_admin":false},"body":"In the process of using it, I found that there is no corresponding example for this project. So I provide an example of gRPC Server and Prometheus with go-grpc-prometheus.\r\n\r\n=========\r\n\r\nrelated PR: https://github.com/grpc-ecosystem/go-grpc-prometheus/pull/33\r\ni re-submit this.\r\n\r\n@hsaliak @mwitkow ","created_at":"2018-01-25T03:45:32Z","updated_at":"2018-03-19T17:14:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c73b18d1d677cf2315c12534efc593d24b578482","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/35/commits","review_comments_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/35/comments","review_comment_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/issues/35/comments","statuses_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/statuses/d7f48af461854088571d230344f9783f78c2acb6","head":{"label":"fengzixu:master","ref":"master","sha":"d7f48af461854088571d230344f9783f78c2acb6","user":{"login":"fengzixu","id":9636615,"avatar_url":"https://avatars0.githubusercontent.com/u/9636615?v=4","gravatar_id":"","url":"https://api.github.com/users/fengzixu","html_url":"https://github.com/fengzixu","followers_url":"https://api.github.com/users/fengzixu/followers","following_url":"https://api.github.com/users/fengzixu/following{/other_user}","gists_url":"https://api.github.com/users/fengzixu/gists{/gist_id}","starred_url":"https://api.github.com/users/fengzixu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengzixu/subscriptions","organizations_url":"https://api.github.com/users/fengzixu/orgs","repos_url":"https://api.github.com/users/fengzixu/repos","events_url":"https://api.github.com/users/fengzixu/events{/privacy}","received_events_url":"https://api.github.com/users/fengzixu/received_events","type":"User","site_admin":false},"repo":{"id":117968112,"name":"go-grpc-prometheus","full_name":"fengzixu/go-grpc-prometheus","owner":{"login":"fengzixu","id":9636615,"avatar_url":"https://avatars0.githubusercontent.com/u/9636615?v=4","gravatar_id":"","url":"https://api.github.com/users/fengzixu","html_url":"https://github.com/fengzixu","followers_url":"https://api.github.com/users/fengzixu/followers","following_url":"https://api.github.com/users/fengzixu/following{/other_user}","gists_url":"https://api.github.com/users/fengzixu/gists{/gist_id}","starred_url":"https://api.github.com/users/fengzixu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengzixu/subscriptions","organizations_url":"https://api.github.com/users/fengzixu/orgs","repos_url":"https://api.github.com/users/fengzixu/repos","events_url":"https://api.github.com/users/fengzixu/events{/privacy}","received_events_url":"https://api.github.com/users/fengzixu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fengzixu/go-grpc-prometheus","description":"Prometheus monitoring for your gRPC Go servers.","fork":true,"url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus","forks_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/forks","keys_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/teams","hooks_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/hooks","issue_events_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/events","assignees_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/tags","blobs_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/languages","stargazers_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/stargazers","contributors_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/contributors","subscribers_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/subscribers","subscription_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/subscription","commits_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/merges","archive_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/downloads","issues_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/labels{/name}","releases_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/fengzixu/go-grpc-prometheus/deployments","created_at":"2018-01-18T10:29:02Z","updated_at":"2018-03-19T13:59:56Z","pushed_at":"2018-03-19T13:59:54Z","git_url":"git://github.com/fengzixu/go-grpc-prometheus.git","ssh_url":"git@github.com:fengzixu/go-grpc-prometheus.git","clone_url":"https://github.com/fengzixu/go-grpc-prometheus.git","svn_url":"https://github.com/fengzixu/go-grpc-prometheus","homepage":null,"size":69,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"grpc-ecosystem:master","ref":"master","sha":"ce0256b0cfa9b64c16caf5b91dec256ad649b7d1","user":{"login":"grpc-ecosystem","id":19352526,"avatar_url":"https://avatars3.githubusercontent.com/u/19352526?v=4","gravatar_id":"","url":"https://api.github.com/users/grpc-ecosystem","html_url":"https://github.com/grpc-ecosystem","followers_url":"https://api.github.com/users/grpc-ecosystem/followers","following_url":"https://api.github.com/users/grpc-ecosystem/following{/other_user}","gists_url":"https://api.github.com/users/grpc-ecosystem/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc-ecosystem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc-ecosystem/subscriptions","organizations_url":"https://api.github.com/users/grpc-ecosystem/orgs","repos_url":"https://api.github.com/users/grpc-ecosystem/repos","events_url":"https://api.github.com/users/grpc-ecosystem/events{/privacy}","received_events_url":"https://api.github.com/users/grpc-ecosystem/received_events","type":"Organization","site_admin":false},"repo":{"id":58739665,"name":"go-grpc-prometheus","full_name":"grpc-ecosystem/go-grpc-prometheus","owner":{"login":"grpc-ecosystem","id":19352526,"avatar_url":"https://avatars3.githubusercontent.com/u/19352526?v=4","gravatar_id":"","url":"https://api.github.com/users/grpc-ecosystem","html_url":"https://github.com/grpc-ecosystem","followers_url":"https://api.github.com/users/grpc-ecosystem/followers","following_url":"https://api.github.com/users/grpc-ecosystem/following{/other_user}","gists_url":"https://api.github.com/users/grpc-ecosystem/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc-ecosystem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc-ecosystem/subscriptions","organizations_url":"https://api.github.com/users/grpc-ecosystem/orgs","repos_url":"https://api.github.com/users/grpc-ecosystem/repos","events_url":"https://api.github.com/users/grpc-ecosystem/events{/privacy}","received_events_url":"https://api.github.com/users/grpc-ecosystem/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grpc-ecosystem/go-grpc-prometheus","description":"Prometheus monitoring for your gRPC Go servers.","fork":false,"url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus","forks_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/forks","keys_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/teams","hooks_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/hooks","issue_events_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/events","assignees_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/tags","blobs_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/languages","stargazers_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/stargazers","contributors_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/contributors","subscribers_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/subscribers","subscription_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/subscription","commits_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/merges","archive_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/downloads","issues_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/labels{/name}","releases_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/deployments","created_at":"2016-05-13T12:45:02Z","updated_at":"2018-03-19T09:51:13Z","pushed_at":"2018-03-19T13:59:55Z","git_url":"git://github.com/grpc-ecosystem/go-grpc-prometheus.git","ssh_url":"git@github.com:grpc-ecosystem/go-grpc-prometheus.git","clone_url":"https://github.com/grpc-ecosystem/go-grpc-prometheus.git","svn_url":"https://github.com/grpc-ecosystem/go-grpc-prometheus","homepage":null,"size":68,"stargazers_count":359,"watchers_count":359,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":35,"mirror_url":null,"archived":false,"open_issues_count":15,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":35,"open_issues":15,"watchers":359,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/35"},"html":{"href":"https://github.com/grpc-ecosystem/go-grpc-prometheus/pull/35"},"issue":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/issues/35"},"comments":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/issues/35/comments"},"review_comments":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/35/comments"},"review_comment":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/pulls/35/commits"},"statuses":{"href":"https://api.github.com/repos/grpc-ecosystem/go-grpc-prometheus/statuses/d7f48af461854088571d230344f9783f78c2acb6"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Bplotka"}}