mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-04 12:47:36 +08:00
39 lines
921 B
Go
39 lines
921 B
Go
|
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),
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
}
|