|
31 | 31 |
|
32 | 32 | func runMetricCapture(c *cobra.Command, _ []string) { |
33 | 33 | capture = Metric |
34 | | - go startMetricCollector(c.Context()) |
35 | | - createMetricDisplay() |
| 34 | + |
| 35 | + updateGraphs(false) // initial update of graphs to have something to display |
| 36 | + if isBackground { |
| 37 | + startMetricCollector(c.Context()) |
| 38 | + } else { |
| 39 | + go startMetricCollector(c.Context()) |
| 40 | + createMetricDisplay() |
| 41 | + } |
36 | 42 | } |
37 | 43 |
|
38 | 44 | func startMetricCollector(ctx context.Context) { |
@@ -80,15 +86,24 @@ func startMetricCollector(ctx context.Context) { |
80 | 86 |
|
81 | 87 | func queryGraphs(ctx context.Context, client api.Client) { |
82 | 88 | for index := range graphs { |
83 | | - go queryGraph(ctx, client, index) |
| 89 | + if isBackground { |
| 90 | + queryGraph(ctx, client, index) // keep logical order for background mode |
| 91 | + } else { |
| 92 | + go queryGraph(ctx, client, index) |
| 93 | + } |
84 | 94 | } |
85 | 95 | } |
86 | 96 |
|
87 | 97 | func queryGraph(ctx context.Context, client api.Client, index int) { |
88 | 98 | query, result := queryProm(ctx, client, graphs[index].Query.PromQL) |
89 | | - if errAdvancedDisplay != nil { |
| 99 | + if app == nil || errAdvancedDisplay != nil { |
90 | 100 | // simply print metrics into logs |
91 | | - log.Printf("%v\n", result) |
| 101 | + log.Print(query.PromQL) |
| 102 | + if result == nil || len(*result) == 0 { |
| 103 | + log.Print(" No result") |
| 104 | + } else { |
| 105 | + log.Print(result.String()) |
| 106 | + } |
92 | 107 | } else { |
93 | 108 | appendMetrics(query, result, index) |
94 | 109 | } |
|
0 commit comments