|
| 1 | +import { Grafana } from './types'; |
| 2 | + |
| 3 | +const percentageFieldConfig = { |
| 4 | + unit: 'percent', |
| 5 | + min: 0, |
| 6 | + max: 100 |
| 7 | +} |
| 8 | + |
| 9 | +export function createStatPercentagePanel( |
| 10 | + title: string, |
| 11 | + position: Grafana.Panel.Position, |
| 12 | + dataSource: string, |
| 13 | + metric: Grafana.Metric |
| 14 | +): Grafana.Panel { |
| 15 | + return { |
| 16 | + title, |
| 17 | + gridPos: position, |
| 18 | + type: 'stat', |
| 19 | + datasource: dataSource, |
| 20 | + targets: [{ |
| 21 | + expr: metric.query, |
| 22 | + legendFormat: metric.label |
| 23 | + }], |
| 24 | + fieldConfig: { |
| 25 | + defaults: { |
| 26 | + ...percentageFieldConfig, |
| 27 | + ...(metric.thresholds ? { |
| 28 | + thresholds: { |
| 29 | + mode: 'absolute', |
| 30 | + steps: metric.thresholds |
| 31 | + } |
| 32 | + } : {}) |
| 33 | + } |
| 34 | + } |
| 35 | + }; |
| 36 | +} |
| 37 | + |
| 38 | +export function createTimeSeriesPercentagePanel( |
| 39 | + title: string, |
| 40 | + position: Grafana.Panel.Position, |
| 41 | + dataSource: string, |
| 42 | + metric: Grafana.Metric |
| 43 | +): Grafana.Panel { |
| 44 | + return createTimeSeriesPanel( |
| 45 | + title, |
| 46 | + position, |
| 47 | + dataSource, |
| 48 | + metric, |
| 49 | + percentageFieldConfig.unit, |
| 50 | + percentageFieldConfig.min, |
| 51 | + percentageFieldConfig.max |
| 52 | + ); |
| 53 | +} |
| 54 | + |
| 55 | +export function createTimeSeriesPanel( |
| 56 | + title: string, |
| 57 | + position: Grafana.Panel.Position, |
| 58 | + dataSource: string, |
| 59 | + metric: Grafana.Metric, |
| 60 | + unit?: string, |
| 61 | + min?: number, |
| 62 | + max?: number |
| 63 | +): Grafana.Panel { |
| 64 | + return { |
| 65 | + title, |
| 66 | + type: 'timeseries', |
| 67 | + datasource: dataSource, |
| 68 | + gridPos: position, |
| 69 | + targets: [{ |
| 70 | + expr: metric.query, |
| 71 | + legendFormat: metric.label |
| 72 | + }], |
| 73 | + fieldConfig: { |
| 74 | + defaults: { |
| 75 | + unit, |
| 76 | + min, |
| 77 | + max, |
| 78 | + ...(metric.thresholds ? { |
| 79 | + thresholds: { |
| 80 | + mode: 'absolute', |
| 81 | + steps: metric.thresholds |
| 82 | + } |
| 83 | + } : {}), |
| 84 | + } |
| 85 | + } |
| 86 | + }; |
| 87 | +} |
| 88 | + |
| 89 | +export function createBurnRatePanel( |
| 90 | + title: string, |
| 91 | + position: Grafana.Panel.Position, |
| 92 | + dataSource: string, |
| 93 | + metric: Grafana.Metric |
| 94 | +): Grafana.Panel { |
| 95 | + return { |
| 96 | + type: 'stat', |
| 97 | + title, |
| 98 | + gridPos: position, |
| 99 | + datasource: dataSource, |
| 100 | + targets: [{ |
| 101 | + expr: metric.query, |
| 102 | + legendFormat: metric.label |
| 103 | + }], |
| 104 | + options: { |
| 105 | + reduceOptions: { |
| 106 | + calcs: ['last'], |
| 107 | + fields: '', |
| 108 | + values: false |
| 109 | + }, |
| 110 | + colorMode: 'value', |
| 111 | + graphMode: 'none', |
| 112 | + textMode: 'value' |
| 113 | + }, |
| 114 | + fieldConfig: { |
| 115 | + defaults: { |
| 116 | + unit: 'none', |
| 117 | + thresholds: { |
| 118 | + mode: 'absolute', |
| 119 | + steps: [ |
| 120 | + { color: 'green', value: null }, |
| 121 | + { color: 'orange', value: 1 }, |
| 122 | + { color: 'red', value: 2 } |
| 123 | + ] |
| 124 | + } |
| 125 | + } |
| 126 | + }, |
| 127 | + } |
| 128 | +} |
0 commit comments