Build a golang application with built in Prometheus metrics, serving json data.
The Build process uses a standard golang image with all build tools included, and generates a static linux binary which runs inside a scratch
container.
The advantages of this approach are: -
- Smaller size
- Quicker runtime
- Uses less resources
- Smaller attack surface
Pull down the repo, and change directory
git clone https://github.com/mjbower/go-prom-example.git
cd go-prom-example
Build the container to your local Docker registry
docker build -t goex1 .
This exposes port 8080 locally, the routes are logged in the startup message
docker run -p 8080:8080 goex1
Listening on: -
http://localhost:8080/shownodes
Use Apache benchmark to send a high volume of requests
ab -n 10000 -c 200 "localhost:8080/shownodes"