### Instruction:
Develop a Golang program that retrieves metrics from an Azure Monitor instance and displays them in a terminal dashboard. The dashboard should update every minute and show CPU usage, memory usage, and network throughput.


### Response:

To create a Golang program that retrieves metrics from an Azure Monitor instance and displays them in a terminal dashboard, you'll need to follow these steps:

1. Set up your development environment with the necessary dependencies.
2. Authenticate with Azure using the SDK.
3. Retrieve the required metrics from Azure Monitor.
4. Create a terminal dashboard using a library like `termui`.
5. Display the retrieved metrics on the dashboard.

Here's a sample implementation of this program:

```go
package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/Azure/azure-sdk-for-go/profiles/latest/monitor/mgmt/insights"
	"github.com/Azure/go-autorest/autorest/azure/auth"
	ui "github.com/gizak/termui/v3"
	"github.com/gizak/termui/v3/widgets"
)

func main() {
	err := ui.Init()
	if err != nil {
		log.Fatalf("failed to initialize termui: %v", err)
	}
	defer ui.Close()

	resourceGroup := os.Getenv("AZURE_RESOURCE_GROUP")
	resourceURI := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/myVM", os.Getenv("AZURE_SUBSCRIPTION_ID"), resourceGroup)

	metricsClient, err := getMetricsClient()
	if err != nil {
		log.Fatal(err)
	}

	cpuGauge := widgets.NewGauge()
	memGauge := widgets.NewGauge()
	netSparkline := widgets.NewSparkline()

	grid := ui.NewGrid()
	termWidth, termHeight := ui.TerminalDimensions()
	grid.SetRect(0, 0, termWidth, termHeight)
	grid.Set(
		ui.NewRow(1.0/3,
			ui.NewCol(1.0/3, cpuGauge),
			ui.NewCol(1.0/3, memGauge),
			ui.NewCol(1.0/3, netSparkline),
		),
	)

	ui.Render(grid)

	ticker := time.NewTicker(time.Minute).C
	for {
		select {
		case <-ticker:
			cpuUsage, memUsage, netThroughput, err := getMetrics(metricsClient, resourceURI)
			if err != nil {
				log.Println(err)
				continue
			}

			cpuGauge.Percent = int(cpuUsage)
			memGauge.Percent = int(memUsage)
			netSparkline.Data = append(netSparkline.Data[1:], netThroughput)

			ui.Render(grid)
		}
	}
}

func getMetricsClient() (*insights.MetricsClient, error) {
	authorizer, err := auth.NewAuthorizerFromEnvironment()
	if err != nil {
		return nil, fmt.Errorf("failed to create authorizer: %v", err)
	}

	client := insights.NewMetricsClient(os.Getenv("AZURE_SUBSCRIPTION_ID"))
	client.Authorizer = authorizer

	return &client, nil
}

func getMetrics(client *insights.MetricsClient, resourceURI string) (float64, float64, float64, error) {
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	metricNames := []string{"Percentage CPU", "Memory\\Working Set", "Network In Total"}
	result, err := client.List(ctx, resourceURI, "PT1M", &metricNames, "", "", "value", "")
	if err != nil {
		return 0, 0, 0, fmt.Errorf("failed to retrieve metrics: %v", err)
	}

	var cpuUsage, memUsage, netThroughput float64
	for _, metric := range *result.Value {
		if len(*metric.Timeseries) == 0 || len((*metric.Timeseries)[0].Data) == 0 {
			continue
		}

		data := (*metric.Timeseries)[0].Data
		value := *data[len(data)-1].Average

		switch *metric.Name.Value {
		case "Percentage CPU":
			cpuUsage = value
		case "Memory\\Working Set":
			memUsage = value / (1024 * 1024)
		case "Network In Total":
			netThroughput = value
		}
	}

	return cpuUsage, memUsage, netThroughput, nil
}
```

This program assumes you have the Azure SDK for Go and termui library installed. You can install them using:

```sh
go get -u github.com/Azure/azure-sdk-for-go
go get -u github.com/gizak/termui/v3
```

Make sure to set the following environment variables before running the program:

- `AZURE_SUBSCRIPTION_ID`: Your Azure subscription ID.
- `AZURE_RESOURCE_GROUP`: The resource group containing your virtual machine.
- `AZURE_TENANT_ID`: Your Azure tenant ID.
- `AZURE_CLIENT_ID`: Your Azure client ID.
- `AZURE_CLIENT_SECRET`: Your Azure client secret.

The program will display a terminal dashboard with three widgets: one for CPU usage, one for memory usage, and one for network throughput. The dashboard will update every minute with new metrics from Azure Monitor.