-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
98 lines (87 loc) · 2.34 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/** Omega-app service http api
**/
package main
import (
"fmt"
"net/http"
"os"
"os/signal"
"runtime"
"time"
"github.com/Dataman-Cloud/omega-metrics/cache"
"github.com/Dataman-Cloud/omega-metrics/config"
"github.com/Dataman-Cloud/omega-metrics/controller"
"github.com/Dataman-Cloud/omega-metrics/db"
"github.com/Dataman-Cloud/omega-metrics/logger"
"github.com/Dataman-Cloud/omega-metrics/util"
log "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
)
func destroy() {
log.Info("destroying ...")
cache.DestroyCache()
util.DestroyMQ()
}
func main() {
initConfigParam()
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
go func() {
log.Info("received exit signal", <-signals)
destroy()
os.Exit(0)
}()
defer destroy()
initServer()
}
func initConfigParam() {
config.InitConfig()
conf := config.Pairs()
numCPU := conf.NumCPU
runtime.GOMAXPROCS(numCPU)
log.Info("Runing with ", numCPU, " CPUs")
logger.LoadLogConfig()
util.InitMQ()
cache.InitCache()
db.InitDb()
util.InitApp()
util.InitJsonParser()
}
func initServer() {
startC()
gin.SetMode(gin.ReleaseMode)
log.Info("[monitor] is up")
router := gin.New()
router.Use(gin.Logger(), gin.Recovery())
// options Handler
// router.Use(controller.OptionHandler)
router.GET("/", func(c *gin.Context) {
c.String(200, "pass")
})
// healthcheck
router.GET("/api/v3/health/metrics", controller.HealthCheck)
monitorGroup := router.Group("/api/v3")
{
monitorGroup.GET("/clusters/:cluster_id/metrics", controller.ClusterMetricsHandler)
monitorGroup.GET("/clusters/:cluster_id/apps/:app/metrics", controller.AppMetricsHandler)
// Request the single application monitor data
monitorGroup.GET("/clusters/:cluster_id/apps/:app/monitor", controller.AppMonitorHandler)
monitorGroup.GET("/clusters/:cluster_id/apps/:app/session", controller.RequestRate)
// get host app instance info by cluster id and host ip
monitorGroup.GET("/clusters/:cluster_id/ip/:ip/instance", controller.HostInstanceHandler)
}
conf := config.Pairs()
addr := fmt.Sprintf("%s:%d", conf.Host, conf.Port)
server := &http.Server{
Addr: addr,
Handler: router,
ReadTimeout: 20 * time.Second,
WriteTimeout: 20 * time.Second,
MaxHeaderBytes: 1 << 20,
}
err := server.ListenAndServe()
if err != nil {
log.Error("Can't start monitor server: ", err)
panic(-1)
}
}