Raspberry Pi disk usage fix

Talks about metering
Post Reply
cyberdiamond
Posts: 2
Joined: Thu Sep 12, 2013 7:55 am

Raspberry Pi disk usage fix

Post by cyberdiamond » Mon Aug 31, 2015 10:36 am

Hi,

I saw a problem in the info page with disk usage wrong on a Raspberry Pi running raspbian.
Here is a simple way to fix it.

Code: Select all

cp -a /path/to/metern/scripts/distros/debian_ARM.php /path/to/metern/scripts/distros/raspbian_ARM.php
vi /path/to/metern/scripts/distros/raspbian_ARM.php
/path/to is where ever YOUR metern path is installed.

Replace rootfs with /dev/root in the last two DISK lines

Code: Select all

:%s/rootfs/\/dev\/root/g
OR just copy the below:

Code: Select all

<?php
# Commands
$UPTIME="uptime";
$CPUUSE="ps aux|awk 'NR > 0 { s +=$3 }; END {print \"cpu %\",s}' | awk '{ print $3 }'";
$MEMTOT="free -m | grep 'Mem' | awk '{print $2}'";
$MEMUSE="free -m| grep 'buffers/cache' | awk '{print $3}'";
$MEMFREE="free -m| grep 'buffers/cache' | awk '{print $4}'";
$DISKUSE="df -h | grep /dev/root | awk '{print $3}'";
$DISKFREE="df -h | grep /dev/root | awk '{print $4}'";
?>
To a new file save it as raspbian_ARM.php to the directory /path/to/metern/scripts/distros/

Change permissions of the file as required then go to admin page.
Select the raspbian_ARM distro on admin page, restart metern if needed.

Cheers,
Steve

jeanmarc
Posts: 1600
Joined: Thu Aug 29, 2013 7:16 am

Re: Raspberry Pi disk usage fix

Post by jeanmarc » Mon Aug 31, 2015 11:01 am

Thanks, i'll add your raspbian_ARM.php in the next release.

thedrake
Posts: 52
Joined: Fri Aug 21, 2015 12:43 pm

Re: Raspberry Pi disk usage fix

Post by thedrake » Sat Sep 05, 2015 12:23 pm

I'm getting wrong CPU percentage too. Actual command does not divide by CPU/core number.

Here is my raspbian_ARM.php with cpu/core numbers included in calculation. I hope nproc is included in std raspbian distro. :)

Code: Select all

<?php
# Commands
$UPTIME="uptime";
$CPUUSE="ps aux|awk -v nproc=`nproc` 'NR > 0 { s +=$3 }; END {print s/nproc}'";
$MEMTOT="free -m | grep 'Mem' | awk '{print $2}'";
$MEMUSE="free -m| grep 'buffers/cache' | awk '{print $3}'";
$MEMFREE="free -m| grep 'buffers/cache' | awk '{print $4}'";
$DISKUSE="df -h | grep root | awk '{print $3}'";
$DISKFREE="df -h | grep root | awk '{print $4}'";
?>

jeanmarc
Posts: 1600
Joined: Thu Aug 29, 2013 7:16 am

Re: Raspberry Pi disk usage fix

Post by jeanmarc » Sat Sep 05, 2015 12:29 pm

I use sysstat (sar) on Archlinux, it does correct calculation on my odroid.

thedrake
Posts: 52
Joined: Fri Aug 21, 2015 12:43 pm

Re: Raspberry Pi disk usage fix

Post by thedrake » Mon Nov 23, 2015 3:11 pm

One more fix for raspbian if you have ramlog installed. It avoids having root fs lines double counted, checking that only main "/" filesystem is picked by grep:

scripts/distros/raspbian_ARM.php

Code: Select all

<?php
# Commands
$UPTIME="uptime";
$CPUUSE="ps aux|awk -v nproc=`nproc` 'NR > 0 { s +=$3 }; END {print s/nproc}'";
$MEMTOT="free -m | grep 'Mem' | awk '{print $2}'";
$MEMUSE="free -m| grep 'buffers/cache' | awk '{print $3}'";
$MEMFREE="free -m| grep 'buffers/cache' | awk '{print $4}'";
$DISKUSE="df -h | grep root.*/$ | awk '{print $3}'";
$DISKFREE="df -h | grep root.*/$ | awk '{print $4}'";
?>
BTW, same for 123solar.

/drk 8-)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests