Skip to content

Commit 4c8307f

Browse files
authored
*: add victoriametrics API (#249)
close #248
1 parent 1f1d885 commit 4c8307f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

service/http/http.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"path"
88
"time"
99

10+
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert"
11+
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect"
12+
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage"
1013
conprofhttp "github.com/pingcap/ng-monitoring/component/conprof/http"
1114
"github.com/pingcap/ng-monitoring/component/topsql"
1215
"github.com/pingcap/ng-monitoring/config"
@@ -63,15 +66,33 @@ func ServeHTTP(l *config.Log, listener net.Listener) {
6366
promHandler.ServeHTTP(c.Writer, c.Request)
6467
})
6568

69+
wh := &wrapHeander{ngHanlder: ng}
6670
httpServer = &http.Server{
67-
Handler: ng,
71+
Handler: wh,
6872
ReadHeaderTimeout: 5 * time.Second,
6973
}
7074
if err = httpServer.Serve(listener); err != nil && err != http.ErrServerClosed {
7175
log.Warn("failed to serve http service", zap.Error(err))
7276
}
7377
}
7478

79+
type wrapHeander struct {
80+
ngHanlder http.Handler
81+
}
82+
83+
func (wrap *wrapHeander) ServeHTTP(w http.ResponseWriter, r *http.Request) {
84+
if vminsert.RequestHandler(w, r) {
85+
return
86+
}
87+
if vmselect.RequestHandler(w, r) {
88+
return
89+
}
90+
if vmstorage.RequestHandler(w, r) {
91+
return
92+
}
93+
wrap.ngHanlder.ServeHTTP(w, r)
94+
}
95+
7596
type Status struct {
7697
Health bool `json:"health"`
7798
}

0 commit comments

Comments
 (0)