mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(monitor,region,host,cloudmon): support VictoriaMetrics as TSDB backend
This commit is contained in:
@@ -20,9 +20,11 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
apis "yunion.io/x/onecloud/pkg/apis/ansible"
|
||||
apiidentity "yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/tsdb"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
ansible_modules "yunion.io/x/onecloud/pkg/mcclient/modules/ansible"
|
||||
@@ -59,27 +61,25 @@ func getServerAttrs(ID string, s *mcclient.ClientSession) (map[string]string, er
|
||||
return params, err
|
||||
}
|
||||
|
||||
func getInfluxdbURL() (string, error) {
|
||||
func getTSDBURL() (string, error) {
|
||||
s := auth.GetAdminSessionWithPublic(nil, "")
|
||||
url, err := s.GetServiceURL("influxdb", apiidentity.EndpointInterfacePublic)
|
||||
|
||||
url, err := tsdb.GetDefaultServiceSourceURL(s, apiidentity.EndpointInterfacePublic)
|
||||
if err != nil {
|
||||
log.Errorf("get influxdb Endpoint error %s", err)
|
||||
return "", err
|
||||
return "", errors.Wrap(err, "get influxdb Endpoint error")
|
||||
}
|
||||
return url, nil
|
||||
}
|
||||
|
||||
func renderExtraVars(vars map[string]string) {
|
||||
|
||||
InfluxdbURL, err := getInfluxdbURL()
|
||||
tsdbURL, err := getTSDBURL()
|
||||
if err != nil {
|
||||
log.Errorf("template binding: get influxdb url error: %s", err)
|
||||
return
|
||||
}
|
||||
for key, value := range vars {
|
||||
if key == "influxdb" && value == "INFLUXDB" {
|
||||
vars[key] = InfluxdbURL
|
||||
vars[key] = tsdbURL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/sets"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
ansible_api "yunion.io/x/onecloud/pkg/apis/ansible"
|
||||
comapi "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
)
|
||||
@@ -55,16 +56,26 @@ func GetArgs(ctx context.Context, serverId, proxyEndpointId string, others inter
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to get serverInfo of server %s", serverId)
|
||||
}
|
||||
influxdbUrl := info.serverDetails.MonitorUrl
|
||||
log.Infof("influxdbUrl: %s", influxdbUrl)
|
||||
influxdbUrl, err = FindValidServiceUrl(ctx, Service{"influxdb", influxdbUrl}, proxyEndpointId, info, host)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to convertInfluxdbUrl %s", influxdbUrl)
|
||||
monitorUrl := info.serverDetails.MonitorUrl
|
||||
log.Infof("TSDB monitor Url: %s", monitorUrl)
|
||||
foundSvc := false
|
||||
errs := []error{}
|
||||
for _, svcName := range []string{apis.SERVICE_TYPE_INFLUXDB, apis.SERVICE_TYPE_VICTORIA_METRICS} {
|
||||
if tsdbUrl, err := FindValidServiceUrl(ctx, Service{svcName, monitorUrl}, proxyEndpointId, info, host); err != nil {
|
||||
errs = append(errs, errors.Wrapf(err, "unable to convertInfluxdbUrl %s", monitorUrl))
|
||||
} else {
|
||||
monitorUrl = tsdbUrl
|
||||
foundSvc = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(influxdbUrl) == 0 {
|
||||
if !foundSvc {
|
||||
return nil, errors.Wrapf(errors.NewAggregate(errs), "convert TSDB service URL")
|
||||
}
|
||||
if len(monitorUrl) == 0 {
|
||||
return nil, errors.Wrap(ErrCannotReachInfluxbd, "please create usable Proxy Endpoint for server and try again")
|
||||
}
|
||||
return getArgs(&info, influxdbUrl), nil
|
||||
return getArgs(&info, monitorUrl), nil
|
||||
}
|
||||
func getArgs(info *sServerInfo, influxdbUrl string) map[string]interface{} {
|
||||
tags := map[string]string{
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"yunion.io/x/pkg/util/httputils"
|
||||
"yunion.io/x/pkg/util/sets"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
ansible_api "yunion.io/x/onecloud/pkg/apis/ansible"
|
||||
proxy_api "yunion.io/x/onecloud/pkg/apis/cloudproxy"
|
||||
comapi "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -46,7 +47,7 @@ type Service struct {
|
||||
|
||||
func serviceComplete(serviceName, address string, port int) (url, checkUrl string, expectedCode int) {
|
||||
switch serviceName {
|
||||
case "influxdb":
|
||||
case apis.SERVICE_TYPE_INFLUXDB, apis.SERVICE_TYPE_VICTORIA_METRICS:
|
||||
return fmt.Sprintf("https://%s:%d", address, port), fmt.Sprintf("https://%s:%d/ping", address, port), 204
|
||||
case "repo":
|
||||
return fmt.Sprintf("http://%s:%d", address, port), fmt.Sprintf("http://%s:%d", address, port), 200
|
||||
@@ -57,7 +58,7 @@ func serviceComplete(serviceName, address string, port int) (url, checkUrl strin
|
||||
|
||||
func serviceComplete2(service Service) (completeUrl string, expectedCode int) {
|
||||
switch service.Name {
|
||||
case "influxdb":
|
||||
case apis.SERVICE_TYPE_INFLUXDB, apis.SERVICE_TYPE_VICTORIA_METRICS:
|
||||
return fmt.Sprintf("%s/ping", service.Url), 204
|
||||
case "repo":
|
||||
return service.Url, 200
|
||||
|
||||
Reference in New Issue
Block a user