Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: usage of predict_linear function in volume dashboard #2763

Merged
merged 12 commits into from
Apr 25, 2024
Merged
4 changes: 2 additions & 2 deletions cmd/tools/grafana/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,11 @@ func checkTopKRange(t *testing.T, path string, data []byte) {
expressions := make([]exprP, 0)

VisitAllPanels(data, func(_ string, key, value gjson.Result) {
doTarget("", key, value, func(path string, expr string, format string) {
doTarget("", key, value, func(path string, expr string, format string, title string) {
if format == "table" || format == "stat" {
return
}
expressions = append(expressions, newExpr(path, expr))
expressions = append(expressions, newExpr(path, expr, title))
})
})

Expand Down
29 changes: 16 additions & 13 deletions cmd/tools/grafana/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ func doMetrics(_ *cobra.Command, _ []string) {
}

type exprP struct {
path string
expr string
vars []string
path string
expr string
vars []string
panelTitle string
}

func visitExpressionsAndQueries(path string, data []byte) {
// collect all expressions
expressions := make([]exprP, 0)
gjson.GetBytes(data, "panels").ForEach(func(key, value gjson.Result) bool {
doTarget("", key, value, func(path string, expr string, _ string) {
expressions = append(expressions, newExpr(path, expr))
doTarget("", key, value, func(path string, expr string, _ string, title string) {
expressions = append(expressions, newExpr(path, expr, title))
})
value.Get("panels").ForEach(func(key2, value2 gjson.Result) bool {
pathPrefix := fmt.Sprintf("panels[%d].", key.Int())
doTarget(pathPrefix, key2, value2, func(path string, expr string, _ string) {
expressions = append(expressions, newExpr(path, expr))
doTarget(pathPrefix, key2, value2, func(path string, expr string, _ string, title string) {
expressions = append(expressions, newExpr(path, expr, title))
})
return true
})
Expand Down Expand Up @@ -127,22 +128,24 @@ func allVariables(data []byte) map[string]variable {
return variables
}

func newExpr(path string, expr string) exprP {
func newExpr(path string, expr string, title string) exprP {
allMatches := varRe.FindAllStringSubmatch(expr, -1)
vars := make([]string, 0, len(allMatches))
for _, match := range allMatches {
vars = append(vars, match[1])
}
return exprP{
path: path,
expr: expr,
vars: vars,
path: path,
expr: expr,
vars: vars,
panelTitle: title,
}
}

func doTarget(pathPrefix string, key gjson.Result, value gjson.Result,
exprFunc func(path string, expr string, format string)) {
exprFunc func(path string, expr string, format string, title string)) {
kind := value.Get("type").String()
title := value.Get("title").String()
if kind == "row" {
return
}
Expand All @@ -151,7 +154,7 @@ func doTarget(pathPrefix string, key gjson.Result, value gjson.Result,
for i, targetN := range targetsSlice {
expr := targetN.Get("expr").String()
pathWithTarget := path + ".targets[" + strconv.Itoa(i) + "]"
exprFunc(pathWithTarget, expr, kind)
exprFunc(pathWithTarget, expr, kind, title)
}
}

Expand Down
296 changes: 296 additions & 0 deletions grafana/dashboards/cmode/volume.json
Original file line number Diff line number Diff line change
Expand Up @@ -7561,6 +7561,302 @@
],
"title": "Volume Growth Rate",
"type": "row"
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need Datacenter column in table.
Cluster should be a column after datacenter (at start) in table.
Default sorting should be on predicted value.
Is gradient bar percentage display better than text percentage value?
Node can be removed from table.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Datacenter column added
  • Cluster column moved to 2nd
  • Node column removed
  • % changed to gradient
  • Default sort desc for predicted value.
image

"collapsed": true,
"datasource": "${DS_PROMETHEUS}",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 25
},
"id": 136,
"panels": [
{
"datasource": "${DS_PROMETHEUS}",
"description": "This table would show 15 day predicted value of size used percentage for top volumes.",
"fieldConfig": {
"defaults": {
"custom": {
"align": "left",
"cellOptions": {
"type": "auto"
},
"filterable": true,
"inspect": false
},
"decimals": 2,
"mappings": [
{
"options": {
"from": 100,
"result": {
"index": 0,
"text": "100%"
},
"to": 999999
},
"type": "range"
},
{
"options": {
"from": -9999999,
"result": {
"index": 1,
"text": "0%"
},
"to": 0
},
"type": "range"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "rgb(31, 176, 196)",
"value": null
}
]
},
"unit": "percent",
"unitScale": true
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "Current Value"
},
"properties": [
{
"id": "custom.width",
"value": 170
},
{
"id": "custom.displayMode",
"value": "gradient-gauge"
}
]
},
{
"matcher": {
"id": "byName",
"options": "SVM"
},
"properties": [
{
"id": "custom.width",
"value": 260
}
]
},
{
"matcher": {
"id": "byName",
"options": "Volume"
},
"properties": [
{
"id": "custom.width",
"value": 330
}
]
},
{
"matcher": {
"id": "byName",
"options": "Cluster"
},
"properties": [
{
"id": "custom.width",
"value": 280
}
]
},
{
"matcher": {
"id": "byName",
"options": "Node"
},
"properties": [
{
"id": "custom.width",
"value": 260
}
]
},
{
"matcher": {
"id": "byName",
"options": "Aggr"
},
"properties": [
{
"id": "custom.width",
"value": 260
}
]
},
{
"matcher": {
"id": "byName",
"options": "Predicted 15th Day Value"
},
"properties": [
{
"id": "custom.width",
"value": 220
},
{
"id": "custom.displayMode",
"value": "gradient-gauge"
}
]
},
{
"matcher": {
"id": "byName",
"options": "Datacenter"
},
"properties": [
{
"id": "custom.width",
"value": 190
}
]
}
]
},
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 12
},
"id": 149,
"interval": "1m",
"maxDataPoints": 2,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"show": false
},
"showHeader": true,
"sortBy": [
{
"desc": true,
"displayName": "Predicted 15th Day Value"
}
]
},
"pluginVersion": "10.3.1",
"targets": [
{
"datasource": "${DS_PROMETHEUS}",
"editorMode": "code",
"expr": "predict_linear(volume_size_used_percent{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",svm=~\"$SVM\",volume=~\"$Volume\"}[3d], 15*24*3600) and topk($TopResources, avg_over_time(volume_size_used_percent{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",svm=~\"$SVM\",volume=~\"$Volume\"}[3h] @ end()))",
"format": "table",
"hide": false,
"instant": true,
"interval": "",
"intervalFactor": 1,
"legendFormat": "",
"refId": "A"
},
{
"datasource": "${DS_PROMETHEUS}",
"editorMode": "code",
"exemplar": false,
"expr": "volume_size_used_percent{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",svm=~\"$SVM\",volume=~\"$Volume\"} and topk($TopResources, avg_over_time(volume_size_used_percent{datacenter=~\"$Datacenter\",cluster=~\"$Cluster\",svm=~\"$SVM\",volume=~\"$Volume\"}[3h] @ end()))",
"format": "table",
"hide": false,
"instant": true,
"legendFormat": "",
"range": false,
"refId": "B"
}
],
"title": "Top $TopResources Volumes Per Size Used Percentage Trend",
"transformations": [
{
"id": "merge",
"options": {}
},
{
"id": "organize",
"options": {
"excludeByName": {
"Time": true,
"Value": false,
"Value #C": false,
"__name__": true,
"datacenter": false,
"instance": true,
"job": true,
"node": true,
"state": true,
"style": true
},
"includeByName": {},
"indexByName": {
"Time": 5,
"Value #A": 10,
"Value #B": 9,
"__name__": 11,
"aggr": 4,
"cluster": 1,
"datacenter": 0,
"instance": 6,
"job": 7,
"style": 8,
"svm": 3,
"volume": 2
},
"renameByName": {
"Value": "Predicted Value ",
"Value #A": "Predicted 15th Day Value",
"Value #B": "Current Value",
"Value #C": "Size",
"Value #D": "",
"Value #E": "Dedupe Space Saved",
"Value #F": "Compression Space Saved",
"Value #G": "Total Space Saved",
"Value #H": "Logical Space Used",
"Value #I": "Physical Space Used",
"Value #J": "Clone Split Estimate",
"__name__": "",
"aggr": "Aggr",
"clone_parent_snapshot": "Clone Parent Snapshot",
"clone_parent_svm": "Clone Parent SVM",
"clone_parent_volume": "Clone Parent Volume",
"cluster": "Cluster",
"datacenter": "Datacenter",
"junction_path": "Junction Path",
"svm": "SVM",
"volume": "Volume"
}
}
}
],
"type": "table"
}
],
"targets": [
{
"datasource": "${DS_PROMETHEUS}",
"refId": "A"
}
],
"title": "Forecast Volume Capacity",
"type": "row"
}
],
"refresh": "",
Expand Down
Loading