github.com/newrelic/newrelic-client-go@v1.1.0/pkg/apm/example_application_instances_test.go (about) 1 package apm 2 3 import ( 4 "fmt" 5 "log" 6 "os" 7 8 "github.com/newrelic/newrelic-client-go/pkg/config" 9 ) 10 11 func Example_application_instances() { 12 // Initialize the client configuration. A Personal API key 13 // is required to communicate with the backend API. 14 cfg := config.New() 15 cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY") 16 17 // Initialize the client. 18 client := New(cfg) 19 20 applicationID := 12345 21 instanceID := 12345678 22 23 params := ListApplicationInstancesParams{ 24 Hostname: "hostname", 25 IDs: []int{instanceID}, 26 } 27 28 // List an application's instances. 29 instances, err := client.ListApplicationInstances(applicationID, ¶ms) 30 if err != nil { 31 log.Fatal("error listing application instances:", err) 32 } 33 34 // Output the application instance count. 35 fmt.Printf("Instance count: %d", len(instances)) 36 37 // Get a specific application instance. 38 instance, err := client.GetApplicationInstance(applicationID, instanceID) 39 if err != nil { 40 log.Fatal("error deleting application:", err) 41 } 42 43 // Output the application instance's host and port. 44 fmt.Printf("Host: %s, Port: %d\n", instance.Host, instance.Port) 45 }