From d29c73c8d04549bfcb88fcfd923d9d77e7d88a0f Mon Sep 17 00:00:00 2001 From: Georgiana Dolocan Date: Fri, 4 Oct 2024 15:29:21 +0300 Subject: [PATCH] Add remaining two panels, hub variable is not working --- grafana-dashboards/cost-attribution.jsonnet | 112 +++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/grafana-dashboards/cost-attribution.jsonnet b/grafana-dashboards/cost-attribution.jsonnet index cdfba98a3f..09d36e780e 100644 --- a/grafana-dashboards/cost-attribution.jsonnet +++ b/grafana-dashboards/cost-attribution.jsonnet @@ -2,6 +2,7 @@ local grafonnet = import 'github.com/grafana/grafonnet/gen/grafonnet-v10.4.0/main.libsonnet'; local dashboard = grafonnet.dashboard; local ts = grafonnet.panel.timeSeries; +local var = grafonnet.dashboard.variable; local totalDailyCosts = ts.new('Total daily costs') @@ -11,7 +12,7 @@ local totalDailyCosts = ||| ) + ts.standardOptions.withMin(20) - + ts.options.withTooltip({ mode: 'multi' }) + + ts.options.withTooltip({ mode: 'single' }) + ts.options.withLegend({ "calcs": [ "count", @@ -86,17 +87,124 @@ local totalDailyCostsPerHub = } ]); +local hubQueryVar = + var.query.new('hub') + + var.query.queryTypes.withLabelValues( + 'Hub', + ) + + var.query.withDatasource( + type= 'yesoreyeram-infinity-datasource', uid='fdsrfvebctptsf' + + ) + + var.query.selectionOptions.withIncludeAll(); + + +local totalDailyCostsPerComponent = + ts.new('Total daily costs per component') + + ts.panelOptions.withDescription( + ||| + Total daily costs per component + ||| + ) + + ts.options.withTooltip({ mode: 'single', sort: "none" }) + + ts.options.withLegend({ + "calcs": [ + "count", + "min", + "mean", + "max", + "sum" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true, + "sortBy": "Min (above zero)", + "sortDesc": true + }) + + ts.fieldConfig.defaults.custom.withLineInterpolation('stepAfter') + + ts.fieldConfig.defaults.custom.withFillOpacity(10) + + ts.fieldConfig.defaults.custom.withStacking("none") + + ts.standardOptions.color.withMode("palette-classic") + + ts.standardOptions.thresholds.withMode("absolute") + + ts.standardOptions.thresholds.withSteps([ + {color: "green", value: null}, + {color: "red", value: 80} + ]) + + ts.standardOptions.withUnit('currencyUSD') + + ts.queryOptions.withTargets([ + { + datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' }, + url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs-per-component?from=${__from:date}&to=${__to:date}", + format: "timeseries", + refId: "A", + columns: [ + {selector: "date", text: "Date", type: "timestamp"}, + {selector: "name", text: "Name", type: "string"}, + {selector: "cost", text: "Cost", type: "number"} + ], + } + ]); + + +local totalDailyCostsPerComponentandHub = + ts.new('Total daily costs per component, for ${hub}') + + ts.panelOptions.withDescription( + ||| + Total daily costs per component, for ${hub} + ||| + ) + + ts.options.withTooltip({ mode: 'single', sort: "none" }) + + ts.options.withLegend({ + "calcs": [ + "count", + "min", + "mean", + "max", + "sum" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true, + "sortBy": "Min (above zero)", + "sortDesc": true + }) + + ts.fieldConfig.defaults.custom.withLineInterpolation('stepAfter') + + ts.fieldConfig.defaults.custom.withFillOpacity(10) + + ts.fieldConfig.defaults.custom.withStacking("none") + + ts.standardOptions.color.withMode("palette-classic") + + ts.standardOptions.thresholds.withMode("absolute") + + ts.standardOptions.thresholds.withSteps([ + {color: "green", value: null}, + {color: "red", value: 80} + ]) + + ts.standardOptions.withUnit('currencyUSD') + + ts.queryOptions.withTargets([ + { + datasource: { type: 'yesoreyeram-infinity-datasource', uid: 'fdsrfvebctptsf' }, + url: "http://aws-ce-grafana-backend.support.svc.cluster.local/total-costs-per-component?from=${__from:date}&to=${__to:date}&hub=${hub}", + format: "timeseries", + refId: "A", + columns: [ + {selector: "date", text: "Date", type: "timestamp"}, + {selector: "name", text: "Name", type: "string"}, + {selector: "cost", text: "Cost", type: "number"} + ], + } + ]); dashboard.new('Cloud cost attribution') + dashboard.withUid('edw06h7udjwg0b') + dashboard.withEditable(true) + dashboard.time.withFrom('now-30d') ++ dashboard.withVariables(hubQueryVar) + dashboard.withPanels( grafonnet.util.grid.makeGrid( [ totalDailyCosts, - totalDailyCostsPerHub + totalDailyCostsPerHub, + totalDailyCostsPerComponent, + totalDailyCostsPerComponentandHub ], panelWidth=24, panelHeight=12,