-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
60 lines (49 loc) · 1.1 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
"github.com/utkarsh-1905/scm/scm"
"github.com/utkarsh-1905/scm/server"
"github.com/utkarsh-1905/scm/signal"
"github.com/utkarsh-1905/scm/utils"
)
func main() {
log.Println("Starting Metrics Server")
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
utils.AddAndParseFlags()
r := mux.NewRouter()
subRouter := r.PathPrefix("/").Subrouter()
server.RegisterRoutesAndMiddleware(subRouter)
r.PathPrefix("/").Handler(subRouter)
utils.StartInfluxDB()
utils.CheckCMDFlags()
go func() {
for {
log.Println("Waiting for Signal")
select {
case <-signal.SigChan.Start:
processes, err := utils.GetProcsByName()
if err != nil {
log.Println("Error getting processes by name")
continue
}
scm.SCM(processes, utils.WriteAPI)
case <-signal.SigChan.Kill:
log.Println("Killing SCM Server")
}
}
}()
http.ListenAndServe(":1910", r)
log.Println("SCM Server Started")
}
// Routes Needed
// 1. /start
// 2. /stop
// 4. /status
// 5. /metrics
// 6. /graph