@@ -14,8 +14,7 @@ import (
14
14
15
15
const (
16
16
// 24h hh:mm:ss: 14:23:20
17
- HHMMSS24h = "15:04:05"
18
- defaultMetricShowCount = 150
17
+ HHMMSS24h = "15:04:05"
19
18
)
20
19
21
20
type Graph struct {
@@ -28,9 +27,10 @@ type Graph struct {
28
27
}
29
28
30
29
var (
31
- legendView * tview.Flex
32
- graphsContainer = tview .NewFlex ().SetDirection (tview .FlexRow )
33
- panelsTextView = tview .NewTextView ()
30
+ legendView * tview.Flex
31
+ timeRangeDropdown = tview .NewDropDown ()
32
+ graphsContainer = tview .NewFlex ().SetDirection (tview .FlexRow )
33
+ panelsTextView = tview .NewTextView ()
34
34
35
35
selectedPanels = []string {}
36
36
graphs = []Graph {}
64
64
)
65
65
66
66
func createMetricDisplay () {
67
- showCount = defaultMetricShowCount
67
+ updateShowMetricCount ()
68
68
updateGraphs (false )
69
69
70
70
app = tview .NewApplication ().
@@ -97,12 +97,24 @@ func createMetricDisplay() {
97
97
func getMetricTop () tview.Primitive {
98
98
topView := tview .NewFlex ().SetDirection (tview .FlexRow )
99
99
topView .AddItem (getInfoRow (), 1 , 0 , false )
100
- topView .AddItem (getCountRow (), 1 , 0 , false )
100
+ countRow := getCountRow (false )
101
+ // add time range dropdown
102
+ countRow .AddItem (tview .NewDropDown ().
103
+ SetLabel ("Time range " ).
104
+ SetOptions (durations , nil ).
105
+ SetCurrentOption (selectedDuration ).
106
+ SetSelectedFunc (func (_ string , index int ) {
107
+ selectedDuration = index
108
+ updateShowMetricCount ()
109
+ updateGraphs (true )
110
+ }).
111
+ SetFieldWidth (5 ), 16 , 0 , false )
112
+ topView .AddItem (countRow , 1 , 0 , false )
101
113
102
114
// panels row containing cycles and custom panels picker
103
115
panelsRow := tview .NewFlex ().SetDirection (tview .FlexColumn )
104
116
105
- // display
117
+ // panels
106
118
panelsRow .AddItem (panelsTextView , 0 , 1 , false )
107
119
if len (selectedPanels ) == 0 {
108
120
panelsRow .
@@ -126,17 +138,24 @@ func getMetricTop() tview.Primitive {
126
138
}), 10 , 0 , false )
127
139
}
128
140
panelsRow .AddItem (tview .NewTextView (), 0 , 2 , false )
129
- updatePanels (false )
141
+ if ! paused {
142
+ updatePanels (false )
143
+ }
130
144
131
- // add cycles and custom columns modal button
145
+ // add panels modal button
132
146
panelsRow .AddItem (tview .NewButton (" Manage panels " ).SetSelectedFunc (func () {
133
- showPopup = true
147
+ popup = PopupPanels
134
148
app .SetRoot (getPages (), true )
135
149
}), 16 , 0 , false )
136
150
topView .AddItem (panelsRow , 1 , 0 , false )
137
151
return topView
138
152
}
139
153
154
+ func updateShowMetricCount () {
155
+ showCount = metricCounts [durations [selectedDuration ]]
156
+ countTextView .SetText (getShowCountText ())
157
+ }
158
+
140
159
func getGraphs () tview.Primitive {
141
160
graphsContainer .Clear ()
142
161
@@ -318,35 +337,33 @@ func updatePanels(query bool) {
318
337
}
319
338
320
339
func updatePlots () {
321
- if ! paused {
322
- for index := range graphs {
323
- if graphs [index ].Plot != nil {
324
- graphs [index ].Plot .SetXAxisLabelFunc (func (i int ) string {
325
- return graphs [index ].Query .Range .Start .Add (time .Duration (i ) * graphs [index ].Query .Range .Step ).Format (HHMMSS24h )
326
- })
340
+ for index := range graphs {
341
+ if graphs [index ].Plot != nil {
342
+ graphs [index ].Plot .SetXAxisLabelFunc (func (i int ) string {
343
+ return graphs [index ].Query .Range .Start .Add (time .Duration (i ) * graphs [index ].Query .Range .Step ).Format (HHMMSS24h )
344
+ })
327
345
328
- if len (graphs [index ].Labels ) > 0 {
329
- graphs [index ].Plot .SetFocusFunc (func () {
330
- mainView .AddItem (getLegends (graphs [index ].Query .PromQL , graphs [index ].Labels , graphs [index ].Legends , graphs [index ].Data ), len (graphs [index ].Legends )+ 3 , 0 , false )
331
- })
332
- graphs [index ].Plot .SetBlurFunc (func () {
333
- if legendView != nil {
334
- mainView .RemoveItem (legendView )
335
- }
336
- })
337
- }
346
+ if len (graphs [index ].Labels ) > 0 {
347
+ graphs [index ].Plot .SetFocusFunc (func () {
348
+ mainView .AddItem (getLegends (graphs [index ].Query .PromQL , graphs [index ].Labels , graphs [index ].Legends , graphs [index ].Data ), len (graphs [index ].Legends )+ 3 , 0 , false )
349
+ })
350
+ graphs [index ].Plot .SetBlurFunc (func () {
351
+ if legendView != nil {
352
+ mainView .RemoveItem (legendView )
353
+ }
354
+ })
355
+ }
338
356
339
- if graphs [index ].Data != nil {
340
- graphs [index ].Plot .SetData (graphs [index ].Data )
341
- }
357
+ if graphs [index ].Data != nil {
358
+ graphs [index ].Plot .SetData (graphs [index ].Data )
342
359
}
343
360
}
344
361
}
345
362
}
346
363
347
364
func appendMetrics (query * Query , matrix * Matrix , index int ) {
348
- // Skip if query / matrix are invalid or when graph array changed in between
349
- if query == nil || matrix == nil || index >= len (graphs ) || graphs [index ].Query .PromQL != query .PromQL {
365
+ // Skip if paused, query / matrix are invalid or when graph array changed in between
366
+ if paused || query == nil || matrix == nil || index >= len (graphs ) || graphs [index ].Query .PromQL != query .PromQL {
350
367
return
351
368
}
352
369
0 commit comments