Add system information section to main view
This commit is contained in:
parent
0898ef2fd7
commit
0316fd2007
2 changed files with 163 additions and 9 deletions
|
@ -80,7 +80,7 @@ ApplicationWindow
|
|||
"load15": sysinfo.loads.avg_15,
|
||||
}
|
||||
|
||||
firstpage.updatePage(uptime);
|
||||
firstpage.updatePage(sysinfo, uptime);
|
||||
coverpage.updateCover(uptime);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,70 @@ Page {
|
|||
updateDisplay();
|
||||
}
|
||||
|
||||
function updatePage(uptime) {
|
||||
days.text = uptime.days + " days"
|
||||
time.text = uptime.hours + " h " + uptime.minutes + " min"
|
||||
load1.text = uptime.load1.toFixed(2)
|
||||
load5.text = uptime.load5.toFixed(2)
|
||||
load15.text = uptime.load15.toFixed(2)
|
||||
function updatePage(sysinfo, uptime) {
|
||||
days.text = uptime.days + " days";
|
||||
time.text = uptime.hours + " h " + uptime.minutes + " min";
|
||||
load1.text = uptime.load1.toFixed(2);
|
||||
load5.text = uptime.load5.toFixed(2);
|
||||
load15.text = uptime.load15.toFixed(2);
|
||||
|
||||
|
||||
// Memory bar
|
||||
|
||||
var meminuse = sysinfo.totalram - sysinfo.freeram;
|
||||
|
||||
usedmem.width = (5 * usedmem.parent.width / 6 - Theme.paddingLarge * 2) * (meminuse / sysinfo.totalram);
|
||||
freemem.width = (5 * freemem.parent.width / 6 - Theme.paddingLarge * 2) * (sysinfo.freeram / sysinfo.totalram);
|
||||
|
||||
var usedram = scaleMem((sysinfo.totalram - sysinfo.freeram), sysinfo.mem_unit);
|
||||
var totalram = scaleMem(sysinfo.totalram, sysinfo.mem_unit);
|
||||
|
||||
memlegend.text = usedram[0].toFixed(2) + " " + usedram[1] + "B/"
|
||||
+ totalram[0].toFixed(2) + " " + totalram[1] + "B ("
|
||||
+ (usedram[0] / totalram[0] * 100).toFixed(2) + " %)";
|
||||
|
||||
|
||||
// Swap bar
|
||||
|
||||
var swapinuse = sysinfo.totalswap - sysinfo.freeswap;
|
||||
|
||||
usedswap.width = (5 * usedswap.parent.width / 6 - Theme.paddingLarge * 2) * (swapinuse / sysinfo.totalswap);
|
||||
freeswap.width = (5 * freeswap.parent.width / 6 - Theme.paddingLarge * 2) * (sysinfo.freeswap / sysinfo.totalswap);
|
||||
|
||||
var usedswap_scale = scaleMem((sysinfo.totalswap - sysinfo.freeswap), sysinfo.mem_unit);
|
||||
var totalswap_scale = scaleMem(sysinfo.totalswap, sysinfo.mem_unit);
|
||||
|
||||
swaplegend.text = usedswap_scale[0].toFixed(2) + " " + usedswap_scale[1] + "B/"
|
||||
+ totalswap_scale[0].toFixed(2) + " " + totalswap_scale[1] + "B ("
|
||||
+ (usedswap_scale[0] / totalswap_scale[0] * 100).toFixed(2) + " %)";
|
||||
|
||||
|
||||
// Processes amount
|
||||
|
||||
procs.text = sysinfo.procs + " processes";
|
||||
}
|
||||
|
||||
// Scale memory sizes to human readable bytes according to mem_unit
|
||||
// Return memory size in bytes and prefix
|
||||
function scaleMem(mem, mem_unit) {
|
||||
var scaled = mem * mem_unit;
|
||||
|
||||
var size_factor = 1024;
|
||||
var size_units = ['', 'ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
|
||||
|
||||
var remainder = 0;
|
||||
|
||||
for (var i = 0; i < size_units.length; ++i) {
|
||||
remainder = scaled / Math.pow(size_factor, i);
|
||||
|
||||
if (remainder < size_factor) {
|
||||
return [remainder, size_units[i]];
|
||||
}
|
||||
}
|
||||
|
||||
// If we have passed yottabytes in memory size, just rudely display as
|
||||
// YB.
|
||||
return [remainder, size_units[size_units.length - 1]];
|
||||
}
|
||||
|
||||
// To enable PullDownMenu, place our content in a SilicaFlickable
|
||||
|
@ -57,9 +115,9 @@ Page {
|
|||
// of the page, followed by our content.
|
||||
Column {
|
||||
id: column
|
||||
|
||||
width: page.width
|
||||
spacing: Theme.paddingLarge
|
||||
spacing: Theme.paddingMedium
|
||||
|
||||
PageHeader {
|
||||
title: "Uptime"
|
||||
}
|
||||
|
@ -119,6 +177,7 @@ Page {
|
|||
width: 3 * parent.width / 12
|
||||
horizontalAlignment: Qt.AlignLeft
|
||||
}
|
||||
|
||||
Label {
|
||||
text: "15"
|
||||
color: Theme.secondaryColor
|
||||
|
@ -134,6 +193,101 @@ Page {
|
|||
horizontalAlignment: Qt.AlignLeft
|
||||
}
|
||||
}
|
||||
|
||||
PageHeader {
|
||||
title: "System information"
|
||||
}
|
||||
|
||||
Item {
|
||||
height: Theme.fontSizeLarge
|
||||
width: parent.width
|
||||
|
||||
Label {
|
||||
id: memlabel
|
||||
text: "Mem"
|
||||
color: Theme.secondaryColor
|
||||
width: parent.width / 6
|
||||
horizontalAlignment: Qt.AlignRight
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.left: memlabel.right
|
||||
anchors.leftMargin: Theme.paddingLarge
|
||||
id: usedmem
|
||||
height: Theme.fontSizeLarge
|
||||
width: 0
|
||||
color: Theme.secondaryColor
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.left: usedmem.right
|
||||
id: freemem
|
||||
height: Theme.fontSizeLarge
|
||||
width: 0
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
|
||||
Label {
|
||||
anchors.left: memlabel.right
|
||||
anchors.leftMargin: Theme.paddingLarge
|
||||
id: memlegend
|
||||
color: Theme.primaryColor
|
||||
width: 5 * parent.width / 6 - Theme.paddingLarge * 2
|
||||
horizontalAlignment: Qt.AlignCenter
|
||||
|
||||
// Overlay the label on the bar
|
||||
z: 1
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
height: Theme.fontSizeLarge
|
||||
width: parent.width
|
||||
|
||||
Label {
|
||||
id: swaplabel
|
||||
text: "Swap"
|
||||
color: Theme.secondaryColor
|
||||
width: parent.width / 6
|
||||
horizontalAlignment: Qt.AlignRight
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.left: swaplabel.right
|
||||
anchors.leftMargin: Theme.paddingLarge
|
||||
id: usedswap
|
||||
height: Theme.fontSizeLarge
|
||||
width: 0
|
||||
color: Theme.secondaryColor
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.left: usedswap.right
|
||||
id: freeswap
|
||||
height: Theme.fontSizeLarge
|
||||
width: 0
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
|
||||
Label {
|
||||
anchors.left: swaplabel.right
|
||||
anchors.leftMargin: Theme.paddingLarge
|
||||
id: swaplegend
|
||||
color: Theme.primaryColor
|
||||
width: 5 * parent.width / 6 - Theme.paddingLarge * 2
|
||||
horizontalAlignment: Qt.AlignCenter
|
||||
|
||||
// Overlay the label on the bar
|
||||
z: 1
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
id: procs
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue