prometheus metrics

Former-commit-id: 190a78c2e71b57402732c72448d9ffd174d3ac1f
This commit is contained in:
zhangwei 2024-03-27 14:35:52 +08:00
parent 1f61eb7e12
commit 8b43bbcbd4
4 changed files with 15 additions and 16 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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
}

View File

@ -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() {