Merge pull request #533 from huanggze/monitor-fix-2

refine monitoring apis
This commit is contained in:
Benjamin Huo
2019-07-02 00:15:51 +08:00
committed by GitHub
8 changed files with 253 additions and 226 deletions

View File

@@ -49,6 +49,9 @@ const (
type FormatedLevelMetric struct {
MetricsLevel string `json:"metrics_level" description:"metric level, eg. cluster"`
Results []FormatedMetric `json:"results" description:"actual array of results"`
CurrentPage int `json:"page,omitempty" description:"current page returned"`
TotalPage int `json:"total_page,omitempty" description:"total number of pages"`
TotalItem int `json:"total_item,omitempty" description:"page size"`
}
type FormatedMetric struct {
@@ -58,7 +61,7 @@ type FormatedMetric struct {
}
type FormatedMetricData struct {
Result []map[string]interface{} `json:"result" description:"result including metric labels, time points and values"`
Result []map[string]interface{} `json:"result" description:"metric data including metric metadata, time points and values"`
ResultType string `json:"resultType" description:"result type, one of matrix, vector"`
}

View File

@@ -27,12 +27,16 @@ func MakeWorkloadPromQL(metricName, nsName, resources_filter, wkKind string) str
wkKind = DaemonSet
case "statefulset":
wkKind = StatefulSet
default:
wkKind = "(.*)"
}
if resources_filter == "" {
resources_filter = ".*"
if wkKind == "" {
resources_filter = Any
} else if resources_filter == "" {
if strings.Contains(metricName, "pod") {
resources_filter = wkKind + ":" + Any
} else if strings.Contains(metricName, strings.ToLower(wkKind)) {
resources_filter = Any
}
} else {
var prefix string

View File

@@ -76,6 +76,7 @@ const (
StatefulSet = "StatefulSet"
DaemonSet = "DaemonSet"
Deployment = "Deployment"
Any = ".*"
)
const (
@@ -598,6 +599,10 @@ var RulePromQLTmplMap = MetricMap{
// workload
// Join the "container_cpu_usage_seconds_total" metric with "kube_pod_owner" to calculate workload-level resource usage
//
// Note the name convention:
// For hardware resource metrics, combine pod metric name with `workload_`
// For k8s resource metrics, must specify the workload type in metric names
"workload_pod_cpu_usage": `round(namespace:workload_cpu_usage:sum{namespace="$2", workload=~"$3"}, 0.001)`,
"workload_pod_memory_usage": `namespace:workload_memory_usage:sum{namespace="$2", workload=~"$3"}`,
"workload_pod_memory_usage_wo_cache": `namespace:workload_memory_usage_wo_cache:sum{namespace="$2", workload=~"$3"}`,

View File

@@ -239,19 +239,11 @@ func Page(pageNum string, limitNum string, fmtLevelMetric *FormatedLevelMetric,
allPage := int(math.Ceil(float64(maxLength) / float64(limit)))
// add page fields
return &struct {
*FormatedLevelMetric
CurrentPage int `json:"page"`
TotalPage int `json:"total_page"`
TotalItem int `json:"total_item"`
Message string `json:"msg"`
}{
FormatedLevelMetric: fmtLevelMetric,
CurrentPage: page,
TotalItem: maxLength,
TotalPage: allPage,
Message: "paged",
}
fmtLevelMetric.CurrentPage = page
fmtLevelMetric.TotalItem = maxLength
fmtLevelMetric.TotalPage = allPage
return fmtLevelMetric
}
// maybe this function is time consuming