Skip to content

feat(baremetal): get metrics #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions api/baremetal/v1alpha1/baremetal_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ type Disk struct {
Type string `json:"type"`
}

// GetServerMetricsResponse get server metrics response
type GetServerMetricsResponse struct {
// Pings timeseries of ping on the server
Pings *scw.TimeSeries `json:"pings"`
}

// IP ip
type IP struct {
// ID iD of the IP
Expand Down Expand Up @@ -1110,6 +1116,46 @@ func (s *API) InstallServer(req *InstallServerRequest, opts ...scw.RequestOption
return &resp, nil
}

type GetServerMetricsRequest struct {
Zone scw.Zone `json:"-"`
// ServerID server ID to get the metrics
ServerID string `json:"-"`
}

// GetServerMetrics return server metrics
//
// Give the ping status on the server associated with the given ID.
func (s *API) GetServerMetrics(req *GetServerMetricsRequest, opts ...scw.RequestOption) (*GetServerMetricsResponse, error) {
var err error

if req.Zone == "" {
defaultZone, _ := s.client.GetDefaultZone()
req.Zone = defaultZone
}

if fmt.Sprint(req.Zone) == "" {
return nil, errors.New("field Zone cannot be empty in request")
}

if fmt.Sprint(req.ServerID) == "" {
return nil, errors.New("field ServerID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "GET",
Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/servers/" + fmt.Sprint(req.ServerID) + "/metrics",
Headers: http.Header{},
}

var resp GetServerMetricsResponse

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

type DeleteServerRequest struct {
Zone scw.Zone `json:"-"`
// ServerID iD of the server to delete
Expand Down