Skip to content

Commit

Permalink
修复谷歌监控无法获取的问题
Browse files Browse the repository at this point in the history
直接返回调用RestAPI的json格式数据
  • Loading branch information
zhaoxiangchun committed May 7, 2020
1 parent 68bcd4f commit d453197
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pkg/multicloud/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func (self *SGoogleClient) monitorList(resource string, params map[string]string
return jsonRequest(self.client, "GET", GOOGLE_MONITOR_DOMAIN, GOOGLE_MONITOR_API_VERSION, resource, params, nil, self.debug)
}

func (self *SGoogleClient) monitorListAll(resource string, params map[string]string, retval interface{}) error {
func (self *SGoogleClient) monitorListAll(resource string, params map[string]string) (*jsonutils.JSONArray, error) {
if params == nil {
params = map[string]string{}
}
Expand All @@ -663,12 +663,12 @@ func (self *SGoogleClient) monitorListAll(resource string, params map[string]str
params["pageToken"] = nextPageToken
resp, err := self.monitorList(resource, params)
if err != nil {
return errors.Wrap(err, "monitorList")
return nil, errors.Wrap(err, "monitorList")
}
if resp.Contains("timeSeries") {
_series, err := resp.GetArray("timeSeries")
if err != nil {
return errors.Wrap(err, "resp.GetArray")
return nil, errors.Wrap(err, "resp.GetTimeSeries")
}
timeSeries.Add(_series...)
}
Expand All @@ -677,7 +677,7 @@ func (self *SGoogleClient) monitorListAll(resource string, params map[string]str
break
}
}
return timeSeries.Unmarshal(retval)
return timeSeries, nil
}

func rawRequest(client *http.Client, method httputils.THttpMethod, domain, apiVersion string, resource string, header http.Header, body io.Reader, debug bool) (*http.Response, error) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/multicloud/google/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import (
"strconv"
"time"

monitoring "cloud.google.com/go/monitoring/apiv3"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"

"yunion.io/x/jsonutils"
)

func (region *SRegion) GetMonitorData(id, serverName, metricName string, since time.Time,
until time.Time) (*monitoring.TimeSeriesIterator, error) {
until time.Time) (*jsonutils.JSONArray, error) {
params := map[string]string{
"filter": `metric.type="` + metricName + `" AND metric.labels.instance_name="` + serverName + `"`,
//"filter": "metric.type=" + metricName + " AND metric.labels.instance_name=" + serverName,
Expand All @@ -33,11 +34,10 @@ func (region *SRegion) GetMonitorData(id, serverName, metricName string, since t
"view": strconv.FormatInt(int64(monitoringpb.ListTimeSeriesRequest_FULL), 10),
}
resource := fmt.Sprintf("%s/%s/%s", "projects", id, "timeSeries")
//client, _ := monitoring.NewMetricClient(context.Background())
rtn := monitoring.TimeSeriesIterator{}
err := region.client.monitorListAll(resource, params, &rtn)

timeSeries, err := region.client.monitorListAll(resource, params)
if err != nil {
return nil, err
}
return &rtn, nil
return timeSeries, nil
}

0 comments on commit d453197

Please sign in to comment.