-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathserver.go
More file actions
37 lines (30 loc) · 961 Bytes
/
server.go
File metadata and controls
37 lines (30 loc) · 961 Bytes
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
package server
import (
"log"
"net"
"strconv"
"github.com/fasthttp/router"
"github.com/urfave/cli/v2"
"github.com/valyala/fasthttp"
"github.com/spendesk/github-actions-exporter/pkg/config"
"github.com/spendesk/github-actions-exporter/pkg/metrics"
)
// RunServer - run http server for expose metrics
func RunServer(ctx *cli.Context) error {
metrics.InitMetrics()
r := router.New()
r.GET("/", func(ctx *fasthttp.RequestCtx) {
ctx.WriteString("/metrics")
})
r.GET("/metrics", prometheusHandler())
if config.Debug {
r.GET("/debug/pprof/", pprofHandlerIndex)
r.GET("/debug/pprof/cmdline", pprofHandlerCmdline)
r.GET("/debug/pprof/profile", pprofHandlerIndex)
r.GET("/debug/pprof/trace", pprofHandlerTrace)
r.GET("/debug/pprof/{profile}", pprofHandlerIndex)
}
log.Print("exporter listening on 0.0.0.0::" + strconv.Itoa(config.Port))
ln, _ := net.Listen("tcp", ":"+strconv.Itoa(config.Port))
return fasthttp.Serve(ln, r.Handler)
}