Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/positiveblue/poc-grpc-prometheus
https://github.com/positiveblue/poc-grpc-prometheus
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/positiveblue/poc-grpc-prometheus
- Owner: positiveblue
- Created: 2020-02-20T18:28:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-06T21:45:32.000Z (almost 5 years ago)
- Last Synced: 2024-04-17T09:12:41.377Z (9 months ago)
- Language: Go
- Size: 21.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
First version of a Go gRPC Prometheus Interceptor
## What is this this?
`client/client.go` calls our gRPC server SayHello method with two different values for the method parameter `Name`
`server/server.go` exposes and endpoint for the prometheus metrics and a grpc method SayHello which receives a `Name` param. The GRPC method has a unary interceptor for exposing two metrics: handled req counter and handled req histogram. The metrics are populated with three labels `req service`, `req method` and the value of the req param `Name`. For getting the value of req.Name we use a method `func CustomLable(v {}interface) string` which basically uses type assertion for casting the interface and getting the right value for the label. For each req type that we want to decorate with the custom label we will have to add a case in the switch statement. Oterwhise, the metrics are populated with the "unknown" label.
`prometheus.yaml`: prometheus configuration
## How to run this?
Open three terminals and run```
prometheus --config.file=prometheus.yaml # prometheus bin should be in your path
```
```
go run server.go
``````
go run client.go
```Open your browser and go to `localhost:9090`.