]> Sergey Matveev's repositories - godwmstat.git/blobdiff - main.go
Show CPU frequency
[godwmstat.git] / main.go
diff --git a/main.go b/main.go
index da12e03d66564e6620bec9fcc7f9de8254743740..a9be080519e3e3d536fd6433f8e3cadb1629da83 100644 (file)
--- a/main.go
+++ b/main.go
@@ -17,13 +17,13 @@ import (
 var (
        MyPID string = strconv.Itoa(os.Getpid())
        CPU   string = "?"
+       Freq  string = "?"
        Mem   string = "?"
        ARC   string = "?"
        Swap  string = "?"
        Flags string = "?"
        IOs   string = "?"
        Net   string = "?"
-       N     string = "?"
 )
 
 func piper(c chan []string, name string, args ...string) error {
@@ -69,10 +69,10 @@ func top() {
        for cols := range bg("top", "-b", "-d", "infinity", "-p", MyPID, "-s", "5", "infinity") {
                switch cols[0] {
                case "CPU:":
-                       CPU = strings.ReplaceAll(
-                               strings.Join([]string{cols[1], cols[5], cols[7]}, " "),
-                               "%", "",
-                       )
+                       CPU = strings.ReplaceAll(fmt.Sprintf(
+                               "%s sys:%s int:%s n:%s",
+                               cols[1], cols[5], cols[7], cols[3],
+                       ), "%", "")
                case "Mem:":
                        Mem = strings.ReplaceAll(strings.Join(cols[1:], " "), ",", "")
                case "ARC:":
@@ -89,7 +89,7 @@ func top() {
 
 func iostat() {
        var stats []string
-       for cols := range bg("iostat", "-d", "-w", N, "-x") {
+       for cols := range bg("iostat", "-d", "-w", "1", "-x") {
                if cols[0] == "device" {
                        IOs = strings.Join(stats, " ")
                        stats = nil
@@ -103,7 +103,7 @@ func iostat() {
 }
 
 func netstat() {
-       for cols := range bg("netstat", "-n", N) {
+       for cols := range bg("netstat", "-I", "bridge0", "-n", "1") {
                if _, err := strconv.Atoi(cols[0]); err != nil {
                        continue
                }
@@ -124,6 +124,16 @@ func netstat() {
        }
 }
 
+func freq() {
+       for cols := range bg("sysctl", "-n", "dev.cpu.0.freq") {
+               raw, err := strconv.Atoi(cols[0])
+               if err != nil {
+                       continue
+               }
+               Freq = fmt.Sprintf("%.1fG", float64(raw)/1000)
+       }
+}
+
 func flagfiles() {
        ents, err := os.ReadDir("/tmp/stargrave-flags")
        if err != nil {
@@ -139,9 +149,7 @@ func flagfiles() {
 
 func main() {
        xsetroot := flag.Bool("xsetroot", false, "Call xsetroot")
-       refresh := flag.Uint("refresh", 2, "Refresh interval")
        flag.Parse()
-       N = strconv.Itoa(int(*refresh))
        go func() {
                for {
                        flagfiles()
@@ -149,6 +157,7 @@ func main() {
                }
        }()
        go top()
+       go freq()
        go iostat()
        go netstat()
        var now time.Time
@@ -157,8 +166,8 @@ func main() {
        for {
                now = time.Now()
                status = fmt.Sprintf(
-                       "[%s]  [%s]  [CPU %s]  [%s%s %s ARC]  [%s] %s",
-                       IOs, Net, CPU, Swap, Mem, ARC, Flags,
+                       "[%s]  [%s]  [%s %s]  [%s%s %s ARC]  [%s] %s",
+                       IOs, Net, CPU, Freq, Swap, Mem, ARC, Flags,
                        now.Format("2006-01-02 15:04:05"),
                )
                if *xsetroot {
@@ -167,6 +176,6 @@ func main() {
                } else {
                        fmt.Println(status)
                }
-               time.Sleep(time.Duration(*refresh) * time.Second)
+               time.Sleep(time.Second)
        }
 }