This module is not meant to be a complete solution, rather it's meant to get just the minimum system information required by archey-go. If you're looking for something more complete, then you might want to take a look at gopsutil
package main
import (
"fmt"
"github.com/alexdreptu/sysinfo/cpu"
)
cpu := &cpu.CPU{}
if err := cpu.Fetch(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
or
cpu, err := cpu.New()
if err != nil {
fmt.Printf(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("Name: %s\n", cpu.Name)
fmt.Printf("Model: %d\n", cpu.Model)
fmt.Printf("Vendor: %s\n", cpu.Vendor)
fmt.Printf("Family: %d\n", cpu.Family)
fmt.Printf("Stepping: %d\n", cpu.Stepping)
fmt.Printf("Cores: %d\n", cpu.Cores)
fmt.Printf("Cache Size: %d KiB\n", cpu.CacheSize)
fmt.Printf("Cache Size: %.2f MiB\n", cpu.CacheSizeInMebibytes())
fmt.Printf("Min Frequency: %d KHz\n", cpu.MinFreq)
fmt.Printf("Max Frequency: %d KHz\n", cpu.MaxFreq)
fmt.Printf("Min Frequency: %.2f MHz\n", cpu.MinFreqInMegahertz())
fmt.Printf("Min Frequency: %.1f GHz\n", cpu.MinFreqInGigahertz())
fmt.Printf("Max Frequency: %.2f MHz\n", cpu.MaxFreqInMegahertz())
fmt.Printf("Max Frequency: %.1f GHz\n", cpu.MaxFreqInGigahertz())
fmt.Printf("Flags %s\n", cpu.FlagsAsString())
package main
import (
"fmt"
"github.com/alexdreptu/sysinfo/fs"
)
rootfs := &fs.FS{Path: "/"}
if err := rootfs.Fetch(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
or
rootfs, err := fs.New("/")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("Total Space on Root: %.2f KiB\n", rootfs.TotalSpaceInKibibytes())
fmt.Printf("Total Space on Root: %.2f MiB\n", rootfs.TotalSpaceInMebibytes())
fmt.Printf("Total Space on Root: %.2f GiB\n", rootfs.TotalSpaceInGibibytes())
fmt.Printf("Free Space on Root: %.2f KiB\n", rootfs.FreeSpaceInKibibytes())
fmt.Printf("Free Space on Root: %.2f MiB\n", rootfs.FreeSpaceInMebibytes())
fmt.Printf("Free Space on Root: %.2f GiB\n", rootfs.FreeSpaceInGibibytes())
fmt.Printf("Used Space on Root: %.2f KiB\n", rootfs.UsedSpaceInKibibytes())
fmt.Printf("Used Space on Root: %.2f MiB\n", rootfs.UsedSpaceInMebibytes())
fmt.Printf("Used Space On Root: %.2f GiB\n", rootfs.UsedSpaceInGibibytes())
package main
import (
"fmt"
"github.com/alexdreptu/sysinfo/mem"
)
mem := &mem.Mem{}
if err := mem.Fetch(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
or
mem, err := mem.New()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("Total Mem: %.2f KiB\n", mem.TotalMemInKibibytes())
fmt.Printf("Total Mem: %.2f MiB\n", mem.TotalMemInMebibytes())
fmt.Printf("Total Mem: %.2f GiB\n", mem.TotalMemInGibibytes())
fmt.Printf("Total High Mem: %.2f KiB\n", mem.TotalHighMemInKibibytes())
fmt.Printf("Total High Mem: %.2f MiB\n", mem.TotalHighMemInMebibytes())
fmt.Printf("Total High Mem: %.2f GiB\n", mem.TotalHighMemInGibibytes())
fmt.Printf("Free Mem: %.2f KiB\n", mem.FreeMemInKibibytes())
fmt.Printf("Free Mem: %.2f MiB\n", mem.FreeMemInMebibytes())
fmt.Printf("Free Mem: %.2f GiB\n", mem.FreeMemInGibibytes())
fmt.Printf("Free High Mem: %.2f KiB\n", mem.FreeHighMemInKibibytes())
fmt.Printf("Free High Mem: %.2f MiB\n", mem.FreeHighMemInMebibytes())
fmt.Printf("Free High Mem: %.2f GiB\n", mem.FreeHighMemInGibibytes())
fmt.Printf("Avail Mem: %.2f KiB\n", mem.AvailMemInKibibytes())
fmt.Printf("Avail Mem: %.2f MiB\n", mem.AvailMemInMebibytes())
fmt.Printf("Avail Mem: %.2f GiB\n", mem.AvailMemInGibibytes())
fmt.Printf("Used Mem: %.2f KiB\n", mem.UsedMemInKibibytes())
fmt.Printf("Used Mem: %.2f MiB\n", mem.UsedMemInMebibytes())
fmt.Printf("Used Mem: %.2f GiB\n", mem.UsedMemInGibibytes())
fmt.Printf("Total Used Mem: %.2f KiB\n", mem.TotalUsedMemInKibibytes())
fmt.Printf("Total Used Mem: %.2f MiB\n", mem.TotalUsedMemInMebibytes())
fmt.Printf("Total Used Mem: %.2f GiB\n", mem.TotalUsedMemInGibibytes())
fmt.Printf("Total Used: %.2f KiB\n", mem.TotalUsedInKibibytes())
fmt.Printf("Total Used: %.2f MiB\n", mem.TotalUsedInMebibytes())
fmt.Printf("Total Used: %.2f GiB\n", mem.TotalUsedInGibibytes())
fmt.Printf("Buffer Mem: %.2f KiB\n", mem.BufferMemInKibibytes())
fmt.Printf("Buffer Mem: %.2f MiB\n", mem.BufferMemInMebibytes())
fmt.Printf("Buffer Mem: %.2f GiB\n", mem.BufferMemInGibibytes())
fmt.Printf("Shared Mem: %.2f KiB\n", mem.SharedMemInKibibytes())
fmt.Printf("Shared Mem: %.2f MiB\n", mem.SharedMemInMebibytes())
fmt.Printf("Shared Mem: %.2f GiB\n", mem.SharedMemInGibibytes())
fmt.Printf("Total Swap: %.2f KiB\n", mem.TotalSwapInKibibytes())
fmt.Printf("Total Swap: %.2f MiB\n", mem.TotalSwapInMebibytes())
fmt.Printf("Total Swap: %.2f GiB\n", mem.TotalSwapInGibibytes())
fmt.Printf("Free Swap: %.2f KiB\n", mem.FreeSwapInKibibytes())
fmt.Printf("Free Swap: %.2f MiB\n", mem.FreeSwapInMebibytes())
fmt.Printf("Free Swap: %.2f GiB\n", mem.FreeSwapInGibibytes())
fmt.Printf("Used Swap: %.2f KiB\n", mem.UsedSwapInKibibytes())
fmt.Printf("Used Swap: %.2f MiB\n", mem.UsedSwapInMebibytes())
fmt.Printf("Used Swap: %.2f GiB\n", mem.UsedSwapInGibibytes())
package main
import (
"fmt"
"github.com/alexdreptu/sysinfo/node"
)
node := &node.Node{}
if err := node.Fetch(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
or
node, err := node.New()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("Domainname: %s\n", node.DomainName)
fmt.Printf("Machine: %s\n", node.Machine)
fmt.Printf("Nodename: %s\n", node.NodeName)
fmt.Printf("OS Name: %s\n", node.OSName)
fmt.Printf("Release: %s\n", node.Release)
fmt.Printf("Sysname: %s\n", node.SysName)
fmt.Printf("Version: %s\n", node.Version)
package main
import (
"fmt"
"github.com/alexdreptu/sysinfo/uptime"
)
uptime := &uptime.Uptime{}
if err := uptime.Fetch(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
or
uptime, err := uptime.New()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
)
fmt.Printf("Uptime: %s\n", uptime)
fmt.Printf("Up since (RFC1123): %s\n", uptime.Since())
fmt.Printf("Up since (Custom): %s\n", uptime.SinceFormat("%d/%m/%y %T")) // strftime format
package main
import (
"fmt"
"github.com/alexdreptu/sysinfo/convert"
)
func main() {
// convert bytes
bytes := 8267812044.8
fmt.Printf("%.2f Bytes -> %.2f Kibibytes\n",
bytes, (convert.Size(bytes) * convert.Byte).ToKibibytes())
fmt.Printf("%.2f Bytes -> %.2f Mebibytes\n",
bytes, (convert.Size(bytes) * convert.Byte).ToMebibytes())
fmt.Printf("%.2f Bytes -> %.2f Gibibytes\n",
bytes, (convert.Size(bytes) * convert.Byte).ToGibibytes())
// convert kibibytes
kibibytes := 8074035.2
fmt.Printf("%.2f Kibibytes -> %.2f Bytes\n",
kibibytes, (convert.Size(kibibytes) * convert.Kibibyte).ToBytes())
fmt.Printf("%.2f Kibibytes -> %.2f Mebibytes\n",
kibibytes, (convert.Size(kibibytes) * convert.Kibibyte).ToMebibytes())
fmt.Printf("%.2f Kibibytes -> %.2f Gibibytes\n",
kibibytes, (convert.Size(kibibytes) * convert.Kibibyte).ToGibibytes())
// convert mebibytes
mebibytes := 7884.8
fmt.Printf("%.2f Mebibytes -> %.2f Bytes\n",
mebibytes, (convert.Size(mebibytes) * convert.Mebibyte).ToBytes())
fmt.Printf("%.2f Mebibytes -> %.2f Kibibytes\n",
mebibytes, (convert.Size(mebibytes) * convert.Mebibyte).ToKibibytes())
fmt.Printf("%.2f Mebibytes -> %.2f Gibibytes\n",
mebibytes, (convert.Size(mebibytes) * convert.Mebibyte).ToGibibytes())
// convert gibibytes
gibibytes := 7.7
fmt.Printf("%.2f Gibibytes -> %.2f Bytes\n",
gibibytes, (convert.Size(gibibytes) * convert.Gibibyte).ToBytes())
fmt.Printf("%.2f Gibibytes -> %.2f Kibibytes\n",
gibibytes, (convert.Size(gibibytes) * convert.Gibibyte).ToKibibytes())
fmt.Printf("%.2f Gibibytes -> %.2f Mebibytes\n",
gibibytes, (convert.Size(gibibytes) * convert.Gibibyte).ToMebibytes())
// convert kilohertz
kilohertz := 3900000
fmt.Printf("%v Kilohertz -> %v Herz\n",
kilohertz, (convert.Frequency(kilohertz) * convert.Kilohertz).ToHertz())
fmt.Printf("%v Kilohertz -> %v Megahertz\n",
kilohertz, (convert.Frequency(kilohertz) * convert.Kilohertz).ToMegahertz())
fmt.Printf("%v Kilohertz -> %v Gigahertz\n",
kilohertz, (convert.Frequency(kilohertz) * convert.Kilohertz).ToGigahertz())
}