sim_tcr
Posts: 338
Joined: Tue Nov 06, 2012 1:01 pm
Location: Bangalore
Contact: Website

Re: Determine information about Pi?

Tue Dec 25, 2012 4:32 am

toysareforboys wrote:

Code: Select all

<?php
echo '</pre><strong>CPU Utilization:</strong><pre>' . shell_exec('ps -e -o pcpu | tail -n +2 | sed \'{:q;N;s/\n/ + /g;t q}\' | bc') . "%";
?>
-Jamie M.
still appears.
1.2
%
http://raspisimon.no-ip.org
Raspberry Pi Model B x 2, Raspberry Pi 2 x 2, Transcend 32GB Class 10, Transcend 16GB Class 10, Transcend 8GB Class 4, Custom 12V 1.5A (stepped down to 5.5V)

User avatar
toysareforboys
Posts: 136
Joined: Thu Dec 06, 2012 11:01 pm

Re: Determine information about Pi?

Tue Dec 25, 2012 4:41 am

sim_tcr wrote:still appears.
1.2
%
In looking at my code on my site, I see I had to strip \n and \r from the string to get the % onto the same line. My super crappy php code:

Code: Select all

<?php
$total_cpu = 'ps -e -o pcpu | tail -n +2 | sed \'{:q;N;s/\n/ + /g;t q}\' | bc';
$total_cpu_num = shell_exec($total_cpu);
$total_cpu_num = str_replace(array("\r", "\n", '/\s+/'), '', $total_cpu_num);
echo $total_cpu_num . "%";
?>
That should work ;)

-Jamie M.
Seagate GoFlex Home, 1.2GHz ARM (kirkwood), 128MB RAM, Gigabit Ethernet, SATA2. Sandisk Extreme 120GB SSD running Arch ARM Linux 3.6.11-0. nginx + php-fpm = LIVE STATUS hosted right on the SGFH!! http://tafb.yi.org

sim_tcr
Posts: 338
Joined: Tue Nov 06, 2012 1:01 pm
Location: Bangalore
Contact: Website

Re: Determine information about Pi?

Tue Dec 25, 2012 7:40 am

toysareforboys wrote:
sim_tcr wrote:still appears.
1.2
%
In looking at my code on my site, I see I had to strip \n and \r from the string to get the % onto the same line. My super crappy php code:

Code: Select all

<?php
$total_cpu = 'ps -e -o pcpu | tail -n +2 | sed \'{:q;N;s/\n/ + /g;t q}\' | bc';
$total_cpu_num = shell_exec($total_cpu);
$total_cpu_num = str_replace(array("\r", "\n", '/\s+/'), '', $total_cpu_num);
echo $total_cpu_num . "%";
?>
That should work ;)

-Jamie M.
That worked.
Here is my page http://raspisimon.no-ip.org/status.php
Wish you all Merry X'mas.
http://raspisimon.no-ip.org
Raspberry Pi Model B x 2, Raspberry Pi 2 x 2, Transcend 32GB Class 10, Transcend 16GB Class 10, Transcend 8GB Class 4, Custom 12V 1.5A (stepped down to 5.5V)

User avatar
toysareforboys
Posts: 136
Joined: Thu Dec 06, 2012 11:01 pm

Re: Determine information about Pi?

Tue Dec 25, 2012 7:47 am

sim_tcr wrote:That worked.
Here is my page http://raspisimon.no-ip.org/status.php
Wish you all Merry X'mas.
Love the page, looks great! :)

I'm also working on some dynamically updating stuff for my page, instead of refreshing the entire page :) It works SOOO much better that way!

Right now it only works by clicking the "stop" button, it should update the uptime, meminfo and cpu load (but not chart) dynamically after that. Click stop2 to stop it. To get it going again, refresh the page and click stop ;)

I'll be working on it lots tonight so maybe it'll be different by the time you load it: http://tafb.yi.org

Have a great christmas and new years :)

-Jamie M.
Seagate GoFlex Home, 1.2GHz ARM (kirkwood), 128MB RAM, Gigabit Ethernet, SATA2. Sandisk Extreme 120GB SSD running Arch ARM Linux 3.6.11-0. nginx + php-fpm = LIVE STATUS hosted right on the SGFH!! http://tafb.yi.org

sim_tcr
Posts: 338
Joined: Tue Nov 06, 2012 1:01 pm
Location: Bangalore
Contact: Website

Re: Determine information about Pi?

Fri Dec 28, 2012 4:00 pm

toysareforboys wrote:I'll be working on it lots tonight so maybe it'll be different by the time you load it: http://tafb.yi.org
I see the new changes, it looks awsome, especially the CPU load progress bar. Do you mind sharing the source code of whole thing?
http://raspisimon.no-ip.org
Raspberry Pi Model B x 2, Raspberry Pi 2 x 2, Transcend 32GB Class 10, Transcend 16GB Class 10, Transcend 8GB Class 4, Custom 12V 1.5A (stepped down to 5.5V)

User avatar
toysareforboys
Posts: 136
Joined: Thu Dec 06, 2012 11:01 pm

Re: Determine information about Pi?

Fri Dec 28, 2012 8:04 pm

sim_tcr wrote:I see the new changes, it looks awsome, especially the CPU load progress bar. Do you mind sharing the source code of whole thing?
I'm glad you like the changes :) My new page is built on Arch linux and not the Pi, but it should still function reasonably well on it (even under Wheezy) :)

I'm afraid to show anyone my super terrible PHP coding so maybe once I clean it up a bit!!

Some information for ya:

The fancy shiny percentage bars that change colour when the values get high were provided by this site: http://0.s3.envato.com/files/2526201/index.html

To dynamically update them so they are "live" I just jquery with <div> tags and how it works is basically all of the values are written every second (using wget) to a file with the <div> tags around each value, and it reads those and spits em into the current html page where the corresponding <div> tags are :)

Here is how to calculate the CPU load with PHP, but remember, this only calculates "user" load, i.e. service and programs you are running, not "system" load :)

Code: Select all

<?php
$total_cpu = 'ps -e -o pcpu | tail -n +2 | sed \'{:q;N;s/\n/ + /g;t q}\' | bc';
$total_cpu_num = shell_exec($total_cpu);
$total_cpu_num = str_replace(array("\r", "\n", '/\s+/'), '', $total_cpu_num);
echo $total_cpu_num ;
?>
I'll post in here when/if I'm ready to release my tweaked page :)

-Jamie M.
Seagate GoFlex Home, 1.2GHz ARM (kirkwood), 128MB RAM, Gigabit Ethernet, SATA2. Sandisk Extreme 120GB SSD running Arch ARM Linux 3.6.11-0. nginx + php-fpm = LIVE STATUS hosted right on the SGFH!! http://tafb.yi.org

Return to “General discussion”