@@ -14,8 +14,7 @@ import (
1414
1515const (
1616 // 24h hh:mm:ss: 14:23:20
17- HHMMSS24h = "15:04:05"
18- defaultMetricShowCount = 150
17+ HHMMSS24h = "15:04:05"
1918)
2019
2120type Graph struct {
6463)
6564
6665func createMetricDisplay () {
67- showCount = defaultMetricShowCount
66+ updateShowMetricCount ()
6867 updateGraphs (false )
6968
7069 app = tview .NewApplication ().
@@ -97,12 +96,24 @@ func createMetricDisplay() {
9796func getMetricTop () tview.Primitive {
9897 topView := tview .NewFlex ().SetDirection (tview .FlexRow )
9998 topView .AddItem (getInfoRow (), 1 , 0 , false )
100- topView .AddItem (getCountRow (), 1 , 0 , false )
99+ countRow := getCountRow (false )
100+ // add time range dropdown
101+ countRow .AddItem (tview .NewDropDown ().
102+ SetLabel ("Time range " ).
103+ SetOptions (durations , nil ).
104+ SetCurrentOption (selectedDuration ).
105+ SetSelectedFunc (func (_ string , index int ) {
106+ selectedDuration = index
107+ updateShowMetricCount ()
108+ updateGraphs (true )
109+ }).
110+ SetFieldWidth (5 ), 16 , 0 , false )
111+ topView .AddItem (countRow , 1 , 0 , false )
101112
102113 // panels row containing cycles and custom panels picker
103114 panelsRow := tview .NewFlex ().SetDirection (tview .FlexColumn )
104115
105- // display
116+ // panels
106117 panelsRow .AddItem (panelsTextView , 0 , 1 , false )
107118 if len (selectedPanels ) == 0 {
108119 panelsRow .
@@ -126,9 +137,11 @@ func getMetricTop() tview.Primitive {
126137 }), 10 , 0 , false )
127138 }
128139 panelsRow .AddItem (tview .NewTextView (), 0 , 2 , false )
129- updatePanels (false )
140+ if ! paused {
141+ updatePanels (false )
142+ }
130143
131- // add cycles and custom columns modal button
144+ // add panels modal button
132145 panelsRow .AddItem (tview .NewButton (" Manage panels " ).SetSelectedFunc (func () {
133146 showPopup = true
134147 app .SetRoot (getPages (), true )
@@ -137,6 +150,11 @@ func getMetricTop() tview.Primitive {
137150 return topView
138151}
139152
153+ func updateShowMetricCount () {
154+ showCount = metricCounts [durations [selectedDuration ]]
155+ countTextView .SetText (getShowCountText ())
156+ }
157+
140158func getGraphs () tview.Primitive {
141159 graphsContainer .Clear ()
142160
@@ -318,35 +336,33 @@ func updatePanels(query bool) {
318336}
319337
320338func 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- })
339+ for index := range graphs {
340+ if graphs [index ].Plot != nil {
341+ graphs [index ].Plot .SetXAxisLabelFunc (func (i int ) string {
342+ return graphs [index ].Query .Range .Start .Add (time .Duration (i ) * graphs [index ].Query .Range .Step ).Format (HHMMSS24h )
343+ })
327344
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- }
345+ if len (graphs [index ].Labels ) > 0 {
346+ graphs [index ].Plot .SetFocusFunc (func () {
347+ mainView .AddItem (getLegends (graphs [index ].Query .PromQL , graphs [index ].Labels , graphs [index ].Legends , graphs [index ].Data ), len (graphs [index ].Legends )+ 3 , 0 , false )
348+ })
349+ graphs [index ].Plot .SetBlurFunc (func () {
350+ if legendView != nil {
351+ mainView .RemoveItem (legendView )
352+ }
353+ })
354+ }
338355
339- if graphs [index ].Data != nil {
340- graphs [index ].Plot .SetData (graphs [index ].Data )
341- }
356+ if graphs [index ].Data != nil {
357+ graphs [index ].Plot .SetData (graphs [index ].Data )
342358 }
343359 }
344360 }
345361}
346362
347363func 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 {
364+ // Skip if paused, query / matrix are invalid or when graph array changed in between
365+ if paused || query == nil || matrix == nil || index >= len (graphs ) || graphs [index ].Query .PromQL != query .PromQL {
350366 return
351367 }
352368
0 commit comments