|
1 | 1 | import { EmbeddedScene, PanelBuilders, SceneFlexItem, SceneFlexLayout, SceneQueryRunner } from "@grafana/scenes"
|
| 2 | +import { LegendDisplayMode } from "@grafana/schema" |
| 3 | + |
| 4 | +function createPodsPanel() { |
| 5 | + return PanelBuilders.timeseries() |
| 6 | + .setTitle('Pods By Status') |
| 7 | + .setData(new SceneQueryRunner({ |
| 8 | + datasource: { |
| 9 | + uid: '$datasource', |
| 10 | + type: 'prometheus', |
| 11 | + }, |
| 12 | + queries: [ |
| 13 | + { |
| 14 | + refId: 'pods', |
| 15 | + expr: `sum( |
| 16 | + kube_pod_status_phase{ |
| 17 | + cluster="$cluster" |
| 18 | + } |
| 19 | + ) by (phase) |
| 20 | + `, |
| 21 | + legendFormat: 'Pods - {{phase}}', |
| 22 | + }, |
| 23 | + ], |
| 24 | + })) |
| 25 | + .setOption('legend', { displayMode: LegendDisplayMode.Table, calcs: ['mean', 'last', 'max'] }) |
| 26 | + .build() |
| 27 | +} |
| 28 | + |
| 29 | +function createPodsByOwnerKindPanel() { |
| 30 | + return PanelBuilders.timeseries() |
| 31 | + .setTitle('Pods By Owner Kind') |
| 32 | + .setData(new SceneQueryRunner({ |
| 33 | + datasource: { |
| 34 | + uid: '$datasource', |
| 35 | + type: 'prometheus', |
| 36 | + }, |
| 37 | + queries: [ |
| 38 | + { |
| 39 | + refId: 'pods', |
| 40 | + expr: `count( |
| 41 | + kube_pod_info{ |
| 42 | + cluster="$cluster" |
| 43 | + } |
| 44 | + ) by (created_by_kind) |
| 45 | + `, |
| 46 | + legendFormat: 'Pods - {{created_by_kind}}', |
| 47 | + }, |
| 48 | + ], |
| 49 | + })) |
| 50 | + .setOption('legend', { displayMode: LegendDisplayMode.Table, calcs: ['mean', 'last', 'max'] }) |
| 51 | + .build() |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +function createDeploymentsPanel() { |
| 56 | + return PanelBuilders.stat() |
| 57 | + .setTitle('Deployments') |
| 58 | + .setData(new SceneQueryRunner({ |
| 59 | + datasource: { |
| 60 | + uid: '$datasource', |
| 61 | + type: 'prometheus', |
| 62 | + }, |
| 63 | + queries: [ |
| 64 | + { |
| 65 | + refId: 'deployments', |
| 66 | + expr: `count( |
| 67 | + kube_deployment_created{ |
| 68 | + cluster="$cluster" |
| 69 | + } |
| 70 | + ) |
| 71 | + `, |
| 72 | + legendFormat: 'Deployments', |
| 73 | + }, |
| 74 | + ], |
| 75 | + })) |
| 76 | + .build() |
| 77 | +} |
| 78 | + |
| 79 | +function createStatefulsetsPanel() { |
| 80 | + return PanelBuilders.stat() |
| 81 | + .setTitle('Statefulsets') |
| 82 | + .setData(new SceneQueryRunner({ |
| 83 | + datasource: { |
| 84 | + uid: '$datasource', |
| 85 | + type: 'prometheus', |
| 86 | + }, |
| 87 | + queries: [ |
| 88 | + { |
| 89 | + refId: 'statefulsets', |
| 90 | + expr: `count( |
| 91 | + kube_statefulset_created{ |
| 92 | + cluster="$cluster" |
| 93 | + } |
| 94 | + ) |
| 95 | + `, |
| 96 | + legendFormat: 'Statefulset', |
| 97 | + }, |
| 98 | + ], |
| 99 | + })) |
| 100 | + .build() |
| 101 | +} |
| 102 | + |
| 103 | +function createDaemonsetsPanel() { |
| 104 | + return PanelBuilders.stat() |
| 105 | + .setTitle('Daemonsets') |
| 106 | + .setData(new SceneQueryRunner({ |
| 107 | + datasource: { |
| 108 | + uid: '$datasource', |
| 109 | + type: 'prometheus', |
| 110 | + }, |
| 111 | + queries: [ |
| 112 | + { |
| 113 | + refId: 'statefulsets', |
| 114 | + expr: `count( |
| 115 | + kube_daemonset_created{ |
| 116 | + cluster="$cluster" |
| 117 | + } |
| 118 | + ) |
| 119 | + `, |
| 120 | + legendFormat: 'Statefulset', |
| 121 | + }, |
| 122 | + ], |
| 123 | + })) |
| 124 | + .build() |
| 125 | +} |
| 126 | + |
| 127 | +function createCronjobsPanel() { |
| 128 | + return PanelBuilders.stat() |
| 129 | + .setTitle('Cronjobs') |
| 130 | + .setData(new SceneQueryRunner({ |
| 131 | + datasource: { |
| 132 | + uid: '$datasource', |
| 133 | + type: 'prometheus', |
| 134 | + }, |
| 135 | + queries: [ |
| 136 | + { |
| 137 | + refId: 'cronjobs', |
| 138 | + expr: `count( |
| 139 | + kube_cronjob_created{ |
| 140 | + cluster="$cluster" |
| 141 | + } |
| 142 | + ) |
| 143 | + `, |
| 144 | + legendFormat: 'Cronjobs', |
| 145 | + }, |
| 146 | + ], |
| 147 | + })) |
| 148 | + .build() |
| 149 | + |
| 150 | +} |
2 | 151 |
|
3 | 152 | export const getOverviewScene = () => {
|
4 | 153 | return new EmbeddedScene({
|
5 | 154 | body: new SceneFlexLayout({
|
| 155 | + direction: 'column', |
6 | 156 | children: [
|
7 |
| - new SceneFlexItem({ |
8 |
| - width: '25%', |
| 157 | + new SceneFlexLayout({ |
| 158 | + direction: 'row', |
9 | 159 | height: 300,
|
10 |
| - body: PanelBuilders.timeseries() |
11 |
| - .setTitle('Nodes') |
12 |
| - .setData(new SceneQueryRunner({ |
13 |
| - datasource: { |
14 |
| - uid: '$datasource', |
15 |
| - type: 'prometheus', |
16 |
| - }, |
17 |
| - queries: [ |
18 |
| - { |
19 |
| - refId: 'nodes', |
20 |
| - expr: 'sum (kube_node_info{cluster="$cluster"})', |
21 |
| - legendFormat: 'Nodes', |
22 |
| - }, |
23 |
| - ], |
24 |
| - })) |
25 |
| - .build(), |
| 160 | + children: [ |
| 161 | + new SceneFlexItem({ |
| 162 | + body: createDeploymentsPanel(), |
| 163 | + }), |
| 164 | + new SceneFlexItem({ |
| 165 | + body: createStatefulsetsPanel(), |
| 166 | + }), |
| 167 | + new SceneFlexItem({ |
| 168 | + body: createDaemonsetsPanel(), |
| 169 | + }), |
| 170 | + new SceneFlexItem({ |
| 171 | + body: createCronjobsPanel(), |
| 172 | + }), |
| 173 | + ] |
| 174 | + }), |
| 175 | + new SceneFlexLayout({ |
| 176 | + direction: 'row', |
| 177 | + height: 400, |
| 178 | + children: [ |
| 179 | + new SceneFlexItem({ |
| 180 | + body: createPodsPanel(), |
| 181 | + }), |
| 182 | + new SceneFlexItem({ |
| 183 | + body: createPodsByOwnerKindPanel(), |
| 184 | + }), |
| 185 | + ] |
26 | 186 | }),
|
27 |
| - new SceneFlexItem({ |
28 |
| - width: '25%', |
29 |
| - height: 300, |
30 |
| - body: PanelBuilders.timeseries() |
31 |
| - .setTitle('Pods') |
32 |
| - .setData(new SceneQueryRunner({ |
33 |
| - datasource: { |
34 |
| - uid: '$datasource', |
35 |
| - type: 'prometheus', |
36 |
| - }, |
37 |
| - queries: [ |
38 |
| - { |
39 |
| - refId: 'pods', |
40 |
| - expr: 'sum (kube_pod_status_phase{cluster="$cluster"}) by (phase)', |
41 |
| - legendFormat: 'Pods - {{phase}}', |
42 |
| - }, |
43 |
| - ], |
44 |
| - })) |
45 |
| - .build(), |
46 |
| - }) |
47 | 187 | ],
|
48 | 188 | }),
|
49 | 189 | })
|
|
0 commit comments