github.com/thanos-io/thanos@v0.32.5/mixin/lib/thanos-grafana-builder/builder.libsonnet (about) 1 local utils = import '../utils.libsonnet'; 2 3 (import 'grafana-builder/grafana.libsonnet') + 4 { 5 collapse: { 6 collapse: true, 7 }, 8 9 panel(title, description=null):: 10 super.panel(title) { [if description != null then 'description']: description }, 11 12 addDashboardLink(name): { 13 links+: [ 14 { 15 dashboard: name, 16 includeVars: true, 17 keepTime: true, 18 title: name, 19 type: 'dashboard', 20 }, 21 ], 22 }, 23 24 spanSize(size):: { 25 span: size, 26 }, 27 28 postfix(postfix):: { 29 postfix: postfix, 30 }, 31 32 sparkline:: { 33 sparkline: { 34 show: true, 35 lineColor: 'rgb(31, 120, 193)', 36 fillColor: 'rgba(31, 118, 189, 0.18)', 37 }, 38 }, 39 40 latencyPanel(metricName, selector, dimensions, multiplier='1'):: { 41 local aggregatedLabels = std.split(dimensions, ','), 42 local dimensionsTemplate = std.join(' ', ['{{%s}}' % std.stripChars(label, ' ') for label in aggregatedLabels]), 43 44 nullPointMode: 'null as zero', 45 targets: [ 46 { 47 expr: 'histogram_quantile(%.2f, sum by (%s) (rate(%s_bucket{%s}[$interval]))) * %s' % [percentile, utils.joinLabels([dimensions, 'le']), metricName, selector, multiplier], 48 format: 'time_series', 49 intervalFactor: 2, 50 legendFormat: 'p%d %s' % [100 * percentile, dimensionsTemplate], 51 logBase: 10, 52 min: null, 53 max: null, 54 step: 10, 55 } 56 for percentile in [0.5, 0.9, 0.99] 57 ], 58 yaxes: $.yaxes('s'), 59 seriesOverrides: [ 60 { 61 alias: 'p99', 62 color: '#FA6400', 63 fill: 1, 64 fillGradient: 1, 65 }, 66 { 67 alias: 'p90', 68 color: '#E0B400', 69 fill: 1, 70 fillGradient: 1, 71 }, 72 { 73 alias: 'p50', 74 color: '#37872D', 75 fill: 10, 76 fillGradient: 0, 77 }, 78 ], 79 }, 80 81 qpsErrTotalPerLabelPanel(selectorErr, selectorTotal, dimensions, perLabel):: { 82 local errExpr = 'sum by (%s, %s) (rate(%s[$interval]))' % [dimensions, perLabel, selectorErr], 83 local totalExpr = 'sum by (%s) (rate(%s[$interval]))' % [dimensions, selectorTotal], 84 85 aliasColors: { 86 'error': '#E24D42', 87 }, 88 targets: [ 89 { 90 expr: '%s / ignoring (%s) group_left() %s' % [errExpr, perLabel, totalExpr], 91 format: 'time_series', 92 intervalFactor: 2, 93 step: 10, 94 }, 95 ], 96 yaxes: $.yaxes({ format: 'percentunit' }), 97 } + $.stack, 98 99 qpsErrTotalPanel(selectorErr, selectorTotal, dimensions):: { 100 local expr(selector) = 'sum by (%s) (rate(%s[$interval]))' % [dimensions, selector], 101 102 aliasColors: { 103 'error': '#E24D42', 104 }, 105 targets: [ 106 { 107 expr: '%s / %s' % [expr(selectorErr), expr(selectorTotal)], 108 format: 'time_series', 109 intervalFactor: 2, 110 legendFormat: 'error', 111 step: 10, 112 }, 113 ], 114 yaxes: $.yaxes({ format: 'percentunit' }), 115 } + $.stack, 116 117 qpsSuccErrRatePanel(selectorErr, selectorTotal, dimensions):: { 118 local expr(selector) = 'sum by (%s) (rate(%s[$interval]))' % [dimensions, selector], 119 120 aliasColors: { 121 success: '#7EB26D', 122 'error': '#E24D42', 123 }, 124 targets: [ 125 { 126 expr: '%s / %s' % [expr(selectorErr), expr(selectorTotal)], 127 format: 'time_series', 128 intervalFactor: 2, 129 legendFormat: 'error', 130 step: 10, 131 }, 132 { 133 expr: '(%s - %s) / %s' % [expr(selectorTotal), expr(selectorErr), expr(selectorTotal)], 134 format: 'time_series', 135 intervalFactor: 2, 136 legendFormat: 'success', 137 step: 10, 138 }, 139 ], 140 yaxes: $.yaxes({ format: 'percentunit', max: 1 }), 141 } + $.stack, 142 143 resourceUtilizationRow(selector, dimensions):: 144 $.row('Resources') 145 .addPanel( 146 $.panel('Memory Used') + 147 $.queryPanel( 148 [ 149 'go_memstats_alloc_bytes{%s}' % selector, 150 'go_memstats_heap_alloc_bytes{%s}' % selector, 151 'rate(go_memstats_alloc_bytes_total{%s}[30s])' % selector, 152 'rate(go_memstats_heap_alloc_bytes{%s}[30s])' % selector, 153 'go_memstats_stack_inuse_bytes{%s}' % selector, 154 'go_memstats_heap_inuse_bytes{%s}' % selector, 155 ], 156 [ 157 'alloc all {{instance}}', 158 'alloc heap {{instance}}', 159 'alloc rate all {{instance}}', 160 'alloc rate heap {{instance}}', 161 'inuse heap {{instance}}', 162 'inuse stack {{instance}}', 163 ] 164 ) + 165 { yaxes: $.yaxes('bytes') }, 166 ) 167 .addPanel( 168 $.panel('Goroutines') + 169 $.queryPanel( 170 'go_goroutines{%s}' % selector, 171 '{{instance}}' 172 ) 173 ) 174 .addPanel( 175 $.panel('GC Time Quantiles') + 176 $.queryPanel( 177 'go_gc_duration_seconds{%s}' % selector, 178 '{{quantile}} {{instance}}' 179 ) 180 ) + 181 $.collapse, 182 } + 183 (import 'grpc.libsonnet') + 184 (import 'http.libsonnet') + 185 (import 'slo.libsonnet')