Skip to content

Commit

Permalink
fixes for ubuntu 20
Browse files Browse the repository at this point in the history
  • Loading branch information
kent007 committed Sep 25, 2020
1 parent a492bfc commit 9333d18
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
22 changes: 1 addition & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
## linux-inspect

[![Go Report Card](https://goreportcard.com/badge/github.com/gyuho/linux-inspect?style=flat-square)](https://goreportcard.com/report/github.com/gyuho/linux-inspect)
[![Build Status](https://img.shields.io/travis/gyuho/linux-inspect.svg?style=flat-square)](https://travis-ci.org/gyuho/linux-inspect)
[![Build Status](https://semaphoreci.com/api/v1/gyuho/linux-inspect/branches/master/shields_badge.svg)](https://semaphoreci.com/gyuho/linux-inspect)
[![Godoc](https://img.shields.io/badge/godoc-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/gyuho/linux-inspect)

linux-inspect implements various Linux inspecting utilities.

```
go get -v github.com/gyuho/linux-inspect/cmd/linux-inspect
```

```
Usage:
linux-inspect [command]
Available Commands:
ds Inspects '/proc/diskstats'
ns Inspects '/proc/net/dev'
ps Inspects '/proc/$PID/status', 'top' command output
ss Inspects '/proc/net/tcp,tcp6'
```
Fork of this module with fixes for using top(1) parser on my Ubuntu 20
6 changes: 3 additions & 3 deletions inspect/proc_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ func ReadCSV(fpath string) (*CSV, error) {
Threads: threads,
VoluntaryCtxtSwitches: volCtxNum,
NonvoluntaryCtxtSwitches: nonVolCtxNum,
CPUNum: cpuNum,
VMRSSNum: vmRssNum,
VMSizeNum: vmSizeNum,
CPUNum: cpuNum,
VMRSSNum: vmRssNum,
VMSizeNum: vmSizeNum,
},

LoadAvg: proc.LoadAvg{
Expand Down
28 changes: 18 additions & 10 deletions top/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,19 @@ const (
command_output_row_idx_command
)

//anything that might appear in the lines above the actual top output
var bytesToSkip = [][]byte{
{116, 111, 112, 32, 45}, // 'top -'
{84, 97, 115, 107, 115, 58, 32}, // 'Tasks: '
{37, 67, 112, 117, 40, 115, 41, 58, 32}, // '%Cpu(s): '
{67, 112, 117, 40, 115, 41, 58, 32}, // 'Cpu(s): '
{75, 105, 66, 32, 77, 101, 109, 32, 58, 32}, // 'KiB Mem : '
{75, 105, 66, 32, 83, 119, 97, 112, 58, 32}, // 'KiB Swap: '
{77, 101, 109, 58, 32}, // 'Mem: '
{83, 119, 97, 112, 58, 32}, // 'Swap: '
{80, 73, 68, 32}, // 'PID '
[]byte("top -"),
[]byte("Tasks: "),
[]byte("%Cpu(s): "),
[]byte("Cpu(s): "),
[]byte("KiB Mem :"),
[]byte("KiB Swap :"),
[]byte("Mem: "),
[]byte("Swap: "),
[]byte("MiB Mem :"),
[]byte("MiB Swap:"),
[]byte("PID "),
}

func topRowToSkip(data []byte) bool {
Expand All @@ -131,8 +134,13 @@ func Parse(s string) ([]Row, error) {
}

row := strings.Fields(strings.TrimSpace(line))
if len(row) != len(Headers) {
if len(row) < len(Headers) {
//too short
return nil, fmt.Errorf("unexpected row column number %v (expected %v)", row, Headers)
} else if len(row) > len(Headers) {
//command had some spaces in it that got cut up into separate commands by the parser
command := strings.Join(row[len(Headers)-1:], " ")
row[len(row)-1] = command
}
rows = append(rows, row)
}
Expand Down

0 comments on commit 9333d18

Please sign in to comment.