Skip to content
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

fix: add correct RRD Data format and fix the variatic function #179

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,14 @@ func (c *Container) MoveVolume(ctx context.Context, params *VirtualMachineMoveDi
func (c *Container) RRDData(ctx context.Context, timeframe Timeframe, consolidationFunction ConsolidationFunction) (rrddata []*RRDData, err error) {
u := url.URL{Path: fmt.Sprintf("/lxc/%s/qemu/%d/rrddata", c.Node, c.VMID)}

// consolidation functions are variadic because they're optional, putting everything into one string and sending that
// consolidation functions are variadic because they're optional, but Proxmox only allows one cf parameter
params := url.Values{}
if len(consolidationFunction) > 0 {

f := ""
for _, cf := range consolidationFunction {
f = f + string(cf)
if len(consolidationFunction) != 1 {
return nil, fmt.Errorf("only one consolidation function allowed")
}
params.Add("cf", f)

params.Add("cf", string(consolidationFunction[0]))
}

params.Add("timeframe", string(timeframe))
Expand Down
18 changes: 12 additions & 6 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (cl *Cluster) UnmarshalJSON(b []byte) error {
type ClusterResources []*ClusterResource

type ClusterResource struct {
ID string `jsont:"id"`
ID string `json:"id"`
Type string `json:"type"`
CGroupMode uint64 `json:"cgroup-mode,omitempty"`
Content string `json:",omitempty"`
Expand Down Expand Up @@ -304,11 +304,17 @@ const (
)

type RRDData struct {
MaxCPU int
MaxMem uint64
Disk int
MaxDisk uint64
Time uint64
Time uint64
Cpu float64
MaxCpu int
Mem float64
MaxMem uint64
Disk int
MaxDisk uint64
DiskRead float64
DiskWrite float64
NetIn float64
NetOut float64
}

// VirtualMachineOptions A key/value pair used to modify a virtual machine config
Expand Down
11 changes: 5 additions & 6 deletions virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,15 +631,14 @@ func (v *VirtualMachine) SnapshotRollback(ctx context.Context, name string) (tas
func (v *VirtualMachine) RRDData(ctx context.Context, timeframe Timeframe, consolidationFunction ...ConsolidationFunction) (rrddata []*RRDData, err error) {
u := url.URL{Path: fmt.Sprintf("/nodes/%s/qemu/%d/rrddata", v.Node, v.VMID)}

// consolidation functions are variadic because they're optional, putting everything into one string and sending that
// consolidation functions are variadic because they're optional, but Proxmox only allows one cf parameter
params := url.Values{}
if len(consolidationFunction) > 0 {

f := ""
for _, cf := range consolidationFunction {
f = f + string(cf)
if len(consolidationFunction) != 1 {
return nil, fmt.Errorf("only one consolidation function allowed")
}
params.Add("cf", f)

params.Add("cf", string(consolidationFunction[0]))
}

params.Add("timeframe", string(timeframe))
Expand Down