GithubHelp home page GithubHelp logo

utf18 / go-mux Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 5.0 18 KB

golang rest api with a gorilla/mux router and prometheus metrics

License: MIT License

Go 89.97% Shell 10.03%
go docker prometheus rest grafana golang

go-mux's Introduction

Sample Project for a gorilla/mux based go rest API with prometheus metrics enabled and simple request logging.

Build Status

the main app is a sample golang application with a gorilla/mux based router.

port 8080 is used and you can build it yourself with: go get -d github.com/ben-st/go-mux

linux: CGO_ENABLED=0 GOOS=linux go build -o mux

OSX: CGO_ENABLED=0 GOOS=darwin go build -o mux

after this you should be able to start it with: ./mux

and test it with curl localhost:8080

or for the metrics endpoint: curl localhost:8080/metrics

If you do not want to build it yourself just use docker or even more convenient docker-compose

docker-compose up

this will launch a stack with grafana, prometheus and the mux application

You can reach your applications under:

grafana:

  • localhost:3000/login
  • admin:password

prometheus:

  • localhost:9090

mux:

  • localhost:8080

If you want to check if prometheus scrapes the mux application correctly, you can use the util/configure-grafana-datasource.sh script to configure the prometheus datasource. After this you only have to import the dashboards in the grafana folder. The mux-dashboard.json is a very basic dashboard which displays the go_threads of both prometheus and mux.

i added a simple prometheus gauge in the gauge.go file to show how to get updated metrics while the http server is running and blocking.

Contributing

All patches are welcome! If you find something is missing or broken send me a PR or file an issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.