Skip to content

Commit

Permalink
bumped to v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmittag committed Jun 25, 2022
1 parent 8b47206 commit deb7f17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
39 changes: 22 additions & 17 deletions l0la.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"
)

const Version = "v0.1.1"
const Version = "v0.1.2"

func Watch(pid int) {
lines := make([]io.Writer, 0)
Expand All @@ -25,22 +25,27 @@ func Watch(pid int) {
pad := 26
s := NewSpinnerAnim()

for {
fmt.Fprint(lines[0], Logo()+"\n")
fmt.Fprintf(lines[0], "%s watching pid: %v %s \n", s.Next(), pid, Pidgrepstatus(pid))
fmt.Fprintf(lines[0], "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n")
fmt.Fprintf(lines[0], "┃ TCP conns ┃ %s ┃\n", Red(LPad(pad, FGroup(Conngrep(pid)))))
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
fmt.Fprintf(lines[0], "┃ Open files ┃ %s ┃\n", Yellow(LPad(pad, FGroup(Filegrep(pid)))))
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
fmt.Fprintf(lines[0], "┃ Threads ┃ %s ┃\n", Blue(LPad(pad, FGroup(Threadgrep(pid)))))
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
fmt.Fprintf(lines[0], "┃ RSS bytes ┃ %s ┃\n", Gray(8, LPad(pad, FGroup(Memgrep(pid)))))
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
fmt.Fprintf(lines[0], "┃ CPU percent ┃ %s ┃\n", Magenta(LPad(pad, Cpugrep(pid))))
fmt.Fprintf(lines[0], "┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n")
l0.Flush()
time.Sleep(time.Millisecond * 500)
if PidgrepActive(pid) {
for {
fmt.Fprint(lines[0], Logo()+"\n")
fmt.Fprintf(lines[0], "%s watching pid: %v %s \n", s.Next(), pid, Pidgrepstatus(pid))
fmt.Fprintf(lines[0], "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n")
fmt.Fprintf(lines[0], "┃ TCP conns ┃ %s ┃\n", Red(LPad(pad, FGroup(Conngrep(pid)))))
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
fmt.Fprintf(lines[0], "┃ Open files ┃ %s ┃\n", Yellow(LPad(pad, FGroup(Filegrep(pid)))))
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
fmt.Fprintf(lines[0], "┃ Threads ┃ %s ┃\n", Blue(LPad(pad, FGroup(Threadgrep(pid)))))
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
fmt.Fprintf(lines[0], "┃ RSS bytes ┃ %s ┃\n", Gray(8, LPad(pad, FGroup(Memgrep(pid)))))
fmt.Fprintf(lines[0], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n")
fmt.Fprintf(lines[0], "┃ CPU percent ┃ %s ┃\n", Magenta(LPad(pad, Cpugrep(pid))))
fmt.Fprintf(lines[0], "┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n")
l0.Flush()
time.Sleep(time.Millisecond * 500)
}
} else {
fmt.Printf(Logo())
fmt.Printf("\n%d not a pid, insufficient privileges or dead?\n", pid)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pidgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (

const pidgrepcmd = "ps -p %d | grep -v PID | wc -l"

func Pidgrep(pid int) bool {
func PidgrepActive(pid int) bool {
cmd := fmt.Sprintf(pidgrepcmd, pid)
stdout, _, _ := Shellout(cmd)
r, _ := strconv.Atoi(strings.TrimSpace(stdout))
return r == 1
}

func Pidgrepstatus(pid int) string {
if Pidgrep(pid) {
if PidgrepActive(pid) {
return "[ACTIVE]"
} else {
return "[DEAD?]"
Expand Down

0 comments on commit deb7f17

Please sign in to comment.