mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-04 12:47:36 +08:00
commit
c30c57e1f4
@ -22,7 +22,11 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/goodrain/rainbond/monitor/custom"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/goodrain/rainbond/cmd/monitor/option"
|
||||
@ -46,6 +50,9 @@ func main() {
|
||||
p := prometheus.NewManager(c, a)
|
||||
controllerManager := controller.NewControllerManager(a, p)
|
||||
|
||||
monitorMysql(c, p)
|
||||
monitorKSM(c, p)
|
||||
|
||||
errChan := make(chan error, 1)
|
||||
defer close(errChan)
|
||||
p.StartDaemon(errChan)
|
||||
@ -79,3 +86,19 @@ func main() {
|
||||
}
|
||||
logrus.Info("See you next time!")
|
||||
}
|
||||
|
||||
func monitorMysql(c *option.Config, p *prometheus.Manager) {
|
||||
if strings.TrimSpace(c.MysqldExporter) != "" {
|
||||
metrics := strings.TrimSpace(c.MysqldExporter)
|
||||
logrus.Infof("add mysql metrics[%s] into prometheus", metrics)
|
||||
custom.AddMetrics(p, custom.Metrics{Name: "mysql", Path: "/metrics", Metrics: []string{metrics}, Interval: 30 * time.Second, Timeout: 15 * time.Second})
|
||||
}
|
||||
}
|
||||
|
||||
func monitorKSM(c *option.Config, p *prometheus.Manager) {
|
||||
if strings.TrimSpace(c.KSMExporter) != "" {
|
||||
metrics := strings.TrimSpace(c.KSMExporter)
|
||||
logrus.Infof("add kube-state-metrics[%s] into prometheus", metrics)
|
||||
custom.AddMetrics(p, custom.Metrics{Name: "kubernetes", Path: "/metrics", Metrics: []string{metrics}, Interval: 30 * time.Second, Timeout: 10 * time.Second})
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ type Config struct {
|
||||
QueryTimeout string
|
||||
QueryMaxConcurrency string
|
||||
CadvisorListenPort int
|
||||
MysqldExporter string
|
||||
KSMExporter string
|
||||
}
|
||||
|
||||
// Options for the web Handler.
|
||||
@ -133,6 +135,8 @@ func (c *Config) AddFlag(cmd *pflag.FlagSet) {
|
||||
cmd.StringVar(&c.AdvertiseAddr, "advertise-addr", c.AdvertiseAddr, "advertise address, and registry into etcd.")
|
||||
cmd.IntVar(&c.CadvisorListenPort, "cadvisor-listen-port", c.CadvisorListenPort, "kubelet cadvisor listen port in all node")
|
||||
cmd.StringSliceVar(&c.AlertManagerUrl, "alertmanager-address", c.AlertManagerUrl, "AlertManager url.")
|
||||
cmd.StringVar(&c.MysqldExporter, "mysqld-exporter", c.MysqldExporter, "mysqld exporter address. eg: 127.0.0.1:9104")
|
||||
cmd.StringVar(&c.KSMExporter, "kube-state-metrics", c.KSMExporter, "kube-state-metrics, current server's kube-state-metrics address")
|
||||
}
|
||||
|
||||
//AddPrometheusFlag prometheus flag
|
||||
|
38
monitor/custom/custom.go
Normal file
38
monitor/custom/custom.go
Normal file
@ -0,0 +1,38 @@
|
||||
package custom
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/goodrain/rainbond/monitor/prometheus"
|
||||
"github.com/prometheus/common/model"
|
||||
)
|
||||
|
||||
// Metrics metrics struct
|
||||
type Metrics struct {
|
||||
Name string
|
||||
Metrics []string
|
||||
Interval time.Duration
|
||||
Timeout time.Duration
|
||||
Path string
|
||||
}
|
||||
|
||||
// AddMetrics add mysql metrics into prometheus
|
||||
func AddMetrics(p *prometheus.Manager, metrics Metrics) {
|
||||
p.UpdateScrape(&prometheus.ScrapeConfig{
|
||||
JobName: metrics.Name,
|
||||
ScrapeInterval: model.Duration(metrics.Interval),
|
||||
ScrapeTimeout: model.Duration(metrics.Timeout),
|
||||
MetricsPath: metrics.Path,
|
||||
ServiceDiscoveryConfig: prometheus.ServiceDiscoveryConfig{
|
||||
StaticConfigs: []*prometheus.Group{
|
||||
{
|
||||
Targets: metrics.Metrics,
|
||||
Labels: map[model.LabelName]model.LabelValue{
|
||||
"component": model.LabelValue(metrics.Name),
|
||||
"service_name": model.LabelValue(metrics.Name),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user