Skip to content

Commit

Permalink
Tweak Aggregate. Fix obscure crash under window size
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencegripper committed Sep 6, 2019
1 parent 0756ae0 commit 05927b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions internal/pkg/handlers/metrics.go
Expand Up @@ -127,7 +127,7 @@ func expandMetricDefinition(ctx context.Context, currentItem *TreeNode) Expander
Display: metric.Name.Value + "\n " + style.Subtle("Unit: "+metric.Unit),
ID: currentItem.ID,
Parentid: currentItem.ID,
ExpandURL: currentItem.ID + "/providers/microsoft.Insights/metrics?timespan=" + time.Now().UTC().Add(-3*time.Hour).Format("2006-01-02T15:04:05.000Z") + "/" + time.Now().UTC().Format("2006-01-02T15:04:05.000Z") + "&interval=PT5M&metricnames=" + metric.Name.Value + "&aggregation=" + metric.PrimaryAggregationType + "&metricNamespace=" + metric.Namespace + "&autoadjusttimegrain=true&validatedimensions=false&api-version=2018-01-01",
ExpandURL: currentItem.ID + "/providers/microsoft.Insights/metrics?timespan=" + time.Now().UTC().Add(-4*time.Hour).Format("2006-01-02T15:04:05.000Z") + "/" + time.Now().UTC().Format("2006-01-02T15:04:05.000Z") + "&interval=PT1M&metricnames=" + metric.Name.Value + "&aggregation=" + metric.PrimaryAggregationType + "&metricNamespace=" + metric.Namespace + "&autoadjusttimegrain=true&validatedimensions=false&api-version=2018-01-01",
ItemType: "metrics.graph",
SubscriptionID: currentItem.SubscriptionID,
Metadata: map[string]string{
Expand Down Expand Up @@ -165,15 +165,15 @@ func expandGraph(ctx context.Context, currentItem *TreeNode) ExpanderResult {
}
}

caption := style.Title(currentItem.Name+" over last 3hrs ") + style.Subtle("(Aggregate: '"+currentItem.Metadata["AggregationType"]+"' Unit: '"+currentItem.Metadata["Units"]+"')")
caption := style.Title(currentItem.Name) + style.Subtle("(Aggregate: '"+currentItem.Metadata["AggregationType"]+"' Unit: '"+currentItem.Metadata["Units"]+"')")

graphData := []float64{}
for _, datapoint := range metricResponse.Value[0].Timeseries[0].Data {
value := datapoint[currentItem.Metadata["AggregationType"]].(float64)
graphData = append(graphData, value)
}

graph := asciigraph.Plot(graphData, asciigraph.Height(ItemWidgetHeight), asciigraph.Width(ItemWidgetWidth), asciigraph.Caption("time: 3hrs ago ----> now"))
graph := asciigraph.Plot(graphData, asciigraph.Height(ItemWidgetHeight), asciigraph.Width(ItemWidgetWidth), asciigraph.Caption("time: 4hrs ago ----> now"))

return ExpanderResult{
Response: "\n\n" + caption + "\n\n" + style.Graph(graph),
Expand Down
6 changes: 4 additions & 2 deletions internal/pkg/views/treeview.go
Expand Up @@ -93,8 +93,10 @@ func (w *ListWidget) Layout(g *gocui.Gui) error {
}

for index := topIndex; index < bottomIndex+1; index++ {
item := allItems[index]
fmt.Fprint(v, item)
if index < len(allItems) {
item := allItems[index]
fmt.Fprint(v, item)
}
}

// If the title is getting too long trim things
Expand Down

0 comments on commit 05927b0

Please sign in to comment.