On Sun, Mar 06, 2016 at 03:23:33PM +0100, Andre Schmidt wrote:
hello archers,
thought i ask here first, before i try some kernel mailing list.
i'm writing (for fun) a tiny daemon that sends linux usage (cpu, mem, net, etc.) statistics as efficiently as possible to another machine, repeatedly, to get "live" data.
at the moment i'm simply sending /proc files, but they sometimes have too much data. so was wondering if there is a more efficient way to get (only parts of) the data thats available in /proc?
for example, /proc/meminfo has all this info:
MemTotal: 8051660 kB MemFree: 6046020 kB MemAvailable: 6843080 kB Buffers: 109116 kB Cached: 708336 kB SwapCached: 0 kB Active: 1332416 kB Inactive: 455428 kB Active(anon): 971040 kB Inactive(anon): 22340 kB Active(file): 361376 kB Inactive(file): 433088 kB Unevictable: 16 kB Mlocked: 16 kB SwapTotal: 1048572 kB SwapFree: 1048572 kB Dirty: 16 kB Writeback: 0 kB AnonPages: 970412 kB Mapped: 323384 kB Shmem: 23008 kB Slab: 71760 kB SReclaimable: 44860 kB SUnreclaim: 26900 kB KernelStack: 6544 kB PageTables: 22924 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 5074400 kB Committed_AS: 3487604 kB VmallocTotal: 34359738367 kB VmallocUsed: 0 kB VmallocChunk: 0 kB HardwareCorrupted: 0 kB AnonHugePages: 413696 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 168600 kB DirectMap2M: 8091648 kB
but i only need:
MemTotal: 8051660 kB MemAvailable: 6843080 kB Cached: 708336 kB
event better would be if kernel would only tell me:
8051660 6843080 708336
if /proc is the only way to get this info, i wonder if creating a kernel module for this would be more efficient, or even possible?
Hello Andre, According to what you need, you may want to use the 'free' command instead, as its output is much simpler than the output of the /proc/meminfo file E.g.
$ free total used free shared buff/cache available Mem: 5951844 486324 4969788 75812 495732 5339492 Swap: 0 0 0
or, if you prefer it be displayed in mebibytes,
$ free -m total used free shared buff/cache available Mem: 5812 496 4832 73 484 5193 Swap: 0 0 0
you can also check the man page for more display options Hope this helps, Jonathan