This documentation is still new and evolving. If you spot any mistakes, unclear explanations, or missing details, please open an issue.
Your feedback helps us improve!
prod operatorsโ
This page lists all operators available in the prod sub-package of ro.
Installโ
First, import the sub-package in your project:
go get -u github.com/samber/ro/plugins/proc
NewCPUInfoWatcherโ
Watches CPU information.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v3/cpu"
)
obs := roproc.NewCPUInfoWatcher(2 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[cpu.InfoStat]())
defer sub.Unsubscribe()
// Next: {CPU: 0, VendorID: GenuineIntel, Family: 6, Model: 142 ...}
// Next: {CPU: 1, VendorID: GenuineIntel, Family: 6, Model: 142 ...}
// ...Prototype:func NewCPUInfoWatcher(interval time.Duration)NewVirtualMemoryWatcherโ
Watches virtual memory statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/mem"
)
obs := roproc.NewVirtualMemoryWatcher(2 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[*mem.VirtualMemoryStat]())
defer sub.Unsubscribe()
// Next: &{Total: 17179869184, Available: 8589934592, Used: 8589934592, ...}
// Next: &{Total: 17179869184, Available: 85983232, Used: 8589934592, ...}
// ...Prototype:func NewVirtualMemoryWatcher(interval time.Duration)NewSwapMemoryWatcherโ
Watches swap memory statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/mem"
)
obs := roproc.NewSwapMemoryWatcher(2 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[*mem.SwapMemoryStat]())
defer sub.Unsubscribe()
// Next: &{Total: 4294967296, Used: 2147483648, Free: 2147483648, ...}
// Next: &{Total: 4294967296, Used: 2155892256, Free: 2139075040, ...}
// ...Prototype:func NewSwapMemoryWatcher(interval time.Duration)NewSwapDeviceWatcherโ
Watches swap device statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/mem"
)
obs := roproc.NewSwapDeviceWatcher(2 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[*mem.SwapDevice]())
defer sub.Unsubscribe()
// Next: &{Name: /dev/sda1, Used: 1073741824, Free: 3221225472, ...}
// Next: &{Name: /dev/sda2, Used: 2147483648, Free: 2147483648, ...}
// ...Prototype:func NewSwapDeviceWatcher(interval time.Duration)NewDiskIOCountersWatcherโ
Watches disk I/O counters statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/disk"
)
obs := roproc.NewDiskIOCountersWatcher(2 * time.Second, "sda", "sdb")
sub := obs.Subscribe(ro.PrintObserver[map[string]disk.IOCountersStat]())
defer sub.Unsubscribe()
// Next: map[sda:{ReadCount: 1000, WriteCount: 500, ...} sdb:{ReadCount: 800, WriteCount: 300, ...}]
// Next: map[sda:{ReadCount: 1005, WriteCount: 505, ...} sdb:{ReadCount: 805, WriteCount: 305, ...}]
// ...Prototype:func NewDiskIOCountersWatcher(interval time.Duration, names ...string)NewDiskPartitionWatcherโ
Watches disk partition statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/disk"
)
obs := roproc.NewDiskPartitionWatcher(5 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[disk.PartitionStat]())
defer sub.Unsubscribe()
// Next: {Device: /dev/sda1, Mountpoint: /, Fstype: ext4, Opts: rw,relatime}
// Next: {Device: /dev/sda2, Mountpoint: /home, Fstype: ext4, Opts: rw,relatime}
// ...Prototype:func NewDiskPartitionWatcher(interval time.Duration)NewHostUserWatcherโ
Watches host user statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/host"
)
obs := roproc.NewHostUserWatcher(10 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[host.UserStat]())
defer sub.Unsubscribe()
// Next: {User: root, Terminal: /dev/pts/0, Host: localhost, Started: 1640995200}
// Next: {User: samber, Terminal: /dev/pts/1, Host: localhost, Started: 1640995300}
// ...Prototype:func NewHostUserWatcher(interval time.Duration)NewLoadMiscWatcherโ
Watches miscellaneous load statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/load"
)
obs := roproc.NewLoadMiscWatcher(2 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[*load.MiscStat]())
defer sub.Unsubscribe()
// Next: &{ProcsTotal: 150, ProcsRunning: 2, ProcsBlocked: 1, CtxSwitches: 1000000, ...}
// Next: &{ProcsTotal: 152, ProcsRunning: 3, ProcsBlocked: 1, CtxSwitches: 1001000, ...}
// ...Prototype:func NewLoadMiscWatcher(interval time.Duration)NewNetConnectionsWatcherโ
Watches network connection statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/net"
)
obs := roproc.NewNetConnectionsWatcher(3 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[net.ConnectionStat]())
defer sub.Unsubscribe()
// Next: {Fd: 3, Family: 2, Type: 1, Laddr: {IP: 127.0.0.1, Port: 8080}, ...}
// Next: {Fd: 4, Family: 2, Type: 1, Laddr: {IP: 192.168.1.100, Port: 443}, ...}
// ...Prototype:func NewNetConnectionsWatcher(interval time.Duration)NewNetConntrackWatcherโ
Watches netfilter conntrack statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/net"
)
obs := roproc.NewNetConntrackWatcher(2 * time.Second, false)
sub := obs.Subscribe(ro.PrintObserver[net.ConntrackStat]())
defer sub.Unsubscribe()
// Next: {Entries: 1000, Searched: 2000, Found: 1500, New: 50, ...}
// Next: {Entries: 1050, Searched: 2100, Found: 1575, New: 55, ...}
// ...Prototype:func NewNetConntrackWatcher(interval time.Duration, perCPU bool)NewNetFilterCountersWatcherโ
Watches netfilter counter statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/net"
)
obs := roproc.NewNetFilterCountersWatcher(2 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[net.FilterStat]())
defer sub.Unsubscribe()
// Next: {ConntrackCount: 1000, ConntrackMax: 65536}
// Next: {ConntrackCount: 1050, ConntrackMax: 65536}
// ...Prototype:func NewNetFilterCountersWatcher(interval time.Duration)NewSensorsTemperatureWatcherโ
Watches sensor temperature statistics.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
"github.com/shirou/gopsutil/v4/sensors"
)
obs := roproc.NewSensorsTemperatureWatcher(2 * time.Second, false)
sub := obs.Subscribe(ro.PrintObserver[sensors.TemperatureStat]())
defer sub.Unsubscribe()
// Next: {SensorKey: coretemp-isa-0000, Temperature: 45.0, SensorHigh: 80.0, SensorCrit: 100.0}
// Next: {SensorKey: acpi-thermal-0, Temperature: 40.0, SensorHigh: 85.0, SensorCrit: 105.0}
// ...Prototype:func NewSensorsTemperatureWatcher(interval time.Duration, perNIC bool)NewLoadAverageWatcherโ
Emits system load average statistics at regular intervals.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
)
obs := roproc.NewLoadAverageWatcher(2 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[*load.AvgStat]())
defer sub.Unsubscribe()
// Next: &{Load1: 0.75 Load5: 0.82 Load15: 0.90}
// Next: &{Load1: 0.80 Load5: 0.83 Load15: 0.91}
// Next: &{Load1: 0.78 Load5: 0.81 Load15: 0.89}
// ... (continues every 2 seconds)Returns system load average values for 1, 5, and 15 minute intervals.
Prototype:func NewLoadAverageWatcher(interval time.Duration)NewDiskUsageWatcherโ
Emits disk usage statistics for a specific mount point or device at regular intervals.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
)
obs := roproc.NewDiskUsageWatcher(5 * time.Second, "/")
sub := obs.Subscribe(ro.PrintObserver[*disk.UsageStat]())
defer sub.Unsubscribe()
// Next: &{Path: "/" Total: 500000000000 Free: 250000000000 Used: 250000000000 UsedPercent: 50.0 ...}
// Next: &{Path: "/" Total: 500000000000 Free: 249000000000 Used: 251000000000 UsedPercent: 50.2 ...}
// ... (continues every 5 seconds)Returns disk usage information including total space, free space, used space, and usage percentage for the specified path.
Prototype:func NewDiskUsageWatcher(interval time.Duration, mountpointOrDevicePath string)NewHostInfoWatcherโ
Emits host system information at regular intervals.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
)
obs := roproc.NewHostInfoWatcher(10 * time.Second)
sub := obs.Subscribe(ro.PrintObserver[*host.InfoStat]())
defer sub.Unsubscribe()
// Next: &{Hostname: "my-server" Uptime: 86400 BootTime: 1640995200 Procs: 150 OS: "linux" ...}
// Next: &{Hostname: "my-server" Uptime: 86410 BootTime: 1640995200 Procs: 152 OS: "linux" ...}
// ... (continues every 10 seconds)Returns comprehensive host information including hostname, uptime, boot time, process count, operating system details, platform, architecture, and other system metadata.
Prototype:func NewHostInfoWatcher(interval time.Duration)NewNetIOCountersWatcherโ
Emits network IO counters statistics at regular intervals.
import (
"time"
"github.com/samber/ro"
roproc "github.com/samber/ro/plugins/proc"
)
obs := roproc.NewNetIOCountersWatcher(3 * time.Second, true)
sub := obs.Subscribe(ro.PrintObserver[net.IOCountersStat]())
defer sub.Unsubscribe()
// Next: &{Name: "eth0" BytesSent: 1024000 BytesRecv: 2048000 PacketsSent: 1000 PacketsRecv: 2000 ...}
// Next: &{Name: "eth0" BytesSent: 1025000 BytesRecv: 2050000 PacketsSent: 1005 PacketsRecv: 2005 ...}
// Next: &{Name: "lo" BytesSent: 5000 BytesRecv: 5000 PacketsSent: 50 PacketsRecv: 50 ...}
// ... (continues every 3 seconds)Returns network interface statistics including bytes sent/received, packets sent/received, and other IO metrics. Set perNIC to true to get stats per network interface, or false to get aggregated stats.
Prototype:func NewNetIOCountersWatcher(interval time.Duration, perNIC bool)