clean old devops code
todo impl use informer Signed-off-by: runzexia <runzexia@yunify.com>
This commit is contained in:
@@ -19,19 +19,15 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/api/monitoring/v1alpha2"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/monitoring"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MonitoringOperator interface {
|
||||
GetMetrics(stmts []string, time time.Time) (v1alpha2.APIResponse, error)
|
||||
GetMetricsOverTime(stmts []string, start, end time.Time, step time.Duration) (v1alpha2.APIResponse, error)
|
||||
GetNamedMetrics(time time.Time, opt monitoring.QueryOption) (v1alpha2.APIResponse, error)
|
||||
GetNamedMetricsOverTime(start, end time.Time, step time.Duration, opt monitoring.QueryOption) (v1alpha2.APIResponse, error)
|
||||
SortMetrics(raw v1alpha2.APIResponse, target, order, identifier string) (v1alpha2.APIResponse, int)
|
||||
PageMetrics(raw v1alpha2.APIResponse, page, limit, rows int) v1alpha2.APIResponse
|
||||
GetMetrics(stmts []string, time time.Time) Metrics
|
||||
GetMetricsOverTime(stmts []string, start, end time.Time, step time.Duration) Metrics
|
||||
GetNamedMetrics(metrics []string, time time.Time, opt monitoring.QueryOption) Metrics
|
||||
GetNamedMetricsOverTime(metrics []string, start, end time.Time, step time.Duration, opt monitoring.QueryOption) Metrics
|
||||
}
|
||||
|
||||
type monitoringOperator struct {
|
||||
@@ -43,27 +39,21 @@ func NewMonitoringOperator(client monitoring.Interface) MonitoringOperator {
|
||||
}
|
||||
|
||||
// TODO(huanggze): reserve for custom monitoring
|
||||
func (mo monitoringOperator) GetMetrics(stmts []string, time time.Time) (v1alpha2.APIResponse, error) {
|
||||
func (mo monitoringOperator) GetMetrics(stmts []string, time time.Time) Metrics {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// TODO(huanggze): reserve for custom monitoring
|
||||
func (mo monitoringOperator) GetMetricsOverTime(stmts []string, start, end time.Time, step time.Duration) (v1alpha2.APIResponse, error) {
|
||||
func (mo monitoringOperator) GetMetricsOverTime(stmts []string, start, end time.Time, step time.Duration) Metrics {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (mo monitoringOperator) GetNamedMetrics(time time.Time, opt monitoring.QueryOption) (v1alpha2.APIResponse, error) {
|
||||
metrics, err := mo.c.GetNamedMetrics(time, opt)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
}
|
||||
return v1alpha2.APIResponse{Results: metrics}, err
|
||||
func (mo monitoringOperator) GetNamedMetrics(metrics []string, time time.Time, opt monitoring.QueryOption) Metrics {
|
||||
ress := mo.c.GetNamedMetrics(metrics, time, opt)
|
||||
return Metrics{Results: ress}
|
||||
}
|
||||
|
||||
func (mo monitoringOperator) GetNamedMetricsOverTime(start, end time.Time, step time.Duration, opt monitoring.QueryOption) (v1alpha2.APIResponse, error) {
|
||||
metrics, err := mo.c.GetNamedMetricsOverTime(start, end, step, opt)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
}
|
||||
return v1alpha2.APIResponse{Results: metrics}, err
|
||||
func (mo monitoringOperator) GetNamedMetricsOverTime(metrics []string, start, end time.Time, step time.Duration, opt monitoring.QueryOption) Metrics {
|
||||
ress := mo.c.GetNamedMetricsOverTime(metrics, start, end, step, opt)
|
||||
return Metrics{Results: ress}
|
||||
}
|
||||
|
||||
223
pkg/models/monitoring/named_metrics.go
Normal file
223
pkg/models/monitoring/named_metrics.go
Normal file
@@ -0,0 +1,223 @@
|
||||
package monitoring
|
||||
|
||||
var ClusterMetrics = []string{
|
||||
"cluster_cpu_utilisation",
|
||||
"cluster_cpu_usage",
|
||||
"cluster_cpu_total",
|
||||
"cluster_memory_utilisation",
|
||||
"cluster_memory_available",
|
||||
"cluster_memory_total",
|
||||
"cluster_memory_usage_wo_cache",
|
||||
"cluster_net_utilisation",
|
||||
"cluster_net_bytes_transmitted",
|
||||
"cluster_net_bytes_received",
|
||||
"cluster_disk_read_iops",
|
||||
"cluster_disk_write_iops",
|
||||
"cluster_disk_read_throughput",
|
||||
"cluster_disk_write_throughput",
|
||||
"cluster_disk_size_usage",
|
||||
"cluster_disk_size_utilisation",
|
||||
"cluster_disk_size_capacity",
|
||||
"cluster_disk_size_available",
|
||||
"cluster_disk_inode_total",
|
||||
"cluster_disk_inode_usage",
|
||||
"cluster_disk_inode_utilisation",
|
||||
"cluster_namespace_count",
|
||||
"cluster_pod_count",
|
||||
"cluster_pod_quota",
|
||||
"cluster_pod_utilisation",
|
||||
"cluster_pod_running_count",
|
||||
"cluster_pod_succeeded_count",
|
||||
"cluster_pod_abnormal_count",
|
||||
"cluster_node_online",
|
||||
"cluster_node_offline",
|
||||
"cluster_node_total",
|
||||
"cluster_cronjob_count",
|
||||
"cluster_pvc_count",
|
||||
"cluster_daemonset_count",
|
||||
"cluster_deployment_count",
|
||||
"cluster_endpoint_count",
|
||||
"cluster_hpa_count",
|
||||
"cluster_job_count",
|
||||
"cluster_statefulset_count",
|
||||
"cluster_replicaset_count",
|
||||
"cluster_service_count",
|
||||
"cluster_secret_count",
|
||||
"cluster_pv_count",
|
||||
"cluster_ingresses_extensions_count",
|
||||
"cluster_load1",
|
||||
"cluster_load5",
|
||||
"cluster_load15",
|
||||
"cluster_pod_abnormal_ratio",
|
||||
"cluster_node_offline_ratio",
|
||||
}
|
||||
|
||||
var NodeMetrics = []string{
|
||||
"node_cpu_utilisation",
|
||||
"node_cpu_total",
|
||||
"node_cpu_usage",
|
||||
"node_memory_utilisation",
|
||||
"node_memory_usage_wo_cache",
|
||||
"node_memory_available",
|
||||
"node_memory_total",
|
||||
"node_net_utilisation",
|
||||
"node_net_bytes_transmitted",
|
||||
"node_net_bytes_received",
|
||||
"node_disk_read_iops",
|
||||
"node_disk_write_iops",
|
||||
"node_disk_read_throughput",
|
||||
"node_disk_write_throughput",
|
||||
"node_disk_size_capacity",
|
||||
"node_disk_size_available",
|
||||
"node_disk_size_usage",
|
||||
"node_disk_size_utilisation",
|
||||
"node_disk_inode_total",
|
||||
"node_disk_inode_usage",
|
||||
"node_disk_inode_utilisation",
|
||||
"node_pod_count",
|
||||
"node_pod_quota",
|
||||
"node_pod_utilisation",
|
||||
"node_pod_running_count",
|
||||
"node_pod_succeeded_count",
|
||||
"node_pod_abnormal_count",
|
||||
"node_load1",
|
||||
"node_load5",
|
||||
"node_load15",
|
||||
"node_pod_abnormal_ratio",
|
||||
}
|
||||
|
||||
var WorkspaceMetrics = []string{
|
||||
"workspace_cpu_usage",
|
||||
"workspace_memory_usage",
|
||||
"workspace_memory_usage_wo_cache",
|
||||
"workspace_net_bytes_transmitted",
|
||||
"workspace_net_bytes_received",
|
||||
"workspace_pod_count",
|
||||
"workspace_pod_running_count",
|
||||
"workspace_pod_succeeded_count",
|
||||
"workspace_pod_abnormal_count",
|
||||
"workspace_ingresses_extensions_count",
|
||||
"workspace_cronjob_count",
|
||||
"workspace_pvc_count",
|
||||
"workspace_daemonset_count",
|
||||
"workspace_deployment_count",
|
||||
"workspace_endpoint_count",
|
||||
"workspace_hpa_count",
|
||||
"workspace_job_count",
|
||||
"workspace_statefulset_count",
|
||||
"workspace_replicaset_count",
|
||||
"workspace_service_count",
|
||||
"workspace_secret_count",
|
||||
"workspace_pod_abnormal_ratio",
|
||||
}
|
||||
|
||||
var NamespaceMetrics = []string{
|
||||
"namespace_cpu_usage",
|
||||
"namespace_memory_usage",
|
||||
"namespace_memory_usage_wo_cache",
|
||||
"namespace_net_bytes_transmitted",
|
||||
"namespace_net_bytes_received",
|
||||
"namespace_pod_count",
|
||||
"namespace_pod_running_count",
|
||||
"namespace_pod_succeeded_count",
|
||||
"namespace_pod_abnormal_count",
|
||||
"namespace_pod_abnormal_ratio",
|
||||
"namespace_memory_limit_hard",
|
||||
"namespace_cpu_limit_hard",
|
||||
"namespace_pod_count_hard",
|
||||
"namespace_cronjob_count",
|
||||
"namespace_pvc_count",
|
||||
"namespace_daemonset_count",
|
||||
"namespace_deployment_count",
|
||||
"namespace_endpoint_count",
|
||||
"namespace_hpa_count",
|
||||
"namespace_job_count",
|
||||
"namespace_statefulset_count",
|
||||
"namespace_replicaset_count",
|
||||
"namespace_service_count",
|
||||
"namespace_secret_count",
|
||||
"namespace_configmap_count",
|
||||
"namespace_ingresses_extensions_count",
|
||||
"namespace_s2ibuilder_count",
|
||||
}
|
||||
|
||||
var WorkloadMetrics = []string{
|
||||
"workload_cpu_usage",
|
||||
"workload_memory_usage",
|
||||
"workload_memory_usage_wo_cache",
|
||||
"workload_net_bytes_transmitted",
|
||||
"workload_net_bytes_received",
|
||||
"workload_deployment_replica",
|
||||
"workload_deployment_replica_available",
|
||||
"workload_statefulset_replica",
|
||||
"workload_statefulset_replica_available",
|
||||
"workload_daemonset_replica",
|
||||
"workload_daemonset_replica_available",
|
||||
"workload_deployment_unavailable_replicas_ratio",
|
||||
"workload_daemonset_unavailable_replicas_ratio",
|
||||
"workload_statefulset_unavailable_replicas_ratio",
|
||||
}
|
||||
|
||||
var PodMetrics = []string{
|
||||
"pod_cpu_usage",
|
||||
"pod_memory_usage",
|
||||
"pod_memory_usage_wo_cache",
|
||||
"pod_net_bytes_transmitted",
|
||||
"pod_net_bytes_received",
|
||||
}
|
||||
|
||||
var ContainerMetrics = []string{
|
||||
"container_cpu_usage",
|
||||
"container_memory_usage",
|
||||
"container_memory_usage_wo_cache",
|
||||
}
|
||||
|
||||
var PVCMetrics = []string{
|
||||
"pvc_inodes_available",
|
||||
"pvc_inodes_used",
|
||||
"pvc_inodes_total",
|
||||
"pvc_inodes_utilisation",
|
||||
"pvc_bytes_available",
|
||||
"pvc_bytes_used",
|
||||
"pvc_bytes_total",
|
||||
"pvc_bytes_utilisation",
|
||||
}
|
||||
|
||||
var EtcdMetrics = []string{
|
||||
"etcd_server_list",
|
||||
"etcd_server_total",
|
||||
"etcd_server_up_total",
|
||||
"etcd_server_has_leader",
|
||||
"etcd_server_leader_changes",
|
||||
"etcd_server_proposals_failed_rate",
|
||||
"etcd_server_proposals_applied_rate",
|
||||
"etcd_server_proposals_committed_rate",
|
||||
"etcd_server_proposals_pending_count",
|
||||
"etcd_mvcc_db_size",
|
||||
"etcd_network_client_grpc_received_bytes",
|
||||
"etcd_network_client_grpc_sent_bytes",
|
||||
"etcd_grpc_call_rate",
|
||||
"etcd_grpc_call_failed_rate",
|
||||
"etcd_grpc_server_msg_received_rate",
|
||||
"etcd_grpc_server_msg_sent_rate",
|
||||
"etcd_disk_wal_fsync_duration",
|
||||
"etcd_disk_wal_fsync_duration_quantile",
|
||||
"etcd_disk_backend_commit_duration",
|
||||
"etcd_disk_backend_commit_duration_quantile",
|
||||
}
|
||||
|
||||
var APIServerMetrics = []string{
|
||||
"apiserver_up_sum",
|
||||
"apiserver_request_rate",
|
||||
"apiserver_request_by_verb_rate",
|
||||
"apiserver_request_latencies",
|
||||
"apiserver_request_by_verb_latencies",
|
||||
}
|
||||
|
||||
var SchedulerMetrics = []string{
|
||||
"scheduler_up_sum",
|
||||
"scheduler_schedule_attempts",
|
||||
"scheduler_schedule_attempt_rate",
|
||||
"scheduler_e2e_scheduling_latency",
|
||||
"scheduler_e2e_scheduling_latency_quantile",
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"kubesphere.io/kubesphere/pkg/api/monitoring/v1alpha2"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/monitoring"
|
||||
"math"
|
||||
"sort"
|
||||
@@ -41,7 +40,7 @@ const (
|
||||
|
||||
type wrapper struct {
|
||||
monitoring.MetricData
|
||||
by func(p, q *monitoring.MetricValue) bool
|
||||
identifier, order string
|
||||
}
|
||||
|
||||
func (w wrapper) Len() int {
|
||||
@@ -49,156 +48,142 @@ func (w wrapper) Len() int {
|
||||
}
|
||||
|
||||
func (w wrapper) Less(i, j int) bool {
|
||||
return w.by(&w.MetricValues[i], &w.MetricValues[j])
|
||||
p := w.MetricValues[i]
|
||||
q := w.MetricValues[j]
|
||||
|
||||
if p.Sample.Value() == q.Sample.Value() {
|
||||
return p.Metadata[w.identifier] < q.Metadata[w.identifier]
|
||||
}
|
||||
|
||||
switch w.order {
|
||||
case OrderAscending:
|
||||
return p.Sample.Value() < q.Sample.Value()
|
||||
default:
|
||||
return p.Sample.Value() > q.Sample.Value()
|
||||
}
|
||||
}
|
||||
|
||||
func (w wrapper) Swap(i, j int) {
|
||||
w.MetricValues[i], w.MetricValues[j] = w.MetricValues[j], w.MetricValues[i]
|
||||
func (id wrapper) Swap(i, j int) {
|
||||
id.MetricValues[i], id.MetricValues[j] = id.MetricValues[j], id.MetricValues[i]
|
||||
}
|
||||
|
||||
// The sortMetrics sorts a group of resources by a given metric
|
||||
// SortMetrics sorts a group of resources by a given metric. Range query doesn't support ranking.
|
||||
// Example:
|
||||
//
|
||||
// before sorting
|
||||
// |------| Metric 1 | Metric 2 | Metric 3 |
|
||||
// | ID a | 1 | XL | |
|
||||
// | ID b | 1 | S | |
|
||||
// | ID c | 3 | M | |
|
||||
// Before sorting:
|
||||
// | ID | Metric 1 | Metric 2 | Metric 3 |
|
||||
// | a | 1 | XL | |
|
||||
// | b | 1 | S | |
|
||||
// | c | 3 | M | |
|
||||
//
|
||||
// sort by metrics_2
|
||||
// |------| Metric 1 | Metric 2 (asc) | Metric 3 |
|
||||
// | ID a | 1 | XL | |
|
||||
// | ID c | 3 | M | |
|
||||
// | ID b | 1 | S | |
|
||||
//
|
||||
// ranking can only be applied to instant query results, not range query
|
||||
func (mo monitoringOperator) SortMetrics(raw v1alpha2.APIResponse, target, order, identifier string) (v1alpha2.APIResponse, int) {
|
||||
if target == "" || len(raw.Results) == 0 {
|
||||
return raw, -1
|
||||
}
|
||||
|
||||
if order == "" {
|
||||
order = OrderDescending
|
||||
}
|
||||
|
||||
var currentResourceMap = make(map[string]int)
|
||||
|
||||
// resource-ordinal map
|
||||
var indexMap = make(map[string]int)
|
||||
i := 0
|
||||
|
||||
for _, item := range raw.Results {
|
||||
if item.MetricType == monitoring.MetricTypeVector && item.Status == monitoring.StatusSuccess {
|
||||
if item.MetricName == target {
|
||||
if order == OrderAscending {
|
||||
sort.Sort(wrapper{item.MetricData, func(p, q *monitoring.MetricValue) bool {
|
||||
if p.Sample[1] == q.Sample[1] {
|
||||
return p.Metadata[identifier] < q.Metadata[identifier]
|
||||
}
|
||||
return p.Sample[1] < q.Sample[1]
|
||||
}})
|
||||
} else {
|
||||
sort.Sort(wrapper{item.MetricData, func(p, q *monitoring.MetricValue) bool {
|
||||
if p.Sample[1] == q.Sample[1] {
|
||||
return p.Metadata[identifier] > q.Metadata[identifier]
|
||||
}
|
||||
return p.Sample[1] > q.Sample[1]
|
||||
}})
|
||||
}
|
||||
|
||||
for _, r := range item.MetricValues {
|
||||
// record the ordinal of resource to indexMap
|
||||
resourceName, exist := r.Metadata[identifier]
|
||||
if exist {
|
||||
if _, exist := indexMap[resourceName]; !exist {
|
||||
indexMap[resourceName] = i
|
||||
i = i + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get total number of rows
|
||||
for _, r := range item.MetricValues {
|
||||
k, ok := r.Metadata[identifier]
|
||||
if ok {
|
||||
currentResourceMap[k] = 1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var keys []string
|
||||
for k := range currentResourceMap {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, resource := range keys {
|
||||
if _, exist := indexMap[resource]; !exist {
|
||||
indexMap[resource] = i
|
||||
i = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
// sort other metrics
|
||||
for i := 0; i < len(raw.Results); i++ {
|
||||
item := raw.Results[i]
|
||||
if item.MetricType == monitoring.MetricTypeVector && item.Status == monitoring.StatusSuccess {
|
||||
sortedMetric := make([]monitoring.MetricValue, len(indexMap))
|
||||
for j := 0; j < len(item.MetricValues); j++ {
|
||||
r := item.MetricValues[j]
|
||||
k, exist := r.Metadata[identifier]
|
||||
if exist {
|
||||
index, exist := indexMap[k]
|
||||
if exist {
|
||||
sortedMetric[index] = r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
raw.Results[i].MetricValues = sortedMetric
|
||||
}
|
||||
}
|
||||
|
||||
return raw, len(indexMap)
|
||||
}
|
||||
|
||||
func (mo monitoringOperator) PageMetrics(raw v1alpha2.APIResponse, page, limit, rows int) v1alpha2.APIResponse {
|
||||
if page <= 0 || limit <= 0 || rows <= 0 || len(raw.Results) == 0 {
|
||||
// After sorting: target=metric_2, order=asc, identifier=id
|
||||
// | ID | Metric 1 | Metric 2 (asc) | Metric 3 |
|
||||
// | a | 1 | XL | |
|
||||
// | c | 3 | M | |
|
||||
// | b | 1 | S | |
|
||||
func (raw *Metrics) Sort(target, order, identifier string) *Metrics {
|
||||
if target == "" || identifier == "" || len(raw.Results) == 0 {
|
||||
return raw
|
||||
}
|
||||
|
||||
// matrix type can not be sorted
|
||||
resourceSet := make(map[string]bool) // resource set records possible values of the identifier
|
||||
resourceOrdinal := make(map[string]int) // resource-ordinal map
|
||||
|
||||
ordinal := 0
|
||||
for _, item := range raw.Results {
|
||||
if item.MetricType != monitoring.MetricTypeVector {
|
||||
return raw
|
||||
if item.MetricType != monitoring.MetricTypeVector || item.Error != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if item.MetricName == target {
|
||||
sort.Sort(wrapper{
|
||||
MetricData: item.MetricData,
|
||||
identifier: identifier,
|
||||
order: order,
|
||||
})
|
||||
|
||||
for _, mv := range item.MetricValues {
|
||||
// Record ordinals in the final result
|
||||
v, ok := mv.Metadata[identifier]
|
||||
if ok && v != "" {
|
||||
resourceOrdinal[v] = ordinal
|
||||
ordinal++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add every unique identifier value to the set
|
||||
for _, mv := range item.MetricValues {
|
||||
v, ok := mv.Metadata[identifier]
|
||||
if ok && v != "" {
|
||||
resourceSet[v] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the i page: [(page-1) * limit, (page) * limit - 1]
|
||||
start := (page - 1) * limit
|
||||
end := (page)*limit - 1
|
||||
var resourceList []string
|
||||
for k := range resourceSet {
|
||||
resourceList = append(resourceList, k)
|
||||
}
|
||||
sort.Strings(resourceList)
|
||||
|
||||
for i := 0; i < len(raw.Results); i++ {
|
||||
if raw.Results[i].MetricType != monitoring.MetricTypeVector || raw.Results[i].Status != monitoring.StatusSuccess {
|
||||
// Fill resource-ordinal map with resources never present in the target, and give them ordinals.
|
||||
for _, r := range resourceList {
|
||||
if _, ok := resourceOrdinal[r]; !ok {
|
||||
resourceOrdinal[r] = ordinal
|
||||
ordinal++
|
||||
}
|
||||
}
|
||||
|
||||
// Sort metrics
|
||||
for i, item := range raw.Results {
|
||||
if item.MetricType != monitoring.MetricTypeVector || item.Error != "" {
|
||||
continue
|
||||
}
|
||||
resultLen := len(raw.Results[i].MetricValues)
|
||||
if start >= resultLen {
|
||||
|
||||
sorted := make([]monitoring.MetricValue, len(resourceList))
|
||||
for _, mv := range item.MetricValues {
|
||||
v, ok := mv.Metadata[identifier]
|
||||
if ok && v != "" {
|
||||
ordinal, _ := resourceOrdinal[v]
|
||||
sorted[ordinal] = mv
|
||||
}
|
||||
}
|
||||
raw.Results[i].MetricValues = sorted
|
||||
}
|
||||
|
||||
raw.CurrentPage = 1
|
||||
raw.TotalPages = 1
|
||||
raw.TotalItems = len(resourceList)
|
||||
return raw
|
||||
}
|
||||
|
||||
func (raw *Metrics) Page(page, limit int) *Metrics {
|
||||
if page < 1 || limit < 1 || len(raw.Results) == 0 {
|
||||
return raw
|
||||
}
|
||||
|
||||
start := (page - 1) * limit
|
||||
end := page * limit
|
||||
|
||||
for i, item := range raw.Results {
|
||||
if item.MetricType != monitoring.MetricTypeVector || item.Error != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
total := len(item.MetricValues)
|
||||
if start >= total {
|
||||
raw.Results[i].MetricValues = nil
|
||||
continue
|
||||
}
|
||||
if end >= resultLen {
|
||||
end = resultLen - 1
|
||||
if end >= total {
|
||||
end = total
|
||||
}
|
||||
slice := raw.Results[i].MetricValues[start : end+1]
|
||||
raw.Results[i].MetricValues = slice
|
||||
|
||||
raw.Results[i].MetricValues = item.MetricValues[start:end]
|
||||
}
|
||||
|
||||
raw.CurrentPage = page
|
||||
raw.TotalPage = int(math.Ceil(float64(rows) / float64(limit)))
|
||||
raw.TotalItem = rows
|
||||
raw.TotalPages = int(math.Ceil(float64(raw.TotalItems) / float64(limit)))
|
||||
return raw
|
||||
}
|
||||
|
||||
91
pkg/models/monitoring/sort_page_test.go
Normal file
91
pkg/models/monitoring/sort_page_test.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/json-iterator/go"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSort(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
target string
|
||||
order string
|
||||
identifier string
|
||||
source string
|
||||
expected string
|
||||
}{
|
||||
{"sort in ascending order", "node_cpu_utilisation", "asc", "node", "source-node-metrics.json", "sorted-node-metrics-asc.json"},
|
||||
{"sort in descending order", "node_memory_utilisation", "desc", "node", "source-node-metrics.json", "sorted-node-metrics-desc.json"},
|
||||
{"sort faulty metrics", "node_memory_utilisation", "desc", "node", "faulty-node-metrics.json", "faulty-node-metrics-sorted.json"},
|
||||
{"sort metrics with an blank node", "node_memory_utilisation", "desc", "node", "blank-node-metrics.json", "blank-node-metrics-sorted.json"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
source, expected, err := jsonFromFile(tt.source, tt.expected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
result := source.Sort(tt.target, tt.order, tt.identifier)
|
||||
if diff := cmp.Diff(*result, *expected); diff != "" {
|
||||
t.Fatalf("%T differ (-got, +want): %s", expected, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPage(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
page int
|
||||
limit int
|
||||
source string
|
||||
expected string
|
||||
}{
|
||||
{"page 0 limit 5", 0, 5, "sorted-node-metrics-asc.json", "sorted-node-metrics-asc.json"},
|
||||
{"page 1 limit 5", 1, 5, "sorted-node-metrics-asc.json", "paged-node-metrics-1.json"},
|
||||
{"page 2 limit 5", 2, 5, "sorted-node-metrics-asc.json", "paged-node-metrics-2.json"},
|
||||
{"page 3 limit 5", 3, 5, "sorted-node-metrics-asc.json", "paged-node-metrics-3.json"},
|
||||
{"page faulty metrics", 1, 2, "faulty-node-metrics-sorted.json", "faulty-node-metrics-paged.json"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
source, expected, err := jsonFromFile(tt.source, tt.expected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
result := source.Page(tt.page, tt.limit)
|
||||
if diff := cmp.Diff(*result, *expected); diff != "" {
|
||||
t.Fatalf("%T differ (-got, +want): %s", expected, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func jsonFromFile(sourceFile, expectedFile string) (*Metrics, *Metrics, error) {
|
||||
sourceJson := &Metrics{}
|
||||
expectedJson := &Metrics{}
|
||||
|
||||
json, err := ioutil.ReadFile(fmt.Sprintf("./testdata/%s", sourceFile))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
err = jsoniter.Unmarshal(json, sourceJson)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
json, err = ioutil.ReadFile(fmt.Sprintf("./testdata/%s", expectedFile))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
err = jsoniter.Unmarshal(json, expectedJson)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return sourceJson, expectedJson, nil
|
||||
}
|
||||
77
pkg/models/monitoring/testdata/blank-node-metrics-sorted.json
vendored
Normal file
77
pkg/models/monitoring/testdata/blank-node-metrics-sorted.json
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"metric_name":"node_disk_size_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.29849334024542695
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_memory_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.23637090535053928
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"page":1,
|
||||
"total_page":1,
|
||||
"total_item":3
|
||||
}
|
||||
92
pkg/models/monitoring/testdata/blank-node-metrics.json
vendored
Normal file
92
pkg/models/monitoring/testdata/blank-node-metrics.json
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"metric_name": "node_disk_size_utilisation",
|
||||
"data": {
|
||||
"resultType": "vector",
|
||||
"result": [
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-2dazc1d6"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": ""
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.2601006025131434
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ezjb7gsk"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.29849334024542695
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-hgcoippu"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name": "node_memory_utilisation",
|
||||
"data": {
|
||||
"resultType": "vector",
|
||||
"result": [
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-2dazc1d6"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": ""
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.1446648505469157
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ezjb7gsk"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.23637090535053928
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-hgcoippu"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
63
pkg/models/monitoring/testdata/faulty-node-metrics-paged.json
vendored
Normal file
63
pkg/models/monitoring/testdata/faulty-node-metrics-paged.json
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"metric_name":"node_cpu_utilisation",
|
||||
"error":"error"
|
||||
},
|
||||
{
|
||||
"metric_name":"node_disk_size_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_memory_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"page":1,
|
||||
"total_page":2,
|
||||
"total_item":4
|
||||
}
|
||||
99
pkg/models/monitoring/testdata/faulty-node-metrics-sorted.json
vendored
Normal file
99
pkg/models/monitoring/testdata/faulty-node-metrics-sorted.json
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"metric_name":"node_cpu_utilisation",
|
||||
"error":"error"
|
||||
},
|
||||
{
|
||||
"metric_name":"node_disk_size_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.29849334024542695
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2601006025131434
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_memory_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.23637090535053928
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.1446648505469157
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"page":1,
|
||||
"total_page":1,
|
||||
"total_item":4
|
||||
}
|
||||
96
pkg/models/monitoring/testdata/faulty-node-metrics.json
vendored
Normal file
96
pkg/models/monitoring/testdata/faulty-node-metrics.json
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"metric_name": "node_cpu_utilisation",
|
||||
"error": "error"
|
||||
},
|
||||
{
|
||||
"metric_name": "node_disk_size_utilisation",
|
||||
"data": {
|
||||
"resultType": "vector",
|
||||
"result": [
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-2dazc1d6"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-9jtsi522"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.2601006025131434
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ezjb7gsk"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.29849334024542695
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-hgcoippu"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name": "node_memory_utilisation",
|
||||
"data": {
|
||||
"resultType": "vector",
|
||||
"result": [
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-2dazc1d6"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-9jtsi522"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.1446648505469157
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ezjb7gsk"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.23637090535053928
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-hgcoippu"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
166
pkg/models/monitoring/testdata/paged-node-metrics-1.json
vendored
Normal file
166
pkg/models/monitoring/testdata/paged-node-metrics-1.json
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"metric_name":"node_cpu_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.021645833333483702
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.03250000000007276
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.05066666666655995
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.05210416666595847
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.06745833333334303
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_disk_size_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.3335848564534758
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2601006025131434
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.21351118996831508
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.35981263055856705
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_memory_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.12824588180084573
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.1446648505469157
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.21291125105270192
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.40309723127991315
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"page":1,
|
||||
"total_page":2,
|
||||
"total_item":8
|
||||
}
|
||||
112
pkg/models/monitoring/testdata/paged-node-metrics-2.json
vendored
Normal file
112
pkg/models/monitoring/testdata/paged-node-metrics-2.json
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"metric_name":"node_cpu_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.07443750000044626
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.07756249999996119
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.18095833333306172
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_disk_size_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.29849334024542695
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.4329682466178235
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_memory_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.23637090535053928
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.823247832787681
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"page":2,
|
||||
"total_page":2,
|
||||
"total_item":8
|
||||
}
|
||||
25
pkg/models/monitoring/testdata/paged-node-metrics-3.json
vendored
Normal file
25
pkg/models/monitoring/testdata/paged-node-metrics-3.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"metric_name":"node_cpu_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_disk_size_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_memory_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector"
|
||||
}
|
||||
}
|
||||
],
|
||||
"page":3,
|
||||
"total_page":2,
|
||||
"total_item":8
|
||||
}
|
||||
247
pkg/models/monitoring/testdata/sorted-node-metrics-asc.json
vendored
Normal file
247
pkg/models/monitoring/testdata/sorted-node-metrics-asc.json
vendored
Normal file
@@ -0,0 +1,247 @@
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"metric_name":"node_cpu_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.021645833333483702
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.03250000000007276
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.05066666666655995
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.05210416666595847
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.06745833333334303
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.07443750000044626
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.07756249999996119
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.18095833333306172
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_disk_size_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.3335848564534758
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2601006025131434
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.21351118996831508
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.35981263055856705
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.29849334024542695
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.4329682466178235
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_memory_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.12824588180084573
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.1446648505469157
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.21291125105270192
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.40309723127991315
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.23637090535053928
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.823247832787681
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"page":1,
|
||||
"total_page":1,
|
||||
"total_item":8
|
||||
}
|
||||
247
pkg/models/monitoring/testdata/sorted-node-metrics-desc.json
vendored
Normal file
247
pkg/models/monitoring/testdata/sorted-node-metrics-desc.json
vendored
Normal file
@@ -0,0 +1,247 @@
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"metric_name":"node_cpu_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.07756249999996119
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.18095833333306172
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.06745833333334303
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.05066666666655995
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.07443750000044626
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.05210416666595847
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.03250000000007276
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.021645833333483702
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_disk_size_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.4329682466178235
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.35981263055856705
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.29849334024542695
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.21351118996831508
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.2601006025131434
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.193,
|
||||
0.3335848564534758
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name":"node_memory_utilisation",
|
||||
"data":{
|
||||
"resultType":"vector",
|
||||
"result":[
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-o13skypq"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.823247832787681
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-2dazc1d6"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-xfcxdn7z"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.40309723127991315
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-hgcoippu"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ezjb7gsk"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.23637090535053928
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-ircdnrao"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.21291125105270192
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-9jtsi522"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.1446648505469157
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric":{
|
||||
"node":"i-tl1i71hr"
|
||||
},
|
||||
"value":[
|
||||
1585658599.195,
|
||||
0.12824588180084573
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"page":1,
|
||||
"total_page":1,
|
||||
"total_item":8
|
||||
}
|
||||
244
pkg/models/monitoring/testdata/source-node-metrics.json
vendored
Normal file
244
pkg/models/monitoring/testdata/source-node-metrics.json
vendored
Normal file
@@ -0,0 +1,244 @@
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"metric_name": "node_cpu_utilisation",
|
||||
"data": {
|
||||
"resultType": "vector",
|
||||
"result": [
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-2dazc1d6"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.18095833333306172
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-9jtsi522"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.03250000000007276
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ezjb7gsk"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.07443750000044626
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-hgcoippu"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.05066666666655995
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ircdnrao"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.05210416666595847
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-o13skypq"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.07756249999996119
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-tl1i71hr"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.021645833333483702
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-xfcxdn7z"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.06745833333334303
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name": "node_disk_size_utilisation",
|
||||
"data": {
|
||||
"resultType": "vector",
|
||||
"result": [
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-2dazc1d6"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.42012898861983516
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-9jtsi522"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.2601006025131434
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ezjb7gsk"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.29849334024542695
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-hgcoippu"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.2588273152865106
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ircdnrao"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.21351118996831508
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-o13skypq"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.4329682466178235
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-tl1i71hr"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.3335848564534758
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-xfcxdn7z"
|
||||
},
|
||||
"value": [
|
||||
1585658599.193,
|
||||
0.35981263055856705
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric_name": "node_memory_utilisation",
|
||||
"data": {
|
||||
"resultType": "vector",
|
||||
"result": [
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-2dazc1d6"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.5286875837861773
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-9jtsi522"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.1446648505469157
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ezjb7gsk"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.23637090535053928
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-hgcoippu"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.2497060264216553
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-ircdnrao"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.21291125105270192
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-o13skypq"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.823247832787681
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-tl1i71hr"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.12824588180084573
|
||||
]
|
||||
},
|
||||
{
|
||||
"metric": {
|
||||
"node": "i-xfcxdn7z"
|
||||
},
|
||||
"value": [
|
||||
1585658599.195,
|
||||
0.40309723127991315
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
10
pkg/models/monitoring/types.go
Normal file
10
pkg/models/monitoring/types.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package monitoring
|
||||
|
||||
import "kubesphere.io/kubesphere/pkg/simple/client/monitoring"
|
||||
|
||||
type Metrics struct {
|
||||
Results []monitoring.Metric `json:"results" description:"actual array of results"`
|
||||
CurrentPage int `json:"page,omitempty" description:"current page returned"`
|
||||
TotalPages int `json:"total_page,omitempty" description:"total number of pages"`
|
||||
TotalItems int `json:"total_item,omitempty" description:"page size"`
|
||||
}
|
||||
Reference in New Issue
Block a user