@@ -2,7 +2,15 @@ import { Icon } from '@iconify/react';
2
2
import { Loader } from '@kinvolk/headlamp-plugin/lib/CommonComponents' ;
3
3
import { SectionBox } from '@kinvolk/headlamp-plugin/lib/CommonComponents' ;
4
4
import { useCluster } from '@kinvolk/headlamp-plugin/lib/k8s' ;
5
- import { Box , IconButton , ToggleButton , ToggleButtonGroup , Tooltip } from '@mui/material' ;
5
+ import {
6
+ Box ,
7
+ Button ,
8
+ MenuItem ,
9
+ Paper ,
10
+ Select ,
11
+ ToggleButton ,
12
+ ToggleButtonGroup ,
13
+ } from '@mui/material' ;
6
14
import Alert from '@mui/material/Alert' ;
7
15
import { useEffect , useState } from 'react' ;
8
16
import { getConfigStore , getPrometheusInterval , getPrometheusPrefix } from '../../../util' ;
@@ -82,114 +90,142 @@ export function GenericMetricsChart(props: GenericMetricsChartProps) {
82
90
setChartVariant ( event . currentTarget . value ) ;
83
91
} ;
84
92
93
+ const interval = getPrometheusInterval ( cluster ) ;
94
+
95
+ const [ timespan , setTimespan ] = useState ( interval ?? '1h' ) ;
96
+
85
97
if ( ! isVisible ) {
86
98
return null ;
87
99
}
88
100
89
- const interval = getPrometheusInterval ( cluster ) ;
90
-
91
101
return (
92
102
< SectionBox >
93
- < Box
94
- display = "flex"
95
- justifyContent = "space-around"
96
- alignItems = "center"
97
- style = { { marginBottom : '1rem' , margin : '0 auto' , width : '0' } }
98
- >
99
- { state === prometheusState . INSTALLED
100
- ? [
101
- < ToggleButtonGroup
102
- onChange = { handleChartVariantChange }
103
+ < Paper variant = "outlined" sx = { { p : 1 } } >
104
+ { state === prometheusState . INSTALLED && (
105
+ < Box display = "flex" gap = { 1 } justifyContent = "flex-end" mb = { 2 } >
106
+ < Button
107
+ variant = "outlined"
108
+ size = "small"
109
+ onClick = { ( ) => {
110
+ setRefresh ( refresh => ! refresh ) ;
111
+ } }
112
+ startIcon = { < Icon icon = { refresh ? 'mdi:pause' : 'mdi:play' } /> }
113
+ sx = { { filter : 'grayscale(1.0)' } }
114
+ >
115
+ { refresh ? 'Pause' : 'Resume' }
116
+ </ Button >
117
+ < ToggleButtonGroup
118
+ onChange = { handleChartVariantChange }
119
+ size = "small"
120
+ aria-label = "metric chooser"
121
+ value = { chartVariant }
122
+ exclusive
123
+ >
124
+ < CustomToggleButton label = "CPU" value = "cpu" icon = "mdi:chip" />
125
+ < CustomToggleButton label = "Memory" value = "memory" icon = "mdi:memory" />
126
+ < CustomToggleButton
127
+ label = "Network"
128
+ value = "network"
129
+ icon = "mdi:folder-network-outline"
130
+ />
131
+ < CustomToggleButton label = "Filesystem" value = "filesystem" icon = "mdi:database" />
132
+ </ ToggleButtonGroup >
133
+ < Box >
134
+ < Select
135
+ variant = "outlined"
103
136
size = "small"
104
- aria-label = "metric chooser "
105
- value = { chartVariant }
106
- exclusive
137
+ name = "Time "
138
+ value = { timespan }
139
+ onChange = { e => setTimespan ( e . target . value ) }
107
140
>
108
- < ToggleButton value = "cpu" > CPU</ ToggleButton >
109
- < ToggleButton value = "memory" > Memory</ ToggleButton >
110
- < ToggleButton value = "network" > Network</ ToggleButton >
111
- < ToggleButton value = "filesystem" > Filesystem</ ToggleButton >
112
- </ ToggleButtonGroup > ,
113
- < Box pl = { 2 } >
114
- < IconButton
115
- onClick = { ( ) => {
116
- setRefresh ( refresh => ! refresh ) ;
117
- } }
118
- size = "large"
119
- >
120
- { refresh ? (
121
- < Tooltip title = "Pause metrics" >
122
- { ' ' }
123
- < Icon icon = "mdi:pause" /> { ' ' }
124
- </ Tooltip >
125
- ) : (
126
- < Tooltip title = "Resume metrics" >
127
- { ' ' }
128
- < Icon icon = "mdi:play" /> { ' ' }
129
- </ Tooltip >
130
- ) }
131
- </ IconButton >
132
- </ Box > ,
133
- ]
134
- : [ ] }
135
- </ Box >
136
-
137
- { state === prometheusState . INSTALLED ? (
138
- < Box
139
- style = { {
140
- justifyContent : 'center' ,
141
- display : 'flex' ,
142
- height : '40vh' ,
143
- width : '80%' ,
144
- margin : '0 auto' ,
145
- } }
146
- >
147
- { chartVariant === 'cpu' && (
148
- < CPUChart
149
- query = { props . cpuQuery }
150
- autoRefresh = { refresh }
151
- prometheusPrefix = { prometheusPrefix }
152
- interval = { interval }
153
- />
154
- ) }
155
- { chartVariant === 'memory' && (
156
- < MemoryChart
157
- query = { props . memoryQuery }
158
- autoRefresh = { refresh }
159
- prometheusPrefix = { prometheusPrefix }
160
- interval = { interval }
161
- />
162
- ) }
163
- { chartVariant === 'network' && (
164
- < NetworkChart
165
- rxQuery = { props . networkRxQuery }
166
- txQuery = { props . networkTxQuery }
167
- autoRefresh = { refresh }
168
- interval = { interval }
169
- prometheusPrefix = { prometheusPrefix }
170
- />
171
- ) }
172
- { chartVariant === 'filesystem' && (
173
- < FilesystemChart
174
- readQuery = { props . filesystemReadQuery }
175
- writeQuery = { props . filesystemWriteQuery }
176
- autoRefresh = { refresh }
177
- interval = { interval }
178
- prometheusPrefix = { prometheusPrefix }
179
- />
180
- ) }
181
- </ Box >
182
- ) : state === prometheusState . LOADING ? (
183
- < Box m = { 2 } >
184
- < Loader title = "Loading Prometheus Info" />
185
- </ Box >
186
- ) : state === prometheusState . ERROR ? (
187
- < Box m = { 2 } >
188
- < Alert severity = "warning" > Error fetching prometheus Info</ Alert >
189
- </ Box >
190
- ) : (
191
- < PrometheusNotFoundBanner />
192
- ) }
141
+ < MenuItem value = { '10m' } > 10 minutes</ MenuItem >
142
+ < MenuItem value = { '30m' } > 30 minutes</ MenuItem >
143
+ < MenuItem value = { '1h' } > 1 hour</ MenuItem >
144
+ < MenuItem value = { '3h' } > 3 hours</ MenuItem >
145
+ < MenuItem value = { '6h' } > 6 hours</ MenuItem >
146
+ < MenuItem value = { '12h' } > 12 hours</ MenuItem >
147
+ < MenuItem value = { '24h' } > 24 hours</ MenuItem >
148
+ < MenuItem value = { '48h' } > 48 hours</ MenuItem >
149
+ < MenuItem value = { 'today' } > Today</ MenuItem >
150
+ < MenuItem value = { 'yesterday' } > Yesterday</ MenuItem >
151
+ < MenuItem value = { 'week' } > Week</ MenuItem >
152
+ < MenuItem value = { 'lastweek' } > Last week</ MenuItem >
153
+ < MenuItem value = { '7d' } > 7 days</ MenuItem >
154
+ < MenuItem value = { '14d' } > 14 days</ MenuItem >
155
+ </ Select >
156
+ </ Box >
157
+ </ Box >
158
+ ) }
159
+ { state === prometheusState . INSTALLED ? (
160
+ < Box
161
+ style = { {
162
+ height : '400px' ,
163
+ } }
164
+ >
165
+ { chartVariant === 'cpu' && (
166
+ < CPUChart
167
+ query = { props . cpuQuery }
168
+ autoRefresh = { refresh }
169
+ prometheusPrefix = { prometheusPrefix }
170
+ interval = { timespan }
171
+ />
172
+ ) }
173
+ { chartVariant === 'memory' && (
174
+ < MemoryChart
175
+ query = { props . memoryQuery }
176
+ autoRefresh = { refresh }
177
+ prometheusPrefix = { prometheusPrefix }
178
+ interval = { timespan }
179
+ />
180
+ ) }
181
+ { chartVariant === 'network' && (
182
+ < NetworkChart
183
+ rxQuery = { props . networkRxQuery }
184
+ txQuery = { props . networkTxQuery }
185
+ autoRefresh = { refresh }
186
+ interval = { timespan }
187
+ prometheusPrefix = { prometheusPrefix }
188
+ />
189
+ ) }
190
+ { chartVariant === 'filesystem' && (
191
+ < FilesystemChart
192
+ readQuery = { props . filesystemReadQuery }
193
+ writeQuery = { props . filesystemWriteQuery }
194
+ autoRefresh = { refresh }
195
+ interval = { timespan }
196
+ prometheusPrefix = { prometheusPrefix }
197
+ />
198
+ ) }
199
+ </ Box >
200
+ ) : state === prometheusState . LOADING ? (
201
+ < Box m = { 2 } >
202
+ < Loader title = "Loading Prometheus Info" />
203
+ </ Box >
204
+ ) : state === prometheusState . ERROR ? (
205
+ < Box m = { 2 } >
206
+ < Alert severity = "warning" > Error fetching prometheus Info</ Alert >
207
+ </ Box >
208
+ ) : (
209
+ < PrometheusNotFoundBanner />
210
+ ) }
211
+ </ Paper >
193
212
</ SectionBox >
194
213
) ;
195
214
}
215
+
216
+ function CustomToggleButton ( {
217
+ label,
218
+ icon,
219
+ value,
220
+ } : {
221
+ label : string ;
222
+ icon : string ;
223
+ value : string ;
224
+ } ) {
225
+ return (
226
+ < ToggleButton size = "small" value = { value } sx = { { textTransform : 'none' , gap : 0.5 , fontSize : 14 } } >
227
+ < Icon icon = { icon } width = "18px" />
228
+ { label }
229
+ </ ToggleButton >
230
+ ) ;
231
+ }
0 commit comments