mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
[ADD] add service prometheus monitor
This commit is contained in:
parent
1a983ff258
commit
a036e92f86
@ -43,7 +43,7 @@ var (
|
||||
)
|
||||
|
||||
var healthDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName("", "", "health_status"),
|
||||
prometheus.BuildFQName(namespace, exporter, "health_status"),
|
||||
"health status.",
|
||||
[]string{"service_name"}, nil,
|
||||
)
|
||||
|
@ -159,7 +159,7 @@ func (s *storeManager) Scrape(ch chan<- prometheus.Metric, namespace, exporter,
|
||||
[]string{"from", "chan"}, nil,
|
||||
)
|
||||
var healthDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName("", "", "health_status"),
|
||||
prometheus.BuildFQName(namespace, exporter, "health_status"),
|
||||
"health status.",
|
||||
[]string{"service_name"}, nil,
|
||||
)
|
||||
|
@ -112,17 +112,22 @@ func handleStatus(serviceTable *termtables.Table, ready bool, v *client.HostNode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func handleResult(table *uitable.Table, v *client.HostNode) {
|
||||
table.AddRow("Uid:", v.ID)
|
||||
table.AddRow("IP:", v.InternalIP)
|
||||
table.AddRow("HostName:", v.HostName)
|
||||
|
||||
for _, v := range v.NodeStatus.Conditions {
|
||||
table.AddRow(string(v.Type),string(v.Status))
|
||||
table.AddRow(string(v.Type), string(v.Status), handleMessage(string(v.Status), v.Message))
|
||||
}
|
||||
}
|
||||
|
||||
func handleMessage(status string, message string) string {
|
||||
if status == "True" {
|
||||
return "N/A"
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
//NewCmdNode NewCmdNode
|
||||
func NewCmdNode() cli.Command {
|
||||
@ -212,7 +217,7 @@ func NewCmdNode() cli.Command {
|
||||
table := uitable.New()
|
||||
table.Wrap = true // wrap columns
|
||||
fmt.Printf("-------------------%s-----------------------\n", v.HostName)
|
||||
handleResult(table,v)
|
||||
handleResult(table, v)
|
||||
|
||||
fmt.Println(table)
|
||||
return nil
|
||||
|
94
monitor/callback/mq.go
Normal file
94
monitor/callback/mq.go
Normal file
@ -0,0 +1,94 @@
|
||||
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
|
||||
// RAINBOND, Application Management Platform
|
||||
|
||||
// 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/>.
|
||||
|
||||
package callback
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/goodrain/rainbond/discover"
|
||||
"github.com/goodrain/rainbond/discover/config"
|
||||
"github.com/goodrain/rainbond/monitor/prometheus"
|
||||
"github.com/goodrain/rainbond/monitor/utils"
|
||||
"github.com/prometheus/common/model"
|
||||
"time"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type Mq struct {
|
||||
discover.Callback
|
||||
Prometheus *prometheus.Manager
|
||||
sortedEndpoints []string
|
||||
}
|
||||
|
||||
func (m *Mq) UpdateEndpoints(endpoints ...*config.Endpoint) {
|
||||
// 用v3 API注册,返回json格试,所以要提前处理一下
|
||||
newEndpoints := make([]*config.Endpoint, 0, len(endpoints))
|
||||
for _, end := range endpoints {
|
||||
newEnd := *end
|
||||
newEndpoints = append(newEndpoints, &newEnd)
|
||||
}
|
||||
|
||||
for i, end := range endpoints {
|
||||
newEndpoints[i].URL = gjson.Get(end.URL, "Addr").String()
|
||||
}
|
||||
|
||||
newArr := utils.TrimAndSort(newEndpoints)
|
||||
|
||||
if utils.ArrCompare(m.sortedEndpoints, newArr) {
|
||||
logrus.Debugf("The endpoints is not modify: %s", m.Name())
|
||||
return
|
||||
}
|
||||
|
||||
m.sortedEndpoints = newArr
|
||||
|
||||
scrape := m.toScrape()
|
||||
m.Prometheus.UpdateScrape(scrape)
|
||||
}
|
||||
|
||||
func (m *Mq) Error(err error) {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
func (m *Mq) Name() string {
|
||||
return "webcli"
|
||||
}
|
||||
|
||||
func (m *Mq) toScrape() *prometheus.ScrapeConfig {
|
||||
ts := make([]string, 0, len(m.sortedEndpoints))
|
||||
for _, end := range m.sortedEndpoints {
|
||||
ts = append(ts, end)
|
||||
}
|
||||
|
||||
return &prometheus.ScrapeConfig{
|
||||
JobName: m.Name(),
|
||||
ScrapeInterval: model.Duration(time.Minute),
|
||||
ScrapeTimeout: model.Duration(30 * time.Second),
|
||||
MetricsPath: "/metrics",
|
||||
HonorLabels: true,
|
||||
ServiceDiscoveryConfig: prometheus.ServiceDiscoveryConfig{
|
||||
StaticConfigs: []*prometheus.Group{
|
||||
{
|
||||
Targets: ts,
|
||||
Labels: map[model.LabelName]model.LabelValue{
|
||||
"service_name": model.LabelValue(m.Name()),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
94
monitor/callback/webcli.go
Normal file
94
monitor/callback/webcli.go
Normal file
@ -0,0 +1,94 @@
|
||||
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
|
||||
// RAINBOND, Application Management Platform
|
||||
|
||||
// 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/>.
|
||||
|
||||
package callback
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/goodrain/rainbond/discover"
|
||||
"github.com/goodrain/rainbond/discover/config"
|
||||
"github.com/goodrain/rainbond/monitor/prometheus"
|
||||
"github.com/goodrain/rainbond/monitor/utils"
|
||||
"github.com/prometheus/common/model"
|
||||
"time"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type Webcli struct {
|
||||
discover.Callback
|
||||
Prometheus *prometheus.Manager
|
||||
sortedEndpoints []string
|
||||
}
|
||||
|
||||
func (w *Webcli) UpdateEndpoints(endpoints ...*config.Endpoint) {
|
||||
// 用v3 API注册,返回json格试,所以要提前处理一下
|
||||
newEndpoints := make([]*config.Endpoint, 0, len(endpoints))
|
||||
for _, end := range endpoints {
|
||||
newEnd := *end
|
||||
newEndpoints = append(newEndpoints, &newEnd)
|
||||
}
|
||||
|
||||
for i, end := range endpoints {
|
||||
newEndpoints[i].URL = gjson.Get(end.URL, "Addr").String()
|
||||
}
|
||||
|
||||
newArr := utils.TrimAndSort(newEndpoints)
|
||||
|
||||
if utils.ArrCompare(w.sortedEndpoints, newArr) {
|
||||
logrus.Debugf("The endpoints is not modify: %s", w.Name())
|
||||
return
|
||||
}
|
||||
|
||||
w.sortedEndpoints = newArr
|
||||
|
||||
scrape := w.toScrape()
|
||||
w.Prometheus.UpdateScrape(scrape)
|
||||
}
|
||||
|
||||
func (w *Webcli) Error(err error) {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
func (w *Webcli) Name() string {
|
||||
return "webcli"
|
||||
}
|
||||
|
||||
func (w *Webcli) toScrape() *prometheus.ScrapeConfig {
|
||||
ts := make([]string, 0, len(w.sortedEndpoints))
|
||||
for _, end := range w.sortedEndpoints {
|
||||
ts = append(ts, end)
|
||||
}
|
||||
|
||||
return &prometheus.ScrapeConfig{
|
||||
JobName: w.Name(),
|
||||
ScrapeInterval: model.Duration(time.Minute),
|
||||
ScrapeTimeout: model.Duration(30 * time.Second),
|
||||
MetricsPath: "/metrics",
|
||||
HonorLabels: true,
|
||||
ServiceDiscoveryConfig: prometheus.ServiceDiscoveryConfig{
|
||||
StaticConfigs: []*prometheus.Group{
|
||||
{
|
||||
Targets: ts,
|
||||
Labels: map[model.LabelName]model.LabelValue{
|
||||
"service_name": model.LabelValue(w.Name()),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
@ -51,6 +51,8 @@ func (d *Monitor) Start() {
|
||||
d.discoverv2.AddProject("app_sync_runtime_server", &callback.AppStatus{Prometheus: d.manager})
|
||||
d.discoverv2.AddProject("builder", &callback.Builder{Prometheus: d.manager})
|
||||
d.discoverv2.AddProject("worker", &callback.Worker{Prometheus: d.manager})
|
||||
d.discoverv2.AddProject("acp_webcli", &callback.Webcli{Prometheus: d.manager})
|
||||
d.discoverv2.AddProject("rainbond_mq", &callback.Webcli{Prometheus: d.manager})
|
||||
|
||||
// node and app runtime metrics needs to be monitored separately
|
||||
go d.discoverNodes(&callback.Node{Prometheus: d.manager}, &callback.App{Prometheus: d.manager}, d.ctx.Done())
|
||||
|
Loading…
Reference in New Issue
Block a user