[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,19 +1,18 @@
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
@ -31,6 +30,7 @@ func Routes() chi.Router {
r.Get("/docker_console", controller.GetDockerConsole().Get)
r.Get("/docker_log", controller.GetDockerLog().Get)
r.Get("/monitor_message", controller.GetMonitorMessage().Get)
r.Get("/new_monitor_message", controller.GetMonitorMessage().Get)
r.Get("/event_log", controller.GetEventLog().Get)
return r
}

View File

@ -29,6 +29,7 @@ import (
"github.com/goodrain/rainbond/pkg/api/apiRouters/doc"
"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/version2"
@ -43,11 +44,12 @@ import (
//Manager apiserver
type Manager struct {
ctx context.Context
cancel context.CancelFunc
conf option.Config
stopChan chan struct{}
r *chi.Mux
ctx context.Context
cancel context.CancelFunc
conf option.Config
stopChan chan struct{}
r *chi.Mux
prometheusProxy proxy.Proxy
}
//NewManager newManager
@ -73,6 +75,7 @@ func NewManager(c option.Config) *Manager {
//simple api version
r.Use(apimiddleware.APIVersion)
r.Use(apimiddleware.Proxy)
return &Manager{
ctx: ctx,
cancel: cancel,
@ -118,6 +121,10 @@ func (m *Manager) Run() {
m.r.Mount("/license", license.Routes())
//兼容老版docker
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服务和文件服务
go func() {
websocketRouter := chi.NewRouter()
@ -172,3 +179,11 @@ func (m *Manager) EventLogInstance(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
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:
- match: "*.*.*.request.*"
name: "app_http_request"
name: "app_request"
labels:
service_id: "$1"
port: "$2"
protocol: $3
method: "$4"
- match: "*.*.*.request.unusual.*"
name: "app_http_request_unusual"
name: "app_request_unusual"
labels:
service_id: "$1"
port: "$2"
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