[ADD] api add proxy for prometheus

This commit is contained in:
goodrain 2018-01-11 13:58:24 +08:00
parent 5aef23e50f
commit 0d1126fc89
3 changed files with 42 additions and 12 deletions

View File

@ -1,4 +1,3 @@
// RAINBOND, Application Management Platform // RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd. // Copyright (C) 2014-2017 Goodrain Co., Ltd.
@ -31,6 +30,7 @@ func Routes() chi.Router {
r.Get("/docker_console", controller.GetDockerConsole().Get) r.Get("/docker_console", controller.GetDockerConsole().Get)
r.Get("/docker_log", controller.GetDockerLog().Get) r.Get("/docker_log", controller.GetDockerLog().Get)
r.Get("/monitor_message", controller.GetMonitorMessage().Get) r.Get("/monitor_message", controller.GetMonitorMessage().Get)
r.Get("/new_monitor_message", controller.GetMonitorMessage().Get)
r.Get("/event_log", controller.GetEventLog().Get) r.Get("/event_log", controller.GetEventLog().Get)
return r return r
} }

View File

@ -29,6 +29,7 @@ import (
"github.com/goodrain/rainbond/pkg/api/apiRouters/doc" "github.com/goodrain/rainbond/pkg/api/apiRouters/doc"
"github.com/goodrain/rainbond/pkg/api/apiRouters/license" "github.com/goodrain/rainbond/pkg/api/apiRouters/license"
"github.com/goodrain/rainbond/pkg/api/proxy"
"github.com/goodrain/rainbond/pkg/api/apiRouters/cloud" "github.com/goodrain/rainbond/pkg/api/apiRouters/cloud"
"github.com/goodrain/rainbond/pkg/api/apiRouters/version2" "github.com/goodrain/rainbond/pkg/api/apiRouters/version2"
@ -48,6 +49,7 @@ type Manager struct {
conf option.Config conf option.Config
stopChan chan struct{} stopChan chan struct{}
r *chi.Mux r *chi.Mux
prometheusProxy proxy.Proxy
} }
//NewManager newManager //NewManager newManager
@ -73,6 +75,7 @@ func NewManager(c option.Config) *Manager {
//simple api version //simple api version
r.Use(apimiddleware.APIVersion) r.Use(apimiddleware.APIVersion)
r.Use(apimiddleware.Proxy) r.Use(apimiddleware.Proxy)
return &Manager{ return &Manager{
ctx: ctx, ctx: ctx,
cancel: cancel, cancel: cancel,
@ -118,6 +121,10 @@ func (m *Manager) Run() {
m.r.Mount("/license", license.Routes()) m.r.Mount("/license", license.Routes())
//兼容老版docker //兼容老版docker
m.r.Get("/v1/etcd/event-log/instances", m.EventLogInstance) m.r.Get("/v1/etcd/event-log/instances", m.EventLogInstance)
//prometheus单节点代理
m.r.Get("/api/v1/query", m.PrometheusAPI)
m.r.Get("/api/v1/query_range", m.PrometheusAPI)
//开启对浏览器的websocket服务和文件服务 //开启对浏览器的websocket服务和文件服务
go func() { go func() {
websocketRouter := chi.NewRouter() websocketRouter := chi.NewRouter()
@ -172,3 +179,11 @@ func (m *Manager) EventLogInstance(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404) w.WriteHeader(404)
return return
} }
//PrometheusAPI prometheus api 代理
func (m *Manager) PrometheusAPI(w http.ResponseWriter, r *http.Request) {
if m.prometheusProxy == nil {
m.prometheusProxy = proxy.CreateProxy("prometheus", "http", []string{"127.0.0.1:9999"})
}
m.prometheusProxy.Proxy(w, r)
}

View File

@ -1,16 +1,31 @@
# #
mappings: mappings:
- match: "*.*.*.request.*" - match: "*.*.*.request.*"
name: "app_http_request" name: "app_request"
labels: labels:
service_id: "$1" service_id: "$1"
port: "$2" port: "$2"
protocol: $3 protocol: $3
method: "$4" method: "$4"
- match: "*.*.*.request.unusual.*" - match: "*.*.*.request.unusual.*"
name: "app_http_request_unusual" name: "app_request_unusual"
labels: labels:
service_id: "$1" service_id: "$1"
port: "$2" port: "$2"
protocol: $3 protocol: $3
code: "$4" code: "$4"
- match: "*.*.*.requesttime.*"
name: "app_requesttime"
labels:
service_id: "$1"
port: "$2"
protocol: $3
mode: "$4"
- match: "*.*.*.requestclient"
name: "app_requestclient"
labels:
service_id: "$1"
port: "$2"
protocol: $3