Providing metrics information to Prometheus
Former-commit-id: fb3fc7f706e06eec42a027943c9339f5fef8d697
This commit is contained in:
parent
09c070b483
commit
e03dd1eede
|
@ -40,13 +40,13 @@ type (
|
|||
ClusterName string `json:"clusterName"`
|
||||
CpuAvail float64 `json:"cpuAvail"`
|
||||
CpuTotal float64 `json:"cpuTotal"`
|
||||
CpuUsage float64 `json:"cpuUsage"`
|
||||
CpuUtilisation float64 `json:"cpuUtilisation"`
|
||||
MemoryAvail float64 `json:"memoryAvail"`
|
||||
MemoryUsage float64 `json:"memoryUsage"`
|
||||
MemoryUtilisation float64 `json:"memoryUtilisation"`
|
||||
MemoryTotal float64 `json:"memoryTotal"`
|
||||
DiskAvail float64 `json:"diskAvail"`
|
||||
DiskTotal float64 `json:"diskTotal"`
|
||||
DiskUsage float64 `json:"diskUsage"`
|
||||
DiskUtilisation float64 `json:"diskUtilisation"`
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -46,20 +46,20 @@ func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesRes
|
|||
for _, centerIndex := range centersIndex {
|
||||
// Query the types of resource centers
|
||||
l.svcCtx.DbEngin.Raw("select name,type as CenterType from t_adapter where id = ?", centerIndex.Id).Scan(¢erIndex)
|
||||
cpuRawData, err := l.svcCtx.PromClient.GetRawData("center_cpu_usage", tracker.AdapterOption{AdapterId: centerIndex.Id})
|
||||
cpuRawData, err := l.svcCtx.PromClient.GetRawData("center_cpu_utilisation", tracker.AdapterOption{AdapterId: centerIndex.Id})
|
||||
cpuData := cpuRawData.(model.Vector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
centerIndex.Cpu = cpuData[0].Value.String()
|
||||
memoryRawData, err := l.svcCtx.PromClient.GetRawData("center_memory_usage", tracker.AdapterOption{AdapterId: centerIndex.Id})
|
||||
memoryRawData, err := l.svcCtx.PromClient.GetRawData("center_memory_utilisation", tracker.AdapterOption{AdapterId: centerIndex.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
memoryData := memoryRawData.(model.Vector)
|
||||
|
||||
centerIndex.Memory = memoryData[0].Value.String()
|
||||
diskRawData, err := l.svcCtx.PromClient.GetRawData("center_disk_usage", tracker.AdapterOption{AdapterId: centerIndex.Id})
|
||||
diskRawData, err := l.svcCtx.PromClient.GetRawData("center_disk_utilisation", tracker.AdapterOption{AdapterId: centerIndex.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -27,15 +27,15 @@ func NewSyncClusterLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *S
|
|||
func (l *SyncClusterLoadLogic) SyncClusterLoad(req *types.SyncClusterLoadReq) error {
|
||||
if len(req.ClusterLoadRecords) != 0 {
|
||||
for _, record := range req.ClusterLoadRecords {
|
||||
tracker.ClusterCpuUsageGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.CpuUsage)
|
||||
tracker.ClusterCpuUtilisationGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.CpuUtilisation)
|
||||
tracker.ClusterCpuAvailGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.CpuAvail)
|
||||
tracker.ClusterCpuTotalGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.CpuTotal)
|
||||
|
||||
tracker.ClusterMemoryUsageGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.MemoryUsage)
|
||||
tracker.ClusterMemoryUtilisationGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.MemoryUtilisation)
|
||||
tracker.ClusterMemoryAvailGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.MemoryAvail)
|
||||
tracker.ClusterMemoryTotalGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.MemoryTotal)
|
||||
|
||||
tracker.ClusterDiskUsageGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.DiskUsage)
|
||||
tracker.ClusterDiskUtilisationGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.DiskUtilisation)
|
||||
tracker.ClusterDiskAvailGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.DiskAvail)
|
||||
tracker.ClusterDiskTotalGauge.WithLabelValues(record.ClusterName, strconv.FormatInt(record.AdapterId, 10)).Set(record.DiskTotal)
|
||||
}
|
||||
|
|
|
@ -34,13 +34,13 @@ type ClusterLoadRecord struct {
|
|||
ClusterName string `json:"clusterName"`
|
||||
CpuAvail float64 `json:"cpuAvail"`
|
||||
CpuTotal float64 `json:"cpuTotal"`
|
||||
CpuUsage float64 `json:"cpuUsage"`
|
||||
CpuUtilisation float64 `json:"cpuUtilisation"`
|
||||
MemoryAvail float64 `json:"memoryAvail"`
|
||||
MemoryUsage float64 `json:"memoryUsage"`
|
||||
MemoryUtilisation float64 `json:"memoryUtilisation"`
|
||||
MemoryTotal float64 `json:"memoryTotal"`
|
||||
DiskAvail float64 `json:"diskAvail"`
|
||||
DiskTotal float64 `json:"diskTotal"`
|
||||
DiskUsage float64 `json:"diskUsage"`
|
||||
DiskUtilisation float64 `json:"diskUtilisation"`
|
||||
}
|
||||
|
||||
type GetClusterListReq struct {
|
||||
|
|
|
@ -27,12 +27,12 @@ const (
|
|||
|
||||
var promQLTemplates = map[string]string{
|
||||
|
||||
"cluster_cpu_usage": "sum by (cluster_name)(cluster_cpu_usage{$1})",
|
||||
"cluster_memory_usage": "sum by (cluster_name)(cluster_memory_usage{$1})",
|
||||
"cluster_disk_usage": "sum by (cluster_name)(cluster_disk_usage{$1})",
|
||||
"center_cpu_usage": "(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_usage": "(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_usage": "(sum by (adapter_id)(cluster_disk_total{$1})-sum by (adapter_id)(cluster_disk_avail{$1}))/sum by (adapter_id)(cluster_disk_total{$1})",
|
||||
"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})",
|
||||
"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})",
|
||||
"center_top3": "topk(3,((sum by (adapter_id)(cluster_cpu_total)-sum by (adapter_id)(cluster_cpu_avail))/sum by (adapter_id)(cluster_cpu_total) + (sum by (adapter_id)(cluster_memory_total) - sum by (adapter_id)(cluster_memory_avail))/sum by (adapter_id)(cluster_memory_total) + (sum by (adapter_id)(cluster_disk_total)-sum by (adapter_id)(cluster_disk_avail))/sum by (adapter_id)(cluster_disk_total))/3)",
|
||||
"namespace_cpu_usage": `round(namespace:container_cpu_usage_seconds_total:sum_rate{namespace!="", $1}, 0.001)`,
|
||||
"namespace_memory_usage": `namespace:container_memory_usage_bytes:sum{namespace!="", $1}`,
|
||||
|
|
|
@ -27,9 +27,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
ClusterCpuUsageGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_cpu_usage",
|
||||
Help: "Cluster CPU Utilization Rate.",
|
||||
ClusterCpuUtilisationGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_cpu_utilisation",
|
||||
Help: "Cluster CPU Utilisation Rate.",
|
||||
}, []string{"cluster_name", "adapter_id"})
|
||||
ClusterCpuAvailGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_cpu_avail",
|
||||
|
@ -39,9 +39,9 @@ var (
|
|||
Name: "cluster_cpu_total",
|
||||
Help: "Cluster CPU Total.",
|
||||
}, []string{"cluster_name", "adapter_id"})
|
||||
ClusterMemoryUsageGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_memory_usage",
|
||||
Help: "Cluster Memory Utilization Rate.",
|
||||
ClusterMemoryUtilisationGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_memory_utilisation",
|
||||
Help: "Cluster Memory Utilisation Rate.",
|
||||
}, []string{"cluster_name", "adapter_id"})
|
||||
ClusterMemoryAvailGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_memory_avail",
|
||||
|
@ -51,9 +51,9 @@ var (
|
|||
Name: "cluster_memory_total",
|
||||
Help: "Cluster Memory Total.",
|
||||
}, []string{"cluster_name", "adapter_id"})
|
||||
ClusterDiskUsageGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_disk_usage",
|
||||
Help: "Cluster Disk Utilization Rate.",
|
||||
ClusterDiskUtilisationGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_disk_utilisation",
|
||||
Help: "Cluster Disk Utilisation Rate.",
|
||||
}, []string{"cluster_name", "adapter_id"})
|
||||
ClusterDiskAvailGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "cluster_disk_avail",
|
||||
|
@ -65,13 +65,13 @@ var (
|
|||
}, []string{"cluster_name", "adapter_id"})
|
||||
|
||||
metrics = []prometheus.Collector{
|
||||
ClusterCpuUsageGauge,
|
||||
ClusterCpuUtilisationGauge,
|
||||
ClusterCpuAvailGauge,
|
||||
ClusterCpuTotalGauge,
|
||||
ClusterMemoryUsageGauge,
|
||||
ClusterMemoryUtilisationGauge,
|
||||
ClusterMemoryAvailGauge,
|
||||
ClusterMemoryTotalGauge,
|
||||
ClusterDiskUsageGauge,
|
||||
ClusterDiskUtilisationGauge,
|
||||
ClusterDiskAvailGauge,
|
||||
ClusterDiskTotalGauge,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue