Skip to content
Get started

Get instance resource utilization stats

client.Instances.Stats(ctx, id) (*InstanceStats, error)
get/instances/{id}/stats

Returns real-time resource utilization statistics for a running VM instance. Metrics are collected from /proc//stat and /proc//statm for CPU and memory, and from TAP interface statistics for network I/O.

ParametersExpand Collapse
id string
ReturnsExpand Collapse
type InstanceStats struct{…}

Real-time resource utilization statistics for a VM instance

AllocatedMemoryBytes int64

Total memory allocated to the VM (Size + HotplugSize) in bytes

formatint64
AllocatedVcpus int64

Number of vCPUs allocated to the VM

CPUSeconds float64

Total CPU time consumed by the VM hypervisor process in seconds

formatdouble
InstanceID string

Instance identifier

InstanceName string

Instance name

MemoryRssBytes int64

Resident Set Size - actual physical memory used by the VM in bytes

formatint64
MemoryVmsBytes int64

Virtual Memory Size - total virtual memory allocated in bytes

formatint64
NetworkRxBytes int64

Total network bytes received by the VM (from TAP interface)

formatint64
NetworkTxBytes int64

Total network bytes transmitted by the VM (from TAP interface)

formatint64
MemoryUtilizationRatio float64optional

Memory utilization ratio (RSS / allocated memory). Only present when allocated_memory_bytes > 0.

formatdouble
Get instance resource utilization stats
package main

import (
  "context"
  "fmt"

  "github.com/kernel/hypeman-go"
  "github.com/kernel/hypeman-go/option"
)

func main() {
  client := hypeman.NewClient(
    option.WithAPIKey("My API Key"),
  )
  instanceStats, err := client.Instances.Stats(context.TODO(), "id")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", instanceStats.InstanceID)
}
{
  "allocated_memory_bytes": 4294967296,
  "allocated_vcpus": 2,
  "cpu_seconds": 29.94,
  "instance_id": "qilviffnqzck2jrim1x6s2b1",
  "instance_name": "my-web-server",
  "memory_rss_bytes": 443338752,
  "memory_vms_bytes": 4330745856,
  "network_rx_bytes": 12345678,
  "network_tx_bytes": 87654321,
  "memory_utilization_ratio": 0.103
}
Returns Examples
{
  "allocated_memory_bytes": 4294967296,
  "allocated_vcpus": 2,
  "cpu_seconds": 29.94,
  "instance_id": "qilviffnqzck2jrim1x6s2b1",
  "instance_name": "my-web-server",
  "memory_rss_bytes": 443338752,
  "memory_vms_bytes": 4330745856,
  "network_rx_bytes": 12345678,
  "network_tx_bytes": 87654321,
  "memory_utilization_ratio": 0.103
}