mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(cloudmon): apsara monitor
This commit is contained in:
@@ -81,7 +81,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230217044210-52661352164d
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230220095739-1ab9c31dce86
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1158,8 +1158,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230217044210-52661352164d h1:5O1nznaWpVVudgt+82cN2ur/ED2GbAVhzlzSuw83z7Q=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230217044210-52661352164d/go.mod h1:yEMFtIKPyIdIfPzsw7oTcH41JXc8G5StUAQw3ZoGj5I=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230220095739-1ab9c31dce86 h1:9h/MiURFtKSbaTPQRdbG+j9L6CzkMc3gGqNBSz/Gxk8=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230220095739-1ab9c31dce86/go.mod h1:yEMFtIKPyIdIfPzsw7oTcH41JXc8G5StUAQw3ZoGj5I=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
Vendored
+1
-1
@@ -1439,7 +1439,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230217044210-52661352164d
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230220095739-1ab9c31dce86
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+2
@@ -113,6 +113,8 @@ type SApsaraClient struct {
|
||||
ownerId string
|
||||
ownerName string
|
||||
|
||||
departments []string
|
||||
|
||||
iregions []cloudprovider.ICloudRegion
|
||||
}
|
||||
|
||||
|
||||
+42
-5
@@ -16,11 +16,13 @@ package apsara
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
)
|
||||
@@ -75,11 +77,48 @@ func (d MetricData) GetTags() map[string]string {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *SApsaraClient) tryGetDepartments() []string {
|
||||
if len(self.departments) > 0 {
|
||||
return self.departments
|
||||
}
|
||||
ret := []string{}
|
||||
if len(self.organizationId) > 0 {
|
||||
ret = append(ret, self.organizationId)
|
||||
}
|
||||
tree, err := self.GetOrganizationTree("1")
|
||||
if err != nil {
|
||||
return ret
|
||||
}
|
||||
for _, child := range tree.Children {
|
||||
if !utils.IsInStringArray(child.Id, ret) && child.Id != "1" {
|
||||
ret = append(ret, child.Id)
|
||||
}
|
||||
}
|
||||
self.departments = ret
|
||||
return self.departments
|
||||
}
|
||||
|
||||
func (self *SApsaraClient) ListMetrics(ns, metricName string, start, end time.Time) ([]MetricData, error) {
|
||||
ret := []MetricData{}
|
||||
departments := self.tryGetDepartments()
|
||||
for i := range departments {
|
||||
part, err := self.listMetrics(departments[i], ns, metricName, start, end)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "NoPermission") {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, part...)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SApsaraClient) listMetrics(departmentId, ns, metricName string, start, end time.Time) ([]MetricData, error) {
|
||||
result := []MetricData{}
|
||||
nextToken := ""
|
||||
for {
|
||||
part, next, err := self.listMetrics(ns, metricName, nextToken, start, end)
|
||||
part, next, err := self._listMetrics(departmentId, ns, metricName, nextToken, start, end)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "listMetrics")
|
||||
}
|
||||
@@ -92,7 +131,7 @@ func (self *SApsaraClient) ListMetrics(ns, metricName string, start, end time.Ti
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (self *SApsaraClient) listMetrics(ns, metricName, nextToken string, start, end time.Time) ([]MetricData, string, error) {
|
||||
func (self *SApsaraClient) _listMetrics(departmentId, ns, metricName, nextToken string, start, end time.Time) ([]MetricData, string, error) {
|
||||
params := make(map[string]string)
|
||||
params["MetricName"] = metricName
|
||||
params["Namespace"] = ns
|
||||
@@ -100,9 +139,7 @@ func (self *SApsaraClient) listMetrics(ns, metricName, nextToken string, start,
|
||||
if len(nextToken) > 0 {
|
||||
params["NextToken"] = nextToken
|
||||
}
|
||||
if len(self.organizationId) > 0 {
|
||||
params["Department"] = self.organizationId
|
||||
}
|
||||
params["Department"] = departmentId
|
||||
params["StartTime"] = fmt.Sprintf("%d", start.UnixMilli())
|
||||
params["EndTime"] = fmt.Sprintf("%d", end.UnixMilli())
|
||||
resp, err := self.metricsRequest("DescribeMetricList", params)
|
||||
|
||||
Reference in New Issue
Block a user