mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
修复谷歌监控无法获取的问题
直接返回调用RestAPI的json格式数据
This commit is contained in:
@@ -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{}
|
||||
}
|
||||
@@ -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...)
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user