This repository was archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (36 loc) · 1.29 KB
/
main.go
File metadata and controls
53 lines (36 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// this project is heavily inspired by the prometheus golang client example project
// https://github.com/prometheus/client_golang/blob/master/examples/simple/main.go
package main
import (
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
promhttp "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
)
func main() {
var log = logrus.New()
// set the log output
log.Out = os.Stdout
// set the log level
log.Level = logrus.DebugLevel
// Routes consist of a path and a handler function.
r := mux.NewRouter()
// sample log.Info
log.Info("http server is ready")
// sample log.Debug
log.Debug("i am only visible in debug mode\n")
// exposes / endpoint with the YourHandler handler
r.HandleFunc("/", YourHandler)
// exposes /metrics endpoint with standard golang metrics used by prometheus
r.Handle("/metrics", promhttp.Handler())
// start a goroutine which start the polling for the metrics endpoint
SimpleGauge()
// wrap a logger around the mux server
logWrapper := handlers.LoggingHandler(os.Stdout, r)
metricsWrapper := prometheus.InstrumentHandler("metrics", logWrapper)
// Bind to a port and pass our loggedRouter in
log.Fatal(http.ListenAndServe(":8080", metricsWrapper))
}