|
Workshop : Follow-up of the CPU with MRTG |
|
|
|
Various pieces of information about kernel activity are available in the /proc/stat file. All of the numbers reported in this file are aggregates since the system first booted. For a quick look, simply cat the file: cat /proc/stat CPU 25205423 2078 10367674 1232769545 cpu0 25205423 2078 10367674 1232769545 page 5683838 276256808 swap 438 22348 This article treats the follow-up of the CPU with MRTG.
The very first "cpu" line aggregates the numbers in all of the other "cpuN" lines. These numbers identify the amount of time the CPU has spent performing different kinds of work. Time units are in USER_HZ (typically hundredths of a second). The meanings of the columns are as follows, from left to right: - user: normal processes executing in user mode
- nice: niced processes executing in user mode
- system: processes executing in kernel mode
- idle: twiddling thumbs
Initially, it will be necessary to put the script below in your /etc/mrtg directory Script Name : cpu.pl Contents: #! /usr/bin/perl my $cpu = `cat /proc/stat | grep “CPU” `; $cpu=~ /cpu (. *) (. *) (. *) (. *)/; my $conso = $1 + $2 + $3; $conso = int ($conso); print “$conso \ N”; print “$conso \ N”; Once, /etc/mrtg/cpu.pl script set up, its rights are changed as follows: - chmod +x /etc/mrtg/cpu.pl
Check your script by : # /etc/mrtg/cpu.pl 35583547 35583547 Then, it will be necessary to update your /etc/mrtg.cfg configuration file, and this with the following contents: Target [localhost-CPU]: `/etc/mrtg/cpu.pl ` Options [localhost-CPU]: noinfo, nopercent, growright, nobanner, noi [Localhost-CPU]: Follow-up of the consumption of the CPU MaxBytes [localhost-CPU]: 9999999999 YLegend [localhost-CPU]: CPU ShortLegend [localhost-CPU]: % LegendO [localhost-CPU]: CPU Legend2 [localhost-CPU]: CPU PageTop [localhost-CPU]: Follow-up of the consumption of the CPU The construction of the new index page (the new synthesis web page) is done using indexmaker command. Here an example: - cp /var/www/mrtg/index.html /var/www/mrtg/index.html.old
- indexmaker --columns=1 --output /var/www/mrtg/index.html /etc/mrtg.cfg
|