add pvc stats api

Signed-off-by: Xin Wang <wileywang@yunify.com>
This commit is contained in:
Xin Wang
2019-09-02 20:43:50 +08:00
parent 76800b435c
commit 87865f9416
7 changed files with 235 additions and 34 deletions

View File

@@ -198,6 +198,37 @@ func MakePodPromQL(metricName, nsName, nodeID, podName, podFilter string) string
return promql
}
func MakePVCPromQL(metricName, nsName, pvcName, scName, pvcFilter string) string {
if pvcFilter == "" {
pvcFilter = ".*"
}
var promql = ""
if nsName != "" {
// get pvc metrics by namespace
if pvcName != "" {
// specific pvc
promql = RulePromQLTmplMap[metricName]
promql = strings.Replace(promql, "$1", nsName, -1)
promql = strings.Replace(promql, "$2", pvcName, -1)
} else {
// all pvc in a specific namespace
metricName += "_ns"
promql = RulePromQLTmplMap[metricName]
promql = strings.Replace(promql, "$1", nsName, -1)
promql = strings.Replace(promql, "$2", pvcFilter, -1)
}
} else {
if scName != "" {
// all pvc in a specific storageclass
metricName += "_sc"
promql = RulePromQLTmplMap[metricName]
promql = strings.Replace(promql, "$1", scName, -1)
}
}
return promql
}
func MakeNamespacePromQL(nsName string, nsFilter string, metricsName string) string {
var recordingRule = RulePromQLTmplMap[metricsName]