diff --git a/api/internal/logic/core/clustersloadlogic.go b/api/internal/logic/core/clustersloadlogic.go index bf23008a..8f3ac6c1 100644 --- a/api/internal/logic/core/clustersloadlogic.go +++ b/api/internal/logic/core/clustersloadlogic.go @@ -44,7 +44,7 @@ func (l *ClustersLoadLogic) ClustersLoad(req *types.ClustersLoadReq) (resp *type //resp.Data = remoteResp.Data resp = &types.ClustersLoadResp{} metrics := []string{"cluster_cpu_utilisation", "cluster_cpu_avail", "cluster_cpu_total", "cluster_memory_total", "cluster_memory_avail", "cluster_memory_utilisation", "cluster_memory_utilisation", "cluster_memory_avail", "cluster_memory_total"} - result := l.svcCtx.PromClient.GetNamedMetrics(metrics, time.Now(), tracker.ClusterOption{}) - println(len(result)) + result := l.svcCtx.PromClient.GetNamedMetrics(metrics, time.Now(), tracker.ClusterOption{AdapterId: req.AdapterId, ClusterName: req.ClusterName}) + resp.Data = result return resp, nil } diff --git a/pkg/tracker/promql.go b/pkg/tracker/promql.go index bf2ad8f4..1dc07394 100644 --- a/pkg/tracker/promql.go +++ b/pkg/tracker/promql.go @@ -27,9 +27,15 @@ const ( var promQLTemplates = map[string]string{ - "cluster_cpu_utilisation": "sum by (cluster_name)(cluster_cpu_usage{$1})", - "cluster_memory_utilisation": "sum by (cluster_name)(cluster_memory_usage{$1})", - "cluster_disk_utilisation": "sum by (cluster_name)(cluster_disk_usage{$1})", + "cluster_cpu_utilisation": "cluster_cpu_utilisation{$1}", + "cluster_memory_utilisation": "cluster_memory_utilisation{$1}", + "cluster_disk_utilisation": "cluster_disk_utilisation{$1}", + "cluster_cpu_total": "cluster_cpu_total{$1}", + "cluster_memory_total": "cluster_memory_total{$1}", + "cluster_disk_total": "cluster_disk_total{$1}", + "cluster_cpu_avail": "cluster_cpu_total{$1}", + "cluster_memory_avail": "cluster_memory_total{$1}", + "cluster_disk_avail": "cluster_disk_total{$1}", "center_cpu_utilisation": "(sum by (adapter_id)(cluster_cpu_total{$1})-sum by (adapter_id)(cluster_cpu_avail{$1}))/sum by (adapter_id)(cluster_cpu_total{$1})", "center_memory_utilisation": "(sum by (adapter_id)(cluster_memory_total{$1})-sum by (adapter_id)(cluster_memory_avail{$1}))/sum by (adapter_id)(cluster_memory_total{$1})", "center_disk_utilisation": "(sum by (adapter_id)(cluster_disk_total{$1})-sum by (adapter_id)(cluster_disk_avail{$1}))/sum by (adapter_id)(cluster_disk_total{$1})", @@ -90,8 +96,8 @@ func makeExpr(metric string, opts QueryOptions) string { func makeClusterMetricExpr(tmpl string, o QueryOptions) string { var clusterSelector string - if o.ClusterName != "" { - clusterSelector = fmt.Sprintf(`cluster_name="%s"`, o.ClusterName) + if o.AdapterId != 0 && o.ClusterName != "" { + clusterSelector = fmt.Sprintf(`adapter_id="%d",cluster_name="%s"`, o.AdapterId, o.ClusterName) } return strings.Replace(tmpl, "$1", clusterSelector, -1) diff --git a/pkg/tracker/queryoptions.go b/pkg/tracker/queryoptions.go index dfdf3831..2ec9588f 100644 --- a/pkg/tracker/queryoptions.go +++ b/pkg/tracker/queryoptions.go @@ -101,12 +101,13 @@ func (a AdapterOption) Apply(o *QueryOptions) { } type ClusterOption struct { - AdapterId int + AdapterId int64 ClusterName string } func (c ClusterOption) Apply(o *QueryOptions) { o.Level = LevelCluster + o.AdapterId = c.AdapterId o.ClusterName = c.ClusterName } diff --git a/pkg/tracker/types.go b/pkg/tracker/types.go index ccdc5818..7ecc2196 100644 --- a/pkg/tracker/types.go +++ b/pkg/tracker/types.go @@ -67,14 +67,6 @@ type MetricValue struct { Series []Point `json:"values,omitempty" description:"time series, values of matrix type"` ExportSample *ExportPoint `json:"exported_value,omitempty" description:"exported time series, values of vector type"` ExportedSeries []ExportPoint `json:"exported_values,omitempty" description:"exported time series, values of matrix type"` - - MinValue string `json:"min_value" description:"minimum value from monitor points"` - MaxValue string `json:"max_value" description:"maximum value from monitor points"` - AvgValue string `json:"avg_value" description:"average value from monitor points"` - SumValue string `json:"sum_value" description:"sum value from monitor points"` - Fee string `json:"fee" description:"resource fee"` - ResourceUnit string `json:"resource_unit"` - CurrencyUnit string `json:"currency_unit"` } func (mv *MetricValue) TransferToExportedMetricValue() {