github.com/wtfutil/wtf@v0.43.0/modules/newrelic/client/application_hosts.go (about)

     1  package newrelic
     2  
     3  import (
     4  	"strconv"
     5  )
     6  
     7  // ApplicationHostSummary describes an Application's host.
     8  type ApplicationHostSummary struct {
     9  	ApdexScore    float64 `json:"apdex_score,omitempty"`
    10  	ErrorRate     float64 `json:"error_rate,omitempty"`
    11  	InstanceCount int     `json:"instance_count,omitempty"`
    12  	ResponseTime  float64 `json:"response_time,omitempty"`
    13  	Throughput    float64 `json:"throughput,omitempty"`
    14  }
    15  
    16  // ApplicationHostEndUserSummary describes the end user summary component of
    17  // an ApplicationHost.
    18  type ApplicationHostEndUserSummary struct {
    19  	ResponseTime float64 `json:"response_time,omitempty"`
    20  	Throughput   float64 `json:"throughput,omitempty"`
    21  	ApdexScore   float64 `json:"apdex_score,omitempty"`
    22  }
    23  
    24  // ApplicationHostLinks list IDs associated with an ApplicationHost.
    25  type ApplicationHostLinks struct {
    26  	Application          int   `json:"application,omitempty"`
    27  	ApplicationInstances []int `json:"application_instances,omitempty"`
    28  	Server               int   `json:"server,omitempty"`
    29  }
    30  
    31  // ApplicationHost describes a New Relic Application Host.
    32  type ApplicationHost struct {
    33  	ApplicationName    string                        `json:"application_name,omitempty"`
    34  	ApplicationSummary ApplicationHostSummary        `json:"application_summary,omitempty"`
    35  	HealthStatus       string                        `json:"health_status,omitempty"`
    36  	Host               string                        `json:"host,omitempty"`
    37  	ID                 int                           `json:"idomitempty"`
    38  	Language           string                        `json:"language,omitempty"`
    39  	Links              ApplicationHostLinks          `json:"links,omitempty"`
    40  	EndUserSummary     ApplicationHostEndUserSummary `json:"end_user_summary,omitempty"`
    41  }
    42  
    43  // ApplicationHostsFilter provides a means to filter requests through
    44  // ApplicationHostsOptions when calling GetApplicationHosts.
    45  type ApplicationHostsFilter struct {
    46  	Hostname string
    47  	IDs      []int
    48  }
    49  
    50  // ApplicationHostsOptions provide a means to filter results when calling
    51  // GetApplicationHosts.
    52  type ApplicationHostsOptions struct {
    53  	Filter ApplicationHostsFilter
    54  	Page   int
    55  }
    56  
    57  // GetApplicationHosts returns a slice of New Relic Application Hosts,
    58  // optionally filtering by ApplicationHostOptions.
    59  func (c *Client) GetApplicationHosts(id int, options *ApplicationHostsOptions) ([]ApplicationHost, error) {
    60  	resp := &struct {
    61  		ApplicationHosts []ApplicationHost `json:"application_hosts,omitempty"`
    62  	}{}
    63  	path := "applications/" + strconv.Itoa(id) + "/hosts.json"
    64  	err := c.doGet(path, options, resp)
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  	return resp.ApplicationHosts, nil
    69  }
    70  
    71  // GetApplicationHost returns a single Application Host associated with the
    72  // given application host ID and host ID.
    73  func (c *Client) GetApplicationHost(appID, hostID int) (*ApplicationHost, error) {
    74  	resp := &struct {
    75  		ApplicationHost ApplicationHost `json:"application_host,omitempty"`
    76  	}{}
    77  	path := "applications/" + strconv.Itoa(appID) + "/hosts/" + strconv.Itoa(hostID) + ".json"
    78  	err := c.doGet(path, nil, resp)
    79  	if err != nil {
    80  		return nil, err
    81  	}
    82  	return &resp.ApplicationHost, nil
    83  }
    84  
    85  func (o *ApplicationHostsOptions) String() string {
    86  	if o == nil {
    87  		return ""
    88  	}
    89  	return encodeGetParams(map[string]interface{}{
    90  		"filter[hostname]": o.Filter.Hostname,
    91  		"filter[ids]":      o.Filter.IDs,
    92  		"page":             o.Page,
    93  	})
    94  }