Compare commits
3 commits
d10c9e7a65
...
4a516cbed8
Author | SHA1 | Date | |
---|---|---|---|
KemoNine | 4a516cbed8 | ||
KemoNine | 494ac4a1e3 | ||
KemoNine | 55459e42f0 |
187
cmd/ui/ui.go
187
cmd/ui/ui.go
|
@ -1,18 +1,23 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eiannone/keyboard"
|
"github.com/eiannone/keyboard"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
"github.com/guillermo/go.procmeminfo"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
CMD_FINDMNT = "/usr/bin/findmnt"
|
||||||
CMD_FIM = "/usr/local/bin/pf-fim.sh"
|
CMD_FIM = "/usr/local/bin/pf-fim.sh"
|
||||||
SLIDESHOW_INTERVAL = 300 * time.Second
|
SLIDESHOW_INTERVAL = 300 * time.Second
|
||||||
)
|
)
|
||||||
|
@ -99,24 +104,178 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Run fim
|
// Run fim
|
||||||
if err := fim.Run(); err != nil {
|
// if err := fim.Run(); err != nil {
|
||||||
// Unwrap the error a bit so we can find out if a signal killed fim or something else
|
// // Unwrap the error a bit so we can find out if a signal killed fim or something else
|
||||||
// An exit code of -1 means the program didn't exit in time or was terminated by a signal (per the docs)
|
// // An exit code of -1 means the program didn't exit in time or was terminated by a signal (per the docs)
|
||||||
if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() != -1 {
|
// if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() != -1 {
|
||||||
log.Fatalf("Error running fim : %s", err)
|
// log.Fatalf("Error running fim : %s", err)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Stop fim slideshow advancing go routine
|
// Stop fim slideshow advancing go routine
|
||||||
close(stop_ticker)
|
close(stop_ticker)
|
||||||
|
|
||||||
|
// Memory info for status panel
|
||||||
|
meminfo := &procmeminfo.MemInfo{}
|
||||||
|
err = meminfo.Update()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting memory info : %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Network interfaces for status panel
|
||||||
|
ifaces, err := net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting netork interfaces : %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disk use
|
||||||
|
findmntOut, _ := exec.Command(CMD_FINDMNT, "-n", "-l",
|
||||||
|
"-o", "TARGET,USE%",
|
||||||
|
"-t", "ext4,exfat,vfat,btrfs,zfs,xfs").Output()
|
||||||
|
filesystems := strings.Split(strings.Trim(string(findmntOut), "\n"), "\n")
|
||||||
|
|
||||||
// Run config UI when slideshow stops
|
// Run config UI when slideshow stops
|
||||||
app := tview.NewApplication()
|
app := tview.NewApplication()
|
||||||
frame := tview.NewFrame(tview.NewBox().SetBackgroundColor(tcell.ColorBlack)).
|
|
||||||
SetBorders(2, 2, 2, 2, 4, 4).
|
// Header
|
||||||
AddText("PiFrame", true, tview.AlignCenter, tcell.ColorWhite).
|
headerTitle := tview.NewTextView().
|
||||||
AddText("Configuration Utility", true, tview.AlignCenter, tcell.ColorRed)
|
SetText("PiFrame").
|
||||||
if err := app.SetRoot(frame, true).EnableMouse(true).Run(); err != nil {
|
SetTextAlign(tview.AlignCenter).
|
||||||
log.Fatalf("Error running UI : %s", err)
|
SetTextColor(tcell.ColorAqua)
|
||||||
|
|
||||||
|
headerSubTitle := tview.NewTextView().
|
||||||
|
SetText("Management Utility").
|
||||||
|
SetTextAlign(tview.AlignCenter).
|
||||||
|
SetTextColor(tcell.ColorSilver)
|
||||||
|
header := tview.NewFlex().
|
||||||
|
SetDirection(tview.FlexRow)
|
||||||
|
header.AddItem(headerTitle, 0, 1, false).
|
||||||
|
AddItem(headerSubTitle, 0, 1, false)
|
||||||
|
|
||||||
|
// Footer fields (Left Column)
|
||||||
|
exitButton := tview.NewButton("Exit").
|
||||||
|
SetSelectedFunc(func() {
|
||||||
|
app.Stop()
|
||||||
|
})
|
||||||
|
exitButton.SetLabelColor(tcell.ColorBlack).
|
||||||
|
SetBorder(true).
|
||||||
|
SetBorderColor(tcell.ColorBlack).
|
||||||
|
SetBackgroundColor(tcell.ColorGreen).
|
||||||
|
SetRect(0, 0, 22, 3)
|
||||||
|
|
||||||
|
rebootButton := tview.NewButton("Reboot").
|
||||||
|
SetSelectedFunc(func() {
|
||||||
|
app.Stop()
|
||||||
|
})
|
||||||
|
rebootButton.SetLabelColor(tcell.ColorBlack).
|
||||||
|
SetBorder(true).
|
||||||
|
SetBorderColor(tcell.ColorBlack).
|
||||||
|
SetBackgroundColor(tcell.ColorYellow).
|
||||||
|
SetRect(0, 0, 22, 3)
|
||||||
|
|
||||||
|
powerOffButton := tview.NewButton("Power Off").
|
||||||
|
SetSelectedFunc(func() {
|
||||||
|
app.Stop()
|
||||||
|
})
|
||||||
|
powerOffButton.SetLabelColor(tcell.ColorBlack).
|
||||||
|
SetBorder(true).
|
||||||
|
SetBorderColor(tcell.ColorBlack).
|
||||||
|
SetBackgroundColor(tcell.ColorRed).
|
||||||
|
SetRect(0, 0, 22, 3)
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
footer := tview.NewFlex()
|
||||||
|
footer.AddItem(exitButton, 0, 1, false).
|
||||||
|
AddItem(rebootButton, 0, 1, false).
|
||||||
|
AddItem(powerOffButton, 0, 1, false)
|
||||||
|
|
||||||
|
// Setup menu
|
||||||
|
menu := tview.NewFlex().
|
||||||
|
SetDirection(tview.FlexRow)
|
||||||
|
menu.SetTitle("Menu").
|
||||||
|
SetBorder(true).
|
||||||
|
SetTitleColor(tcell.ColorAqua)
|
||||||
|
|
||||||
|
// Setup main panel (Center column)
|
||||||
|
main := tview.NewFlex().
|
||||||
|
SetDirection(tview.FlexRow)
|
||||||
|
main.SetTitle("").
|
||||||
|
SetBorder(true)
|
||||||
|
|
||||||
|
// Side bar fields
|
||||||
|
sideBarMemoryTitle := tview.NewTextView().
|
||||||
|
SetText("Memory Use (Mb)").
|
||||||
|
SetTextColor(tcell.ColorYellow)
|
||||||
|
divisor := math.Pow(1024.0, 2.0)
|
||||||
|
sideBarMemoryStats := tview.NewTextView().
|
||||||
|
SetText(fmt.Sprintf(" %.1f / %.1f",
|
||||||
|
float64(meminfo.Used())/divisor,
|
||||||
|
float64(meminfo.Total())/divisor))
|
||||||
|
sideBarSwapTitle := tview.NewTextView().
|
||||||
|
SetText("Swap Use").
|
||||||
|
SetTextColor(tcell.ColorYellow)
|
||||||
|
sideBarSwapStats := tview.NewTextView().
|
||||||
|
SetText(fmt.Sprintf(" %d%%", meminfo.Swap()))
|
||||||
|
sideBarFilesystemTitle := tview.NewTextView().
|
||||||
|
SetText("Disk Use").
|
||||||
|
SetTextColor(tcell.ColorYellow)
|
||||||
|
var sideBarFilesystems []*tview.TextView
|
||||||
|
for _, i := range filesystems {
|
||||||
|
filesystemAsTextView := tview.NewTextView().
|
||||||
|
SetText(fmt.Sprintf(" %s", i))
|
||||||
|
sideBarFilesystems = append(sideBarFilesystems, filesystemAsTextView)
|
||||||
|
}
|
||||||
|
sideBarIPAddressesTitle := tview.NewTextView().
|
||||||
|
SetText("IP Addresses").
|
||||||
|
SetTextColor(tcell.ColorYellow)
|
||||||
|
var sideBarIPAddresses []*tview.TextView
|
||||||
|
for _, i := range ifaces {
|
||||||
|
addrs, err := i.Addrs()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting interface addresses : %s", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, a := range addrs {
|
||||||
|
ipAsTextView := tview.NewTextView().
|
||||||
|
SetText(fmt.Sprintf(" %v : %s", i.Name, a.String()))
|
||||||
|
sideBarIPAddresses = append(sideBarIPAddresses, ipAsTextView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup side bar (Right column)
|
||||||
|
sideBar := tview.NewFlex().
|
||||||
|
SetDirection(tview.FlexRow)
|
||||||
|
sideBar.SetTitle("System Info").
|
||||||
|
SetBorder(true).
|
||||||
|
SetTitleColor(tcell.ColorAqua)
|
||||||
|
sideBar.AddItem(sideBarMemoryTitle, 1, 1, false)
|
||||||
|
sideBar.AddItem(sideBarMemoryStats, 1, 1, false)
|
||||||
|
sideBar.AddItem(sideBarSwapTitle, 1, 1, false)
|
||||||
|
sideBar.AddItem(sideBarSwapStats, 1, 1, false)
|
||||||
|
sideBar.AddItem(sideBarFilesystemTitle, 1, 1, false)
|
||||||
|
for _, filesystemAsTextView := range sideBarFilesystems {
|
||||||
|
sideBar.AddItem(filesystemAsTextView, 1, 1, false)
|
||||||
|
}
|
||||||
|
sideBar.AddItem(sideBarIPAddressesTitle, 1, 1, false)
|
||||||
|
for _, ipAsTextView := range sideBarIPAddresses {
|
||||||
|
sideBar.AddItem(ipAsTextView, 1, 1, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main UI
|
||||||
|
grid := tview.NewGrid().
|
||||||
|
SetRows(2, 0, 4).
|
||||||
|
SetColumns(25, 50, 50).
|
||||||
|
SetBorders(true).
|
||||||
|
AddItem(header, 0, 0, 1, 3, 0, 0, false).
|
||||||
|
AddItem(footer, 2, 0, 1, 3, 0, 0, false)
|
||||||
|
|
||||||
|
grid.AddItem(menu, 1, 0, 1, 1, 0, 100, true).
|
||||||
|
AddItem(main, 1, 1, 1, 1, 0, 100, false).
|
||||||
|
AddItem(sideBar, 1, 2, 1, 1, 0, 100, false)
|
||||||
|
|
||||||
|
// Show UI and panic if there are any errors
|
||||||
|
if err := app.SetRoot(grid, true).EnableMouse(false).Run(); err != nil {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -11,6 +11,8 @@ require (
|
||||||
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807
|
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807
|
||||||
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||||
github.com/gdamore/tcell v1.4.0
|
github.com/gdamore/tcell v1.4.0
|
||||||
|
github.com/guillermo/go.procmeminfo v0.0.0-20131127224636-be4355a9fb0e
|
||||||
|
github.com/mackerelio/go-osstat v0.1.0 // indirect
|
||||||
github.com/rivo/tview v0.0.0-20200818120338-53d50e499bf9
|
github.com/rivo/tview v0.0.0-20200818120338-53d50e499bf9
|
||||||
gopkg.in/fsnotify.v1 v1.4.7 // indirect
|
gopkg.in/fsnotify.v1 v1.4.7 // indirect
|
||||||
)
|
)
|
||||||
|
|
5
go.sum
5
go.sum
|
@ -18,9 +18,13 @@ github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo
|
||||||
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
|
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
|
||||||
github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
|
github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
|
||||||
github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
|
github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
|
||||||
|
github.com/guillermo/go.procmeminfo v0.0.0-20131127224636-be4355a9fb0e h1:/6/OurM62Ddm8CR8PveE0a+ql2mL+ycAhOwd563kpdg=
|
||||||
|
github.com/guillermo/go.procmeminfo v0.0.0-20131127224636-be4355a9fb0e/go.mod h1:TQrLAmkOSnZ4g1eFORtCfTEbFuVZD0Zm55vdnrilBaw=
|
||||||
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
|
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
|
||||||
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
|
github.com/mackerelio/go-osstat v0.1.0 h1:e57QHeHob8kKJ5FhcXGdzx5O6Ktuc5RHMDIkeqhgkFA=
|
||||||
|
github.com/mackerelio/go-osstat v0.1.0/go.mod h1:1K3NeYLhMHPvzUu+ePYXtoB58wkaRpxZsGClZBJyIFw=
|
||||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
|
@ -29,6 +33,7 @@ github.com/rivo/tview v0.0.0-20200818120338-53d50e499bf9 h1:csnip7QsoiE2Ee0RkELN
|
||||||
github.com/rivo/tview v0.0.0-20200818120338-53d50e499bf9/go.mod h1:xV4Aw4WIX8cmhg71U7MUHBdpIQ7zSEXdRruGHLaEAOc=
|
github.com/rivo/tview v0.0.0-20200818120338-53d50e499bf9/go.mod h1:xV4Aw4WIX8cmhg71U7MUHBdpIQ7zSEXdRruGHLaEAOc=
|
||||||
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
golang.org/x/sys v0.0.0-20190410235845-0ad05ae3009d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0=
|
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0=
|
||||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|
28
vendor/github.com/guillermo/go.procmeminfo/README.md
generated
vendored
Normal file
28
vendor/github.com/guillermo/go.procmeminfo/README.md
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# procmeminfo
|
||||||
|
|
||||||
|
[![GoDoc](http://godoc.org/github.com/guillermo/go.procmeminfo?status.png)](http://godoc.org/github.com/guillermo/go.procmeminfo)
|
||||||
|
|
||||||
|
Package procmeminfo provides an interface for /proc/meminfo
|
||||||
|
|
||||||
|
```golang
|
||||||
|
import "github.com/guillermo/go.procmeminfo"
|
||||||
|
meminfo := &procmeminfo.MemInfo{}
|
||||||
|
meminfo.Update()
|
||||||
|
|
||||||
|
(*meminfo)['Cached'] // Get cached memory
|
||||||
|
(*meminfo)['Buffers'] // Get buffers size
|
||||||
|
(*meminfo)['...'] // Any field in /proc/meminfo
|
||||||
|
|
||||||
|
meminfo.Total() // Total memory size in bytes
|
||||||
|
meminfo.Free() // Free Memory (Free + Cached + Buffers)
|
||||||
|
meminfo.Used() // Total - Used
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Docs
|
||||||
|
|
||||||
|
Visit: http://godoc.org/github.com/guillermo/go.procmeminfo
|
||||||
|
|
||||||
|
## LICENSE
|
||||||
|
|
||||||
|
BSD
|
307
vendor/github.com/guillermo/go.procmeminfo/meminfo.go
generated
vendored
Normal file
307
vendor/github.com/guillermo/go.procmeminfo/meminfo.go
generated
vendored
Normal file
|
@ -0,0 +1,307 @@
|
||||||
|
/*
|
||||||
|
Package procmeminfo provides an interface for /proc/meminfo
|
||||||
|
|
||||||
|
import "github.com/guillermo/go.procmeminfo"
|
||||||
|
|
||||||
|
meminfo := &procmeminfo.MemInfo{}
|
||||||
|
meminfo.Update()
|
||||||
|
|
||||||
|
Once the info was updated you can access like a normal map[string]float64
|
||||||
|
|
||||||
|
v := (*meminfo)["MemTotal"] // 1809379328 (1766972 * 1024)
|
||||||
|
|
||||||
|
It also implement some handy methods, like:
|
||||||
|
|
||||||
|
meminfo.Total() // (*meminfo)["MemTotal"]
|
||||||
|
meminfo.Free() // MemFree + Buffers + Cached
|
||||||
|
meminfo.Used() // Total - Free
|
||||||
|
|
||||||
|
|
||||||
|
Return all the values in units, so while you get this from cat /proc/meminfo
|
||||||
|
|
||||||
|
MemTotal: 1766972 kB
|
||||||
|
MemFree: 115752 kB
|
||||||
|
Buffers: 3172 kB
|
||||||
|
Cached: 182552 kB
|
||||||
|
SwapCached: 83572 kB
|
||||||
|
Active: 1055284 kB
|
||||||
|
Inactive: 382872 kB
|
||||||
|
Active(anon): 932712 kB
|
||||||
|
Inactive(anon): 329508 kB
|
||||||
|
Active(file): 122572 kB
|
||||||
|
Inactive(file): 53364 kB
|
||||||
|
Unevictable: 10640 kB
|
||||||
|
Mlocked: 10640 kB
|
||||||
|
SwapTotal: 1808668 kB
|
||||||
|
SwapFree: 1205672 kB
|
||||||
|
Dirty: 100 kB
|
||||||
|
Writeback: 0 kB
|
||||||
|
AnonPages: 1214740 kB
|
||||||
|
Mapped: 115636 kB
|
||||||
|
Shmem: 4840 kB
|
||||||
|
Slab: 77412 kB
|
||||||
|
SReclaimable: 34344 kB
|
||||||
|
SUnreclaim: 43068 kB
|
||||||
|
KernelStack: 4328 kB
|
||||||
|
PageTables: 39428 kB
|
||||||
|
NFS_Unstable: 0 kB
|
||||||
|
Bounce: 0 kB
|
||||||
|
WritebackTmp: 0 kB
|
||||||
|
CommitLimit: 2692152 kB
|
||||||
|
Committed_AS: 5448372 kB
|
||||||
|
VmallocTotal: 34359738367 kB
|
||||||
|
VmallocUsed: 106636 kB
|
||||||
|
VmallocChunk: 34359618556 kB
|
||||||
|
HardwareCorrupted: 0 kB
|
||||||
|
AnonHugePages: 0 kB
|
||||||
|
HugePages_Total: 0
|
||||||
|
HugePages_Free: 0
|
||||||
|
HugePages_Rsvd: 0
|
||||||
|
HugePages_Surp: 0
|
||||||
|
Hugepagesize: 2048 kB
|
||||||
|
DirectMap4k: 216236 kB
|
||||||
|
DirectMap2M: 1593344 kB
|
||||||
|
|
||||||
|
|
||||||
|
All the kB values are multiply by 1024
|
||||||
|
|
||||||
|
This is the info extracted from the man page of proc:
|
||||||
|
|
||||||
|
|
||||||
|
/proc/meminfo
|
||||||
|
This file reports statistics about memory usage on the system. It is used by free(1) to report the amount of free and used memory (both physical and swap) on the system as well as the shared memory and buffers used by the kernel. Each line of the file consists of a parameter name, followed by a colon, the value of
|
||||||
|
the parameter, and an option unit of measurement (e.g., "kB"). The list below describes the parameter names and the format specifier required to read the field value. Except as noted below, all of the fields have been present since at least Linux 2.6.0. Some fileds are displayed only if the kernel was configured
|
||||||
|
with various options; those dependencies are noted in the list.
|
||||||
|
|
||||||
|
MemTotal %lu
|
||||||
|
Total usable RAM (i.e. physical RAM minus a few reserved bits and the kernel binary code).
|
||||||
|
|
||||||
|
MemFree %lu
|
||||||
|
The sum of LowFree+HighFree.
|
||||||
|
|
||||||
|
Buffers %lu
|
||||||
|
Relatively temporary storage for raw disk blocks that shouldn't get tremendously large (20MB or so).
|
||||||
|
|
||||||
|
Cached %lu
|
||||||
|
In-memory cache for files read from the disk (the page cache). Doesn't include SwapCached.
|
||||||
|
|
||||||
|
SwapCached %lu
|
||||||
|
Memory that once was swapped out, is swapped back in but still also is in the swap file. (If memory pressure is high, these pages don't need to be swapped out again because they are already in the swap file. This saves I/O.)
|
||||||
|
|
||||||
|
Active %lu
|
||||||
|
Memory that has been used more recently and usually not reclaimed unless absolutely necessary.
|
||||||
|
|
||||||
|
Inactive %lu
|
||||||
|
Memory which has been less recently used. It is more eligible to be reclaimed for other purposes.
|
||||||
|
|
||||||
|
Active(anon) %lu (since Linux 2.6.28)
|
||||||
|
[To be documented.]
|
||||||
|
|
||||||
|
Inactive(anon) %lu (since Linux 2.6.28)
|
||||||
|
[To be documented.]
|
||||||
|
|
||||||
|
Active(file) %lu (since Linux 2.6.28)
|
||||||
|
[To be documented.]
|
||||||
|
|
||||||
|
Inactive(file) %lu (since Linux 2.6.28)
|
||||||
|
[To be documented.]
|
||||||
|
|
||||||
|
Unevictable %lu (since Linux 2.6.28)
|
||||||
|
(From Linux 2.6.28 to 2.6.30, CONFIG_UNEVICTABLE_LRU was required.) [To be documented.]
|
||||||
|
|
||||||
|
Mlocked %lu (since Linux 2.6.28)
|
||||||
|
(From Linux 2.6.28 to 2.6.30, CONFIG_UNEVICTABLE_LRU was required.) [To be documented.]
|
||||||
|
|
||||||
|
HighTotal %lu
|
||||||
|
(Starting with Linux 2.6.19, CONFIG_HIGHMEM is required.) Total amount of highmem. Highmem is all memory above ~860MB of physical memory. Highmem areas are for use by user-space programs, or for the page cache. The kernel must use tricks to access this memory, making it slower to access than lowmem.
|
||||||
|
|
||||||
|
HighFree %lu
|
||||||
|
(Starting with Linux 2.6.19, CONFIG_HIGHMEM is required.) Amount of free highmem.
|
||||||
|
|
||||||
|
LowTotal %lu
|
||||||
|
(Starting with Linux 2.6.19, CONFIG_HIGHMEM is required.) Total amount of lowmem. Lowmem is memory which can be used for everything that highmem can be used for, but it is also available for the kernel's use for its own data structures. Among many other things, it is where everything from Slab is allo‐
|
||||||
|
cated. Bad things happen when you're out of lowmem.
|
||||||
|
|
||||||
|
LowFree %lu
|
||||||
|
(Starting with Linux 2.6.19, CONFIG_HIGHMEM is required.) Amount of free lowmem.
|
||||||
|
|
||||||
|
MmapCopy %lu (since Linux 2.6.29)
|
||||||
|
(CONFIG_MMU is required.) [To be documented.]
|
||||||
|
|
||||||
|
SwapTotal %lu
|
||||||
|
Total amount of swap space available.
|
||||||
|
|
||||||
|
SwapFree %lu
|
||||||
|
Amount of swap space that is currently unused.
|
||||||
|
|
||||||
|
Dirty %lu
|
||||||
|
Memory which is waiting to get written back to the disk.
|
||||||
|
|
||||||
|
Writeback %lu
|
||||||
|
Memory which is actively being written back to the disk.
|
||||||
|
|
||||||
|
AnonPages %lu (since Linux 2.6.18)
|
||||||
|
Non-file backed pages mapped into user-space page tables.
|
||||||
|
|
||||||
|
Mapped %lu
|
||||||
|
Files which have been mmaped, such as libraries.
|
||||||
|
|
||||||
|
Shmem %lu (since Linux 2.6.32)
|
||||||
|
[To be documented.]
|
||||||
|
|
||||||
|
Slab %lu
|
||||||
|
In-kernel data structures cache.
|
||||||
|
|
||||||
|
SReclaimable %lu (since Linux 2.6.19)
|
||||||
|
Part of Slab, that might be reclaimed, such as caches.
|
||||||
|
|
||||||
|
SUnreclaim %lu (since Linux 2.6.19)
|
||||||
|
Part of Slab, that cannot be reclaimed on memory pressure.
|
||||||
|
|
||||||
|
KernelStack %lu (since Linux 2.6.32)
|
||||||
|
Amount of memory allocated to kernel stacks.
|
||||||
|
|
||||||
|
PageTables %lu (since Linux 2.6.18)
|
||||||
|
Amount of memory dedicated to the lowest level of page tables.
|
||||||
|
|
||||||
|
Quicklists %lu (since Linux 2.6.27)
|
||||||
|
(CONFIG_QUICKLIST is required.) [To be documented.]
|
||||||
|
|
||||||
|
NFS_Unstable %lu (since Linux 2.6.18)
|
||||||
|
NFS pages sent to the server, but not yet committed to stable storage.
|
||||||
|
|
||||||
|
Bounce %lu (since Linux 2.6.18)
|
||||||
|
Memory used for block device "bounce buffers".
|
||||||
|
|
||||||
|
WritebackTmp %lu (since Linux 2.6.26)
|
||||||
|
Memory used by FUSE for temporary writeback buffers.
|
||||||
|
|
||||||
|
CommitLimit %lu (since Linux 2.6.10)
|
||||||
|
Based on the overcommit ratio ('vm.overcommit_ratio'), this is the total amount of memory currently available to be allocated on the system. This limit is adhered to only if strict overcommit accounting is enabled (mode 2 in /proc/sys/vm/overcommit_ratio). The CommitLimit is calculated using the following
|
||||||
|
formula:
|
||||||
|
|
||||||
|
CommitLimit = (overcommit_ratio * Physical RAM) + Swap
|
||||||
|
|
||||||
|
For example, on a system with 1GB of physical RAM and 7GB of swap with a overcommit_ratio of 30, this formula yields a CommitLimit of 7.3GB. For more details, see the memory overcommit documentation in the kernel source file Documentation/vm/overcommit-accounting.
|
||||||
|
|
||||||
|
Committed_AS %lu
|
||||||
|
The amount of memory presently allocated on the system. The committed memory is a sum of all of the memory which has been allocated by processes, even if it has not been "used" by them as of yet. A process which allocates 1GB of memory (using malloc(3) or similar), but touches only 300MB of that memory will
|
||||||
|
show up as using only 300MB of memory even if it has the address space allocated for the entire 1GB. This 1GB is memory which has been "committed" to by the VM and can be used at any time by the allocating application. With strict overcommit enabled on the system (mode 2 /proc/sys/vm/overcommit_memory),
|
||||||
|
allocations which would exceed the CommitLimit (detailed above) will not be permitted. This is useful if one needs to guarantee that processes will not fail due to lack of memory once that memory has been successfully allocated.
|
||||||
|
|
||||||
|
VmallocTotal %lu
|
||||||
|
Total size of vmalloc memory area.
|
||||||
|
|
||||||
|
VmallocUsed %lu
|
||||||
|
Amount of vmalloc area which is used.
|
||||||
|
|
||||||
|
VmallocChunk %lu
|
||||||
|
Largest contiguous block of vmalloc area which is free.
|
||||||
|
|
||||||
|
HardwareCorrupted %lu (since Linux 2.6.32)
|
||||||
|
(CONFIG_MEMORY_FAILURE is required.) [To be documented.]
|
||||||
|
|
||||||
|
AnonHugePages %lu (since Linux 2.6.38)
|
||||||
|
(CONFIG_TRANSPARENT_HUGEPAGE is required.) Non-file backed huge pages mapped into user-space page tables.
|
||||||
|
|
||||||
|
HugePages_Total %lu
|
||||||
|
(CONFIG_HUGETLB_PAGE is required.) The size of the pool of huge pages.
|
||||||
|
|
||||||
|
HugePages_Free %lu
|
||||||
|
(CONFIG_HUGETLB_PAGE is required.) The number of huge pages in the pool that are not yet allocated.
|
||||||
|
|
||||||
|
HugePages_Rsvd %lu (since Linux 2.6.17)
|
||||||
|
(CONFIG_HUGETLB_PAGE is required.) This is the number of huge pages for which a commitment to allocate from the pool has been made, but no allocation has yet been made. These reserved huge pages guarantee that an application will be able to allocate a huge page from the pool of huge pages at fault time.
|
||||||
|
|
||||||
|
HugePages_Surp %lu (since Linux 2.6.24)
|
||||||
|
(CONFIG_HUGETLB_PAGE is required.) This is the number of huge pages in the pool above the value in /proc/sys/vm/nr_hugepages. The maximum number of surplus huge pages is controlled by /proc/sys/vm/nr_overcommit_hugepages.
|
||||||
|
|
||||||
|
Hugepagesize %lu
|
||||||
|
(CONFIG_HUGETLB_PAGE is required.) The size of huge pages.
|
||||||
|
*/
|
||||||
|
package procmeminfo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MemInfo is a map[string]uint64 with all the values found in /proc/meminfo
|
||||||
|
type MemInfo map[string]uint64
|
||||||
|
|
||||||
|
// Update s with current values, usign the pid stored in the Stat
|
||||||
|
func (m *MemInfo) Update() error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
path := filepath.Join("/proc/meminfo")
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
text := scanner.Text()
|
||||||
|
|
||||||
|
n := strings.Index(text, ":")
|
||||||
|
if n == -1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
key := text[:n] // metric
|
||||||
|
data := strings.Split(strings.Trim(text[(n+1):], " "), " ")
|
||||||
|
if len(data) == 1 {
|
||||||
|
value, err := strconv.ParseUint(data[0], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
(*m)[key] = value
|
||||||
|
} else if len(data) == 2 {
|
||||||
|
if data[1] == "kB" {
|
||||||
|
value, err := strconv.ParseUint(data[0], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
(*m)[key] = value * 1024
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Total return the size of the memory in bytes.
|
||||||
|
// It is an alias of (*m)["MemInfo"]
|
||||||
|
func (m *MemInfo) Total() uint64 {
|
||||||
|
return (*m)["MemTotal"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Available return the available memory following this formula:
|
||||||
|
//
|
||||||
|
// Available = Free + Buffers + Cached
|
||||||
|
func (m *MemInfo) Available() uint64 {
|
||||||
|
d := *m
|
||||||
|
return d["MemFree"] + d["Buffers"] + d["Cached"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used is a generic way of reporting used memory. It follows the next formula:
|
||||||
|
//
|
||||||
|
// Used = Total - Available
|
||||||
|
func (m *MemInfo) Used() uint64 {
|
||||||
|
return m.Total() - m.Available()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap returns the % of swap used
|
||||||
|
func (m *MemInfo) Swap() int {
|
||||||
|
total := (*m)["SwapTotal"]
|
||||||
|
free := (*m)["SwapFree"]
|
||||||
|
if total == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int((100 * (total - free)) / total)
|
||||||
|
}
|
5
vendor/modules.txt
vendored
5
vendor/modules.txt
vendored
|
@ -68,8 +68,13 @@ github.com/gdamore/tcell/terminfo/x/xfce
|
||||||
github.com/gdamore/tcell/terminfo/x/xnuppc
|
github.com/gdamore/tcell/terminfo/x/xnuppc
|
||||||
github.com/gdamore/tcell/terminfo/x/xterm
|
github.com/gdamore/tcell/terminfo/x/xterm
|
||||||
github.com/gdamore/tcell/terminfo/x/xterm_kitty
|
github.com/gdamore/tcell/terminfo/x/xterm_kitty
|
||||||
|
# github.com/guillermo/go.procmeminfo v0.0.0-20131127224636-be4355a9fb0e
|
||||||
|
## explicit
|
||||||
|
github.com/guillermo/go.procmeminfo
|
||||||
# github.com/lucasb-eyer/go-colorful v1.0.3
|
# github.com/lucasb-eyer/go-colorful v1.0.3
|
||||||
github.com/lucasb-eyer/go-colorful
|
github.com/lucasb-eyer/go-colorful
|
||||||
|
# github.com/mackerelio/go-osstat v0.1.0
|
||||||
|
## explicit
|
||||||
# github.com/mattn/go-runewidth v0.0.9
|
# github.com/mattn/go-runewidth v0.0.9
|
||||||
github.com/mattn/go-runewidth
|
github.com/mattn/go-runewidth
|
||||||
# github.com/rivo/tview v0.0.0-20200818120338-53d50e499bf9
|
# github.com/rivo/tview v0.0.0-20200818120338-53d50e499bf9
|
||||||
|
|
Loading…
Reference in a new issue