14 "github.com/dustin/go-humanize"
18 MyPID string = strconv.Itoa(os.Getpid())
28 func piper(c chan []string, name string, args ...string) error {
29 cmd := exec.Command(name, args...)
30 r, err := cmd.StdoutPipe()
38 scanner := bufio.NewScanner(r)
40 cols := strings.Fields(scanner.Text())
45 if err = scanner.Err(); err != nil {
53 func bg(cmd string, args ...string) chan []string {
54 c := make(chan []string)
57 err := piper(c, cmd, args...)
59 log.Println("error:", cmd, ":", err)
61 time.Sleep(time.Second)
68 for cols := range bg("top", "-b", "-d", "infinity", "-p", MyPID, "-s", "5", "infinity") {
71 CPU = strings.ReplaceAll(
72 fmt.Sprintf("%s sys:%s int:%s", cols[1], cols[5], cols[7]),
76 Mem = strings.ReplaceAll(strings.Join(cols[1:], " "), ",", "")
80 if len(cols) >= 5 && cols[4] == "Used," {
81 Swap = cols[3] + " Swap "
91 for cols := range bg("iostat", "-d", "-w", "1", "-x") {
92 if cols[0] == "device" {
93 IOs = strings.Join(stats, " ")
97 if len(cols) < 4 || (cols[1] == "0" && cols[2] == "0") {
100 stats = append(stats, fmt.Sprintf("%s:%s/%s", cols[0], cols[1], cols[2]))
105 for cols := range bg("netstat", "-I", "bridge0", "-n", "1") {
106 if _, err := strconv.Atoi(cols[0]); err != nil {
109 ibps, err := strconv.Atoi(cols[3])
113 obps, err := strconv.Atoi(cols[6])
120 humanize.IBytes(uint64(ibps)),
121 humanize.IBytes(uint64(obps)),
127 ents, err := os.ReadDir("/tmp/stargrave-flags")
132 fs := make([]string, 0, len(ents))
133 for _, ent := range ents {
134 fs = append(fs, ent.Name())
136 Flags = strings.Join(fs, " ")
140 xsetroot := flag.Bool("xsetroot", false, "Call xsetroot")
145 time.Sleep(20 * time.Second)
156 status = fmt.Sprintf(
157 "[%s] [%s] [%s] [%s%s %s ARC] [%s] %s",
158 IOs, Net, CPU, Swap, Mem, ARC, Flags,
159 now.Format("2006-01-02 15:04:05"),
162 cmd = exec.Command("xsetroot", "-name", status)
167 time.Sleep(time.Second)