While monitoring a http/php server, I needed to do some statistics about php-cgi memory usage.
Playing with memory_limit in PHP, we wanted to know the average memory usage per php-cgi process. This is easily calculated with our best friend awk.
First, get the number of php running processes:
# ps aux | grep php-cgi | grep -v grep | wc -l 126
Then, use awk to calculate the average memory usage for these processes:
# ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'
33987.8
The number used in the calculation is the field RSS given by ps. The ps manual page says:
rss: resident set size, the non-swapped physical memory that a task has used (in kiloBytes)
You can also calculate the total memory used by all php-cgi processes:
# ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s;}'
4302028
If you need to watch the trend of this average memory usage, a little shell loop does the trick:
# while [ 1 ]; do ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'; sleep 2; done
34401.3
34405.1
34408.4
34409.4
34414.2
34417
This entry was written by , posted on March 13, 2009 at 4:14 pm, filed under Benchmarks, Command line, Monitoring and tagged awk, memory, php, shell. Leave a comment or view the discussion at the permalink.
The dmidecode command gives you all informations available about your memory.
With the special parameter “-t 16″, you can see the maximum (physical) memory that your server can have:
$ dmidecode -t 16 # dmidecode 2.8 SMBIOS 2.4 present. Handle 0x1000, DMI type 16, 15 bytes Physical Memory Array Location: System Board Or Motherboard Use: System Memory Error Correction Type: Multi-bit ECC Maximum Capacity: 32 GB Error Information Handle: Not Provided Number Of Devices: 8
Here we can see that your server can handle up to 32Gb
To know which slots are used or not use the “-t 17″ flag.
dmidecode -t 17 | grep Size
Size: 2048 MB
Size: 2048 MB
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
This entry was written by , posted on August 4, 2008 at 8:42 am, filed under Uncategorized and tagged dmidecode, memory. Leave a comment or view the discussion at the permalink.