github.com/wtfutil/wtf@v0.43.0/modules/newrelic/client/applications.go (about) 1 package newrelic 2 3 import ( 4 "strconv" 5 "time" 6 ) 7 8 // ApplicationSummary describes the brief summary component of an Application. 9 type ApplicationSummary struct { 10 ResponseTime float64 `json:"response_time,omitempty"` 11 Throughput float64 `json:"throughput,omitempty"` 12 ErrorRate float64 `json:"error_rate,omitempty"` 13 ApdexTarget float64 `json:"apdex_target,omitempty"` 14 ApdexScore float64 `json:"apdex_score,omitempty"` 15 HostCount int `json:"host_count,omitempty"` 16 InstanceCount int `json:"instance_count,omitempty"` 17 ConcurrentInstanceCount int `json:"concurrent_instance_count,omitempty"` 18 } 19 20 // EndUserSummary describes the end user summary component of an Application. 21 type EndUserSummary struct { 22 ResponseTime float64 `json:"response_time,omitempty"` 23 Throughput float64 `json:"throughput,omitempty"` 24 ApdexTarget float64 `json:"apdex_target,omitempty"` 25 ApdexScore float64 `json:"apdex_score,omitempty"` 26 } 27 28 // Settings describe settings for an Application. 29 type Settings struct { 30 AppApdexThreshold float64 `json:"app_apdex_threshold,omitempty"` 31 EndUserApdexThreshold float64 `json:"end_user_apdex_threshold,omitempty"` 32 EnableRealUserMonitoring bool `json:"enable_real_user_monitoring,omitempty"` 33 UseServerSideConfig bool `json:"use_server_side_config,omitempty"` 34 } 35 36 // Links list IDs associated with an Application. 37 type Links struct { 38 Servers []int `json:"servers,omitempty"` 39 ApplicationHosts []int `json:"application_hosts,omitempty"` 40 ApplicationInstances []int `json:"application_instances,omitempty"` 41 AlertPolicy int `json:"alert_policy,omitempty"` 42 } 43 44 // Application describes a New Relic Application. 45 type Application struct { 46 ID int `json:"id,omitempty"` 47 Name string `json:"name,omitempty"` 48 Language string `json:"language,omitempty"` 49 HealthStatus string `json:"health_status,omitempty"` 50 Reporting bool `json:"reporting,omitempty"` 51 LastReportedAt time.Time `json:"last_reported_at,omitempty"` 52 ApplicationSummary ApplicationSummary `json:"application_summary,omitempty"` 53 EndUserSummary EndUserSummary `json:"end_user_summary,omitempty"` 54 Settings Settings `json:"settings,omitempty"` 55 Links Links `json:"links,omitempty"` 56 } 57 58 // ApplicationFilter provides a means to filter requests through 59 // ApplicaitonOptions when calling GetApplications. 60 type ApplicationFilter struct { 61 Name string 62 Host string 63 IDs []int 64 Language string 65 } 66 67 // ApplicationOptions provides a means to filter results when calling 68 // GetApplicaitons. 69 type ApplicationOptions struct { 70 Filter ApplicationFilter 71 Page int 72 } 73 74 func (o *ApplicationOptions) String() string { 75 if o == nil { 76 return "" 77 } 78 return encodeGetParams(map[string]interface{}{ 79 "filter[name]": o.Filter.Name, 80 "filter[host]": o.Filter.Host, 81 "filter[ids]": o.Filter.IDs, 82 "filter[language]": o.Filter.Language, 83 "page": o.Page, 84 }) 85 } 86 87 // GetApplications returns a slice of New Relic Applications, optionally 88 // filtering by ApplicationOptions. 89 func (c *Client) GetApplications(options *ApplicationOptions) ([]Application, error) { 90 resp := &struct { 91 Applications []Application `json:"applications,omitempty"` 92 }{} 93 err := c.doGet("applications.json", options, resp) 94 if err != nil { 95 return nil, err 96 } 97 return resp.Applications, nil 98 } 99 100 // GetApplication returns a single Application associated with a given ID. 101 func (c *Client) GetApplication(id int) (*Application, error) { 102 resp := &struct { 103 Application Application `json:"application,omitempty"` 104 }{} 105 path := "applications/" + strconv.Itoa(id) + ".json" 106 err := c.doGet(path, nil, resp) 107 if err != nil { 108 return nil, err 109 } 110 return &resp.Application, nil 111 }