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