2019-05-22 23:16:55 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
|
2019-11-12 15:18:09 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
|
2019-05-22 23:16:55 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
var httpListenAddr = flag.String("httpListenAddr", ":8428", "TCP address to listen for http connections")
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
buildinfo.Init()
|
|
|
|
logger.Init()
|
2019-12-19 13:32:08 +01:00
|
|
|
logger.Infof("starting VictoriaMetrics at %q...", *httpListenAddr)
|
2019-05-22 23:16:55 +02:00
|
|
|
startTime := time.Now()
|
|
|
|
vmstorage.Init()
|
|
|
|
vmselect.Init()
|
|
|
|
vminsert.Init()
|
|
|
|
|
|
|
|
go httpserver.Serve(*httpListenAddr, requestHandler)
|
|
|
|
logger.Infof("started VictoriaMetrics in %s", time.Since(startTime))
|
|
|
|
|
|
|
|
sig := procutil.WaitForSigterm()
|
|
|
|
logger.Infof("received signal %s", sig)
|
|
|
|
|
|
|
|
logger.Infof("gracefully shutting down webservice at %q", *httpListenAddr)
|
|
|
|
startTime = time.Now()
|
|
|
|
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
|
|
|
logger.Fatalf("cannot stop the webservice: %s", err)
|
|
|
|
}
|
|
|
|
vminsert.Stop()
|
|
|
|
logger.Infof("successfully shut down the webservice in %s", time.Since(startTime))
|
|
|
|
|
|
|
|
vmstorage.Stop()
|
|
|
|
vmselect.Stop()
|
|
|
|
|
2019-11-12 15:18:09 +01:00
|
|
|
fs.MustStopDirRemover()
|
|
|
|
|
2019-05-22 23:16:55 +02:00
|
|
|
logger.Infof("the VictoriaMetrics has been stopped in %s", time.Since(startTime))
|
|
|
|
}
|
|
|
|
|
|
|
|
func requestHandler(w http.ResponseWriter, r *http.Request) bool {
|
|
|
|
if vminsert.RequestHandler(w, r) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if vmselect.RequestHandler(w, r) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if vmstorage.RequestHandler(w, r) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|