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 {
|
type ProcessInfo struct {
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
Pid int `json:"pid"`
|
Pid int `json:"pid"`
|
||||||
Ppid int `json:"parent_pid"`
|
Ppid int `json:"parent_pid"`
|
||||||
StartTime string `json:"start_time"`
|
StartTime string `json:"start_time"`
|
||||||
PercentCpu string `json:"percent_cpu"`
|
PercentCpu float32 `json:"percent_cpu"`
|
||||||
PercentMemory string `json:"percent_mem"`
|
PercentMemory float32 `json:"percent_mem"`
|
||||||
RSS string `json:"rss"`
|
RSS uint64 `json:"rss"`
|
||||||
VirtualSize string `json:"virtual_size"`
|
VirtualSize uint64 `json:"virtual_size"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
RunningTime string `json:"running_time"`
|
RunningTime string `json:"running_time"`
|
||||||
Cmd string `json:"cmd"`
|
Cmd string `json:"cmd"`
|
||||||
}
|
}
|
||||||
|
@ -155,16 +155,32 @@ func (c *containerData) GetProcessList() ([]v2.ProcessInfo, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid ppid %q: %v", fields[2], err)
|
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 {
|
if isRoot || pidMap[pid] == true {
|
||||||
processes = append(processes, v2.ProcessInfo{
|
processes = append(processes, v2.ProcessInfo{
|
||||||
User: fields[0],
|
User: fields[0],
|
||||||
Pid: pid,
|
Pid: pid,
|
||||||
Ppid: ppid,
|
Ppid: ppid,
|
||||||
StartTime: fields[3],
|
StartTime: fields[3],
|
||||||
PercentCpu: fields[4],
|
PercentCpu: float32(percentCpu),
|
||||||
PercentMemory: fields[5],
|
PercentMemory: float32(percentMem),
|
||||||
RSS: fields[6],
|
RSS: rss,
|
||||||
VirtualSize: fields[7],
|
VirtualSize: vs,
|
||||||
Status: fields[8],
|
Status: fields[8],
|
||||||
RunningTime: fields[9],
|
RunningTime: fields[9],
|
||||||
Cmd: strings.Join(fields[10:], " "),
|
Cmd: strings.Join(fields[10:], " "),
|
||||||
|
@ -25,10 +25,9 @@ function humanize(num, size, units) {
|
|||||||
|
|
||||||
// Following the IEC naming convention
|
// Following the IEC naming convention
|
||||||
function humanizeIEC(num) {
|
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];
|
return ret[0].toFixed(2) + " " + ret[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Following the Metric naming convention
|
// Following the Metric naming convention
|
||||||
function humanizeMetric(num) {
|
function humanizeMetric(num) {
|
||||||
var ret = humanize(num, 1000, ["TB", "GB", "MB", "KB", "Bytes"]);
|
var ret = humanize(num, 1000, ["TB", "GB", "MB", "KB", "Bytes"]);
|
||||||
@ -428,7 +427,7 @@ function drawFileSystemUsage(machineInfo, stats) {
|
|||||||
|
|
||||||
function drawProcesses(processInfo) {
|
function drawProcesses(processInfo) {
|
||||||
var titles = ["User", "PID", "PPID", "Start Time", "CPU %", "MEM %", "RSS", "Virtual Size", "Status", "Running Time", "Command"];
|
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 = []
|
var data = []
|
||||||
for (var i = 1; i < processInfo.length; i++) {
|
for (var i = 1; i < processInfo.length; i++) {
|
||||||
var elements = [];
|
var elements = [];
|
||||||
@ -436,10 +435,10 @@ function drawProcesses(processInfo) {
|
|||||||
elements.push(processInfo[i].pid);
|
elements.push(processInfo[i].pid);
|
||||||
elements.push(processInfo[i].parent_pid);
|
elements.push(processInfo[i].parent_pid);
|
||||||
elements.push(processInfo[i].start_time);
|
elements.push(processInfo[i].start_time);
|
||||||
elements.push(processInfo[i].percent_cpu);
|
elements.push({ v:processInfo[i].percent_cpu, f:processInfo[i].percent_cpu.toFixed(2)});
|
||||||
elements.push(processInfo[i].percent_mem);
|
elements.push({ v:processInfo[i].percent_mem, f:processInfo[i].percent_mem.toFixed(2)});
|
||||||
elements.push(processInfo[i].rss);
|
elements.push({ v:processInfo[i].rss, f:humanizeIEC(processInfo[i].rss)});
|
||||||
elements.push(processInfo[i].virtual_size);
|
elements.push({ v:processInfo[i].virtual_size, f:humanizeIEC(processInfo[i].virtual_size)});
|
||||||
elements.push(processInfo[i].status);
|
elements.push(processInfo[i].status);
|
||||||
elements.push(processInfo[i].running_time);
|
elements.push(processInfo[i].running_time);
|
||||||
elements.push(processInfo[i].cmd);
|
elements.push(processInfo[i].cmd);
|
||||||
|
Loading…
Reference in New Issue
Block a user