Junior — Middle
What are the main system indicators you know and can use for resource monitoring?
sobes.tech AI
Answer from AI
Key system metrics for resource monitoring:
- CPU Usage: percentage of CPU utilization, helps identify overloads.
- Memory Usage: amount of used and free RAM.
- Disk I/O: read/write speeds, delays.
- Network I/O: volume of data transmitted and received, error count.
- Load Average: average system load over a specific period.
- Number of Goroutines (for Go): number of active goroutines, may indicate leaks.
- Garbage Collection metrics: time and frequency of garbage collections.
In Go, you can use the runtime package to get information about goroutines and garbage collection:
import (
"fmt"
"runtime"
)
func printStats() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Goroutines: %d\n", runtime.NumGoroutine())
fmt.Printf("Alloc = %v MiB\n", m.Alloc / 1024 / 1024)
fmt.Printf("TotalAlloc = %v MiB\n", m.TotalAlloc / 1024 / 1024)
fmt.Printf("Sys = %v MiB\n", m.Sys / 1024 / 1024)
fmt.Printf("NumGC = %v\n", m.NumGC)
}