-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
46 lines (39 loc) · 912 Bytes
/
server.go
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
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/cobra"
)
var exporterServerCmd = &cobra.Command{
Use: "server",
Short: "Start neo4j_exporter server.",
Run: startServer,
}
func startServer(cmd *cobra.Command, args []string) {
initializeConfig()
collector := newVulsCollector()
prometheus.MustRegister(collector)
router := mux.NewRouter()
router.HandleFunc("/", healthHandler)
router.Handle("/metrics", promhttp.Handler())
log.Fatal(
http.ListenAndServe(
":"+flagPort,
router,
),
)
}
type healthReturn struct {
Status string `json:"status"`
Message string `json:"message"`
}
func healthHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(healthReturn{
Status: "ok",
Message: "",
})
}