You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudbroker/prometheus/compute_cpu_load.go

58 lines
1.5 KiB

package prometheus
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type ComputeCPULoadRequest struct {
// Compute ID
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Time to loads of statistic in seconds
// Required: false
ForLast uint64 `url:"forLast,omitempty" json:"forLast,omitempty"`
// The reading interval in seconds
// Required: true
Step uint64 `url:"step,omitempty" json:"step,omitempty"`
// Number of zeros after the decimal point
// Required: true
DecimalPlaces uint64 `url:"decimalPlaces,omitempty" json:"decimalPlaces,omitempty"`
}
// Per-second CPU time consumed by Compute in percent, average over the time step specified
func (p Prometheus) ComputeCPULoad(ctx context.Context, req ComputeCPULoadRequest) (*PrometheusData, error) {
res, err := p.ComputeCPULoadRaw(ctx, req)
if err != nil {
return nil, err
}
info := PrometheusData{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets information about compute as an array of bytes
func (p Prometheus) ComputeCPULoadRaw(ctx context.Context, req ComputeCPULoadRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/prometheus/computeCPUload"
res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}