Implemented GET, POST, DELETE and PUT services on a books database using Mux router and Go. Tested it using Postman and CURL. Monitored it using Prometheus and Grafana.
- GET request using CURL -
curl http://localhost:8000/api/books -X GET | jq
Response -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 248 100 248 0 0 121k 0 --:--:-- --:--:-- --:--:-- 242k
[
{
"id": 1,
"isbn": "978-0812036381",
"title": "Hamlet",
"author": {
"firstname": "William",
"lastname": "Shakespeare"
}
},
{
"id": 2,
"isbn": "978-0671027032",
"title": "How to Win Friends & Influence People",
"author": {
"firstname": "Dale",
"lastname": "Carnegie"
}
}
]
- GET request using CURL -
curl http://localhost:8000/api/books/1 -X GET | jq
Response -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 108 100 108 0 0 105k 0 --:--:-- --:--:-- --:--:-- 105k
{
"id": 1,
"isbn": "978-0812036381",
"title": "Hamlet",
"author": {
"firstname": "William",
"lastname": "Shakespeare"
}
}
-
POST request using CURL -
curl http://localhost:8000/api/books -g -X POST -H "Content-Type: application/json" -d '{"isbn":"978-0060555665","title":"The Intelligent Investor","author":{"firstname":"Benjamin", "lastname":"Graham"}}'
-
DELETE request using CURL -
curl http://localhost:8000/api/books/1 -X "DELETE"
-
PUT request using CURL -
curl http://localhost:8000/api/books/2 -X PUT -H "Content-Type: application/json" -d '{"isbn":"978-1503212831","title":"A Christmas Carol","author":{"firstname":"Charles", "lastname":"Dickens"}}'
make swagger
to generate swagger.yaml file.- serving the swagger.yaml file to Redoc middlewares.
- Getting the docs ready.
- Edit the api to get the matrices at
http://localhost:8000/metrics
- cd in the prometheus folder and change the
prometheus.yml
file accordingly. - cd to the prometheus download folder and
./prometheus --config.file=prometheus.yml
- Check whether prometheus server is running and whether the targets are UP by going to -
http://localhost:9090/new/targets
- Start grafana
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server
- Open
http://localhost:3000/
- Import prometheus as datasource in grafana
- Import an already made dashboard.
- https://www.keycdn.com/support/popular-curl-examples#:~:text=13.-,GET%20method,request%20GET%20or%20%2DX%20GET%20.
- https://github.com/rusart/muxprom
- https://www.youtube.com/watch?v=SonwZ6MF5BE
- https://dzone.com/articles/go-microservices-part-15-monitoring-with-prometheu
- https://banzaicloud.com/blog/monitoring-gin-with-prometheus/
- https://prometheus.io/docs/prometheus/latest/getting_started/
- https://medium.com/htc-research-engineering-blog/build-a-monitoring-dashboard-by-prometheus-grafana-741a7d949ec2
- https://goswagger.io/generate/spec.html