Improve process table output.
Use pretty prints, but maintain sorting capabilities.
This commit is contained in:
parent
a9f4b691c1
commit
1ca29f8f20
@ -171,15 +171,15 @@ type RequestOptions struct {
|
||||
}
|
||||
|
||||
type ProcessInfo struct {
|
||||
User string `json:"user"`
|
||||
Pid int `json:"pid"`
|
||||
Ppid int `json:"parent_pid"`
|
||||
StartTime string `json:"start_time"`
|
||||
PercentCpu string `json:"percent_cpu"`
|
||||
PercentMemory string `json:"percent_mem"`
|
||||
RSS string `json:"rss"`
|
||||
VirtualSize string `json:"virtual_size"`
|
||||
Status string `json:"status"`
|
||||
RunningTime string `json:"running_time"`
|
||||
Cmd string `json:"cmd"`
|
||||
User string `json:"user"`
|
||||
Pid int `json:"pid"`
|
||||
Ppid int `json:"parent_pid"`
|
||||
StartTime string `json:"start_time"`
|
||||
PercentCpu float32 `json:"percent_cpu"`
|
||||
PercentMemory float32 `json:"percent_mem"`
|
||||
RSS uint64 `json:"rss"`
|
||||
VirtualSize uint64 `json:"virtual_size"`
|
||||
Status string `json:"status"`
|
||||
RunningTime string `json:"running_time"`
|
||||
Cmd string `json:"cmd"`
|
||||
}
|
||||
|
@ -155,16 +155,32 @@ func (c *containerData) GetProcessList() ([]v2.ProcessInfo, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid ppid %q: %v", fields[2], err)
|
||||
}
|
||||
percentCpu, err := strconv.ParseFloat(fields[4], 32)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid cpu percent %q: %v", fields[4], err)
|
||||
}
|
||||
percentMem, err := strconv.ParseFloat(fields[5], 32)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid memory percent %q: %v", fields[5], err)
|
||||
}
|
||||
rss, err := strconv.ParseUint(fields[6], 0, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid rss %q: %v", fields[6], err)
|
||||
}
|
||||
vs, err := strconv.ParseUint(fields[7], 0, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid virtual size %q: %v", fields[7], err)
|
||||
}
|
||||
if isRoot || pidMap[pid] == true {
|
||||
processes = append(processes, v2.ProcessInfo{
|
||||
User: fields[0],
|
||||
Pid: pid,
|
||||
Ppid: ppid,
|
||||
StartTime: fields[3],
|
||||
PercentCpu: fields[4],
|
||||
PercentMemory: fields[5],
|
||||
RSS: fields[6],
|
||||
VirtualSize: fields[7],
|
||||
PercentCpu: float32(percentCpu),
|
||||
PercentMemory: float32(percentMem),
|
||||
RSS: rss,
|
||||
VirtualSize: vs,
|
||||
Status: fields[8],
|
||||
RunningTime: fields[9],
|
||||
Cmd: strings.Join(fields[10:], " "),
|
||||
|
@ -25,10 +25,9 @@ function humanize(num, size, units) {
|
||||
|
||||
// Following the IEC naming convention
|
||||
function humanizeIEC(num) {
|
||||
var ret = humanize(num, 1024, ["TiB", "GiB", "MiB", "KiB", "Bytes"]);
|
||||
var ret = humanize(num, 1024, ["TiB", "GiB", "MiB", "KiB", "B"]);
|
||||
return ret[0].toFixed(2) + " " + ret[1];
|
||||
}
|
||||
|
||||
// Following the Metric naming convention
|
||||
function humanizeMetric(num) {
|
||||
var ret = humanize(num, 1000, ["TB", "GB", "MB", "KB", "Bytes"]);
|
||||
@ -428,7 +427,7 @@ function drawFileSystemUsage(machineInfo, stats) {
|
||||
|
||||
function drawProcesses(processInfo) {
|
||||
var titles = ["User", "PID", "PPID", "Start Time", "CPU %", "MEM %", "RSS", "Virtual Size", "Status", "Running Time", "Command"];
|
||||
var titleTypes = ['string', 'number', 'number', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string'];
|
||||
var titleTypes = ['string', 'number', 'number', 'string', 'number', 'number', 'number', 'number', 'string', 'string', 'string'];
|
||||
var data = []
|
||||
for (var i = 1; i < processInfo.length; i++) {
|
||||
var elements = [];
|
||||
@ -436,10 +435,10 @@ function drawProcesses(processInfo) {
|
||||
elements.push(processInfo[i].pid);
|
||||
elements.push(processInfo[i].parent_pid);
|
||||
elements.push(processInfo[i].start_time);
|
||||
elements.push(processInfo[i].percent_cpu);
|
||||
elements.push(processInfo[i].percent_mem);
|
||||
elements.push(processInfo[i].rss);
|
||||
elements.push(processInfo[i].virtual_size);
|
||||
elements.push({ v:processInfo[i].percent_cpu, f:processInfo[i].percent_cpu.toFixed(2)});
|
||||
elements.push({ v:processInfo[i].percent_mem, f:processInfo[i].percent_mem.toFixed(2)});
|
||||
elements.push({ v:processInfo[i].rss, f:humanizeIEC(processInfo[i].rss)});
|
||||
elements.push({ v:processInfo[i].virtual_size, f:humanizeIEC(processInfo[i].virtual_size)});
|
||||
elements.push(processInfo[i].status);
|
||||
elements.push(processInfo[i].running_time);
|
||||
elements.push(processInfo[i].cmd);
|
||||
|
Loading…
Reference in New Issue
Block a user